Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitlab ci yml image and services mechanism?

I don't understand the mechanism of the keywords image and services in the file.gitlab-ci.yml. when do we know on which image the commands of the keyword script are executed ?

When i read the gitlabci documentation i understand the theory of the keywords "image" and "services" well, so i have already done tests and managed to interact with a httpd service by a wget for example, however, in practice i can't understand what the image is for ?

Let me explain :)

First i created a structure with a job that makes a "uname -a" by not declaring any images:

job_scriptWithDefaultImage:
  stage: gitlabtest1
  script:
    - uname -a

The result then shows me a "uname -a" running on the runner:

$ uname -a
Linux runner-b41b332f-project-9060-concurrent-0 4.4.0-104-generic #127-Ubuntu SMP Mon Dec 11 12:16:42 UTC 2017 x86_64 Linux

Then i simply add an image in my job specifying i want to use an alpine:

job_scriptWithAlpineImage:
  internship: gitlabtest2
  image: registry.hub.docker.com/library/alpine:latest
  script:
    - uname -a

The result is exactly the same, the uname always runs on the runner, instead of my alpine ...

$ uname -a
Linux runner-9cade5e3-project-9060-concurrent-0 4.4.0-130-generic #156-Ubuntu SMP Thu Jun 14 08:53:28 UTC 2018 x86_64 GNU/Linux

So i don't understand at all:

  • What my image is for ?
  • How to execute commands in that image in my pipeline job script section ?
like image 312
lepapareil Avatar asked Oct 04 '18 08:10

lepapareil


1 Answers

Docker uses the host's kernel. As you can see by your uname -a output, it gives the runner's machine info. That's why regardless of the container you get the same output. You can even try it on your machine.

https://stackoverflow.com/a/31012367/4551937

Regarding Gitlab Runner, your service is independent. It will be attached and provided to your job calling it, as if it was running beside it.

Your job will use the image you specify with the image tag to run the commands listed in script (you can chain them). If no image is specified, it will take the default one defined in the runner configuration (probably Ubuntu).

like image 200
Hiruma Avatar answered Oct 01 '22 05:10

Hiruma