7

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 ?
lepapareil
  • 491
  • 3
  • 6
  • 16

1 Answers1

1

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).

Hiruma
  • 629
  • 5
  • 14
  • Do I understand that any command found on the host (runner) will be used instead of the image one, is there a notion of priority ? For example, if I do a uname -a, it is the runner who answers as you explain it, however if I do an apt update, then it is on the image that the command is executed. How do I know for sure that the command I launch is launched from the image and not from the host ? Is there a system command list, or should I blindly trust the dock runner and tell myself that as long as it works I have nothing more to understand ? how lucky we are :) – lepapareil Oct 04 '18 at 20:13
  • That's not the runner answering, that's the container, but reading the runner's kernel. The docker runner has a set config, it's either a docker runner, or a shell one (default to the first if I remember, there might have been an hybrid mode but I think they dropped it). You don't need to "trust" anything, because it will do what you configured it to do ;) Also: don't run `apt-get` in your container if you can avoid it, you will be wasting time every time you run your job. Just build a cached image with per-installed dependencies. – Hiruma Oct 04 '18 at 20:25
  • 1
    Okay, thanks, I understand a lot better now ! (apt update was just there for the example). I did some more tests following your answer, I finally understood who was launching what and in what order :) Thank you for unlocking my understanding, too bad the documentation is not as accurate as your answers:) – lepapareil Oct 04 '18 at 20:34