Commit 5fa6992e authored by Amy Qualls's avatar Amy Qualls

Merge branch 'selhorn-docker-edits-1' into 'master'

Fixed Vale issues

See merge request gitlab-org/gitlab!50467
parents 4f44258f bcb5623b
...@@ -10,18 +10,18 @@ type: concepts, howto ...@@ -10,18 +10,18 @@ type: concepts, howto
GitLab CI/CD in conjunction with [GitLab Runner](../runners/README.md) can use GitLab CI/CD in conjunction with [GitLab Runner](../runners/README.md) can use
[Docker Engine](https://www.docker.com/) to test and build any application. [Docker Engine](https://www.docker.com/) to test and build any application.
Docker is an open-source project that allows you to use predefined images to Docker is an open-source project that has predefined images you can use to
run applications in independent "containers" that are run within a single Linux run applications in independent "containers." These containers run in a single Linux
instance. [Docker Hub](https://hub.docker.com/) has a rich database of pre-built images that can be instance. [Docker Hub](https://hub.docker.com/) is a database of pre-built images you can
used to test and build your applications. use to test and build your applications.
When used with GitLab CI/CD, Docker runs each job in a separate and isolated When you use Docker with GitLab CI/CD, Docker runs each job in a separate and isolated
container using the predefined image that's set up in container. You specify the container image in the project's
[`.gitlab-ci.yml`](../yaml/README.md). [`.gitlab-ci.yml`](../yaml/README.md) file.
This makes it easier to have a simple and reproducible build environment that Docker containers provide a reproducible build environment that
can also run on your workstation. The added benefit is that you can test all can run on your workstation. When a Docker container is running, you can test
the commands that we explore later from your shell, rather than having to commands from your shell, rather than having to
test them on a dedicated CI server. test them on a dedicated CI server.
## Register Docker Runner ## Register Docker Runner
...@@ -29,7 +29,7 @@ test them on a dedicated CI server. ...@@ -29,7 +29,7 @@ test them on a dedicated CI server.
To use GitLab Runner with Docker you need to [register a new runner](https://docs.gitlab.com/runner/register/) To use GitLab Runner with Docker you need to [register a new runner](https://docs.gitlab.com/runner/register/)
to use the `docker` executor. to use the `docker` executor.
An example can be seen below. First we set up a temporary template to supply the services: In this example, we first set up a temporary template to supply the services:
```shell ```shell
cat > /tmp/test-config.template.toml << EOF cat > /tmp/test-config.template.toml << EOF
...@@ -42,7 +42,7 @@ name = "mysql:latest" ...@@ -42,7 +42,7 @@ name = "mysql:latest"
EOF EOF
``` ```
Then we register the runner using the template that was just created: Then use this template to register the runner:
```shell ```shell
sudo gitlab-runner register \ sudo gitlab-runner register \
...@@ -63,25 +63,26 @@ accessible during the build process. ...@@ -63,25 +63,26 @@ accessible during the build process.
The `image` keyword is the name of the Docker image the Docker executor The `image` keyword is the name of the Docker image the Docker executor
runs to perform the CI tasks. runs to perform the CI tasks.
By default, the executor only pulls images from [Docker Hub](https://hub.docker.com/), By default, the executor pulls images only from [Docker Hub](https://hub.docker.com/).
however this can be configured in the `gitlab-runner/config.toml` by setting However, you can configure the location in the `gitlab-runner/config.toml` file. For example,
the [Docker pull policy](https://docs.gitlab.com/runner/executors/docker.html#how-pull-policies-work) to allow using local images. you can set the [Docker pull policy](https://docs.gitlab.com/runner/executors/docker.html#how-pull-policies-work)
to use local images.
For more information about images and Docker Hub, please read For more information about images and Docker Hub, read
the [Docker Fundamentals](https://docs.docker.com/engine/understanding-docker/) documentation. the [Docker Fundamentals](https://docs.docker.com/engine/understanding-docker/) documentation.
## What is a service ## What is a service
The `services` keyword defines just another Docker image that's run during The `services` keyword defines another Docker image that's run during
your job and is linked to the Docker image that the `image` keyword defines. your job. It's linked to the Docker image that the `image` keyword defines,
This allows you to access the service image during build time. which allows you to access the service image during build time.
The service image can run any application, but the most common use case is to The service image can run any application, but the most common use case is to
run a database container, for example, `mysql`. It's easier and faster to use an run a database container, for example, `mysql`. It's easier and faster to use an
existing image and run it as an additional container than install `mysql` every existing image and run it as an additional container than to install `mysql` every
time the project is built. time the project is built.
You're not limited to have only database services. You can add as many You're not limited to only database services. You can add as many
services you need to `.gitlab-ci.yml` or manually modify `config.toml`. services you need to `.gitlab-ci.yml` or manually modify `config.toml`.
Any image found at [Docker Hub](https://hub.docker.com/) or your private Container Registry can be Any image found at [Docker Hub](https://hub.docker.com/) or your private Container Registry can be
used as a service. used as a service.
...@@ -94,56 +95,57 @@ You can see some widely used services examples in the relevant documentation of ...@@ -94,56 +95,57 @@ You can see some widely used services examples in the relevant documentation of
### How services are linked to the job ### How services are linked to the job
To better understand how the container linking works, read To better understand how container linking works, read
[Linking containers together](https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/). [Linking containers together](https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/).
To summarize, if you add `mysql` as service to your application, the image is If you add `mysql` as service to your application, the image is
then used to create a container that's linked to the job container. used to create a container that's linked to the job container.
The service container for MySQL is accessible under the hostname `mysql`. The service container for MySQL is accessible under the hostname `mysql`.
So, in order to access your database service you have to connect to the host To access your database service, connect to the host named `mysql` instead of a
named `mysql` instead of a socket or `localhost`. Read more in [accessing the socket or `localhost`. Read more in [accessing the services](#accessing-the-services).
services](#accessing-the-services).
### How the health check of services works ### How the health check of services works
Services are designed to provide additional functionality which is **network accessible**. Services are designed to provide additional features which are **network accessible**.
It may be a database like MySQL, or Redis, and even `docker:stable-dind` which They may be a database like MySQL, or Redis, and even `docker:stable-dind` which
allows you to use Docker in Docker. It can be practically anything that's allows you to use Docker-in-Docker. It can be practically anything that's
required for the CI/CD job to proceed and is accessed by network. required for the CI/CD job to proceed, and is accessed by network.
To make sure this works, the runner: To make sure this works, the runner:
1. Checks which ports are exposed from the container by default. 1. Checks which ports are exposed from the container by default.
1. Starts a special container that waits for these ports to be accessible. 1. Starts a special container that waits for these ports to be accessible.
When the second stage of the check fails, either because there is no opened port in the If the second stage of the check fails, it prints the warning: `*** WARNING: Service XYZ probably didn't start properly`.
service, or the service was not started properly before the timeout and the port is not This issue can occur because:
responding, it prints the warning: `*** WARNING: Service XYZ probably didn't start properly`.
- There is no opened port in the service.
- The service was not started properly before the timeout, and the port is not
responding.
In most cases it affects the job, but there may be situations when the job In most cases it affects the job, but there may be situations when the job
still succeeds even if that warning was printed. For example: still succeeds even if that warning was printed. For example:
- The service was started a little after the warning was raised, and the job is - The service was started shortly after the warning was raised, and the job is
not using the linked service from the beginning. In that case, when the not using the linked service from the beginning. In that case, when the
job needed to access the service, it may have been already there waiting for job needed to access the service, it may have been already there waiting for
connections. connections.
- The service container is not providing any networking service, but it's doing - The service container is not providing any networking service, but it's doing
something with the job's directory (all services have the job directory mounted something with the job's directory (all services have the job directory mounted
as a volume under `/builds`). In that case, the service does its job, and as a volume under `/builds`). In that case, the service does its job, and
since the job is not trying to connect to it, it does not fail. because the job is not trying to connect to it, it does not fail.
### What services are not for ### What services are not for
As it was mentioned before, this feature is designed to provide **network accessible** As mentioned before, this feature is designed to provide **network accessible**
services. A database is the simplest example of such a service. services. A database is the simplest example of such a service.
The services feature is not designed to, and does not add any software from the The services feature is not designed to, and does not, add any software from the
defined `services` image(s) to the job's container. defined `services` image(s) to the job's container.
For example, if you have the following `services` defined in your job, the `php`, For example, if you have the following `services` defined in your job, the `php`,
`node` or `go` commands are **not** available for your script, and thus `node` or `go` commands are **not** available for your script, and the job fails:
the job fails:
```yaml ```yaml
job: job:
...@@ -162,16 +164,15 @@ If you need to have `php`, `node` and `go` available for your script, you should ...@@ -162,16 +164,15 @@ If you need to have `php`, `node` and `go` available for your script, you should
either: either:
- Choose an existing Docker image that contains all required tools. - Choose an existing Docker image that contains all required tools.
- Create your own Docker image, with all the required tools included - Create your own Docker image, with all the required tools included,
and use that in your job. and use that in your job.
### Accessing the services ### Accessing the services
Let's say that you need a Wordpress instance to test some API integration with Let's say that you need a Wordpress instance to test some API integration with
your application. your application. You can then use for example the
[`tutum/wordpress`](https://hub.docker.com/r/tutum/wordpress/) image in your
You can then use for example the [tutum/wordpress](https://hub.docker.com/r/tutum/wordpress/) image in your `.gitlab-ci.yml` file:
`.gitlab-ci.yml`:
```yaml ```yaml
services: services:
...@@ -179,13 +180,13 @@ services: ...@@ -179,13 +180,13 @@ services:
``` ```
If you don't [specify a service alias](#available-settings-for-services), If you don't [specify a service alias](#available-settings-for-services),
when the job is run, `tutum/wordpress` is started and you have when the job runs, `tutum/wordpress` is started. You have
access to it from your build container under two hostnames to choose from: access to it from your build container under two hostnames:
- `tutum-wordpress` - `tutum-wordpress`
- `tutum__wordpress` - `tutum__wordpress`
Hostnames with underscores are not RFC valid and may cause problems in 3rd party Hostnames with underscores are not RFC valid and may cause problems in third-party
applications. applications.
The default aliases for the service's hostname are created from its image name The default aliases for the service's hostname are created from its image name
...@@ -202,7 +203,7 @@ To override the default behavior, you can ...@@ -202,7 +203,7 @@ To override the default behavior, you can
## Define `image` and `services` from `.gitlab-ci.yml` ## Define `image` and `services` from `.gitlab-ci.yml`
You can simply define an image that's used for all jobs and a list of You can define an image that's used for all jobs, and a list of
services that you want to use during build time: services that you want to use during build time:
```yaml ```yaml
...@@ -275,7 +276,7 @@ test: ...@@ -275,7 +276,7 @@ test:
You can also pass custom environment [variables](../variables/README.md) You can also pass custom environment [variables](../variables/README.md)
to fine tune your Docker `images` and `services` directly in the `.gitlab-ci.yml` file. to fine tune your Docker `images` and `services` directly in the `.gitlab-ci.yml` file.
For more information, see [custom environment variables](../variables/README.md#gitlab-ciyml-defined-variables) For more information, read [custom environment variables](../variables/README.md#gitlab-ciyml-defined-variables)
```yaml ```yaml
# The following variables are automatically passed down to the Postgres container # The following variables are automatically passed down to the Postgres container
...@@ -314,11 +315,11 @@ test: ...@@ -314,11 +315,11 @@ test:
When configuring the `image` or `services` entries, you can use a string or a map as When configuring the `image` or `services` entries, you can use a string or a map as
options: options:
- when using a string as an option, it must be the full name of the image to use - When using a string as an option, it must be the full name of the image to use
(including the Registry part if you want to download the image from a Registry (including the Registry part if you want to download the image from a Registry
other than Docker Hub) other than Docker Hub).
- when using a map as an option, then it must contain at least the `name` - When using a map as an option, then it must contain at least the `name`
option, which is the same name of the image as used for the string setting option, which is the same name of the image as used for the string setting.
For example, the following two definitions are equal: For example, the following two definitions are equal:
...@@ -350,8 +351,8 @@ For example, the following two definitions are equal: ...@@ -350,8 +351,8 @@ For example, the following two definitions are equal:
| Setting | Required | GitLab version | Description | | Setting | Required | GitLab version | Description |
|------------|----------|----------------| ----------- | |------------|----------|----------------| ----------- |
| `name` | yes, when used with any other option | 9.4 |Full name of the image that should be used. It should contain the Registry part if needed. | | `name` | yes, when used with any other option | 9.4 |Full name of the image to use. It should contain the Registry part if needed. |
| `entrypoint` | no | 9.4 |Command or script that should be executed as the container's entrypoint. It's translated to Docker's `--entrypoint` option while creating the container. The syntax is similar to [`Dockerfile`'s `ENTRYPOINT`](https://docs.docker.com/engine/reference/builder/#entrypoint) directive, where each shell token is a separate string in the array. | | `entrypoint` | no | 9.4 |Command or script to execute as the container's entrypoint. It's translated to Docker's `--entrypoint` option while creating the container. The syntax is similar to [`Dockerfile`'s `ENTRYPOINT`](https://docs.docker.com/engine/reference/builder/#entrypoint) directive, where each shell token is a separate string in the array. |
### Available settings for `services` ### Available settings for `services`
...@@ -359,8 +360,8 @@ For example, the following two definitions are equal: ...@@ -359,8 +360,8 @@ For example, the following two definitions are equal:
| Setting | Required | GitLab version | Description | | Setting | Required | GitLab version | Description |
|------------|----------|----------------| ----------- | |------------|----------|----------------| ----------- |
| `name` | yes, when used with any other option | 9.4 | Full name of the image that should be used. It should contain the Registry part if needed. | | `name` | yes, when used with any other option | 9.4 | Full name of the image to use. It should contain the Registry part if needed. |
| `entrypoint` | no | 9.4 |Command or script that should be executed as the container's entrypoint. It's translated to Docker's `--entrypoint` option while creating the container. The syntax is similar to [`Dockerfile`'s `ENTRYPOINT`](https://docs.docker.com/engine/reference/builder/#entrypoint) directive, where each shell token is a separate string in the array. | | `entrypoint` | no | 9.4 |Command or script to execute as the container's entrypoint. It's translated to Docker's `--entrypoint` option while creating the container. The syntax is similar to [`Dockerfile`'s `ENTRYPOINT`](https://docs.docker.com/engine/reference/builder/#entrypoint) directive, where each shell token is a separate string in the array. |
| `command` | no | 9.4 |Command or script that should be used as the container's command. It's translated to arguments passed to Docker after the image's name. The syntax is similar to [`Dockerfile`'s `CMD`](https://docs.docker.com/engine/reference/builder/#cmd) directive, where each shell token is a separate string in the array. | | `command` | no | 9.4 |Command or script that should be used as the container's command. It's translated to arguments passed to Docker after the image's name. The syntax is similar to [`Dockerfile`'s `CMD`](https://docs.docker.com/engine/reference/builder/#cmd) directive, where each shell token is a separate string in the array. |
| `alias` (1) | no | 9.4 |Additional alias that can be used to access the service from the job's container. Read [Accessing the services](#accessing-the-services) for more information. | | `alias` (1) | no | 9.4 |Additional alias that can be used to access the service from the job's container. Read [Accessing the services](#accessing-the-services) for more information. |
...@@ -379,8 +380,8 @@ services: ...@@ -379,8 +380,8 @@ services:
- mysql:latest - mysql:latest
``` ```
The runner would start two containers using the `mysql:latest` image, but both The runner would start two containers, each that uses the `mysql:latest` image.
of them would be added to the job's container with the `mysql` alias based on However, both of them would be added to the job's container with the `mysql` alias, based on
the [default hostname naming](#accessing-the-services). This would end with one the [default hostname naming](#accessing-the-services). This would end with one
of the services not being accessible. of the services not being accessible.
...@@ -404,31 +405,33 @@ in `.gitlab-ci.yml` file. ...@@ -404,31 +405,33 @@ in `.gitlab-ci.yml` file.
> Introduced in GitLab and GitLab Runner 9.4. Read more about the [extended configuration options](#extended-docker-configuration-options). > Introduced in GitLab and GitLab Runner 9.4. Read more about the [extended configuration options](#extended-docker-configuration-options).
Let's assume you have a `super/sql:latest` image with some SQL database Let's assume you have a `super/sql:latest` image with some SQL database
inside it and you would like to use it as a service for your job. Let's also in it. You would like to use it as a service for your job. Let's also
assume that this image does not start the database process while starting assume that this image does not start the database process while starting
the container and the user needs to manually use `/usr/bin/super-sql run` as the container. The user needs to manually use `/usr/bin/super-sql run` as
a command to start the database. a command to start the database.
Before the new extended Docker configuration options, you would need to create Before the new extended Docker configuration options, you would need to:
your own image based on the `super/sql:latest` image, add the default command,
and then use it in job's configuration, like:
```dockerfile - Create your own image based on the `super/sql:latest` image.
# my-super-sql:latest image's Dockerfile - Add the default command.
- Use the image in the job's configuration:
FROM super/sql:latest ```dockerfile
CMD ["/usr/bin/super-sql", "run"] # my-super-sql:latest image's Dockerfile
```
```yaml FROM super/sql:latest
# .gitlab-ci.yml CMD ["/usr/bin/super-sql", "run"]
```
services: ```yaml
# .gitlab-ci.yml
services:
- my-super-sql:latest - my-super-sql:latest
``` ```
After the new extended Docker configuration options, you can now simply After the new extended Docker configuration options, you can
set a `command` in `.gitlab-ci.yml`, like: set a `command` in the `.gitlab-ci.yml` file instead:
```yaml ```yaml
# .gitlab-ci.yml # .gitlab-ci.yml
...@@ -438,15 +441,15 @@ services: ...@@ -438,15 +441,15 @@ services:
command: ["/usr/bin/super-sql", "run"] command: ["/usr/bin/super-sql", "run"]
``` ```
As you can see, the syntax of `command` is similar to [Dockerfile's `CMD`](https://docs.docker.com/engine/reference/builder/#cmd). The syntax of `command` is similar to [Dockerfile's `CMD`](https://docs.docker.com/engine/reference/builder/#cmd).
### Overriding the entrypoint of an image ### Overriding the entrypoint of an image
> Introduced in GitLab and GitLab Runner 9.4. Read more about the [extended configuration options](#extended-docker-configuration-options). > Introduced in GitLab and GitLab Runner 9.4. Read more about the [extended configuration options](#extended-docker-configuration-options).
Before showing the available entrypoint override methods, let's describe shortly Before showing the available entrypoint override methods, let's describe
how the runner starts and uses a Docker image for the containers used in the how the runner starts. It uses a Docker image for the containers used in the
CI jobs: CI/CD jobs:
1. The runner starts a Docker container using the defined entrypoint (default 1. The runner starts a Docker container using the defined entrypoint (default
from `Dockerfile` that may be overridden in `.gitlab-ci.yml`) from `Dockerfile` that may be overridden in `.gitlab-ci.yml`)
...@@ -455,32 +458,35 @@ CI jobs: ...@@ -455,32 +458,35 @@ CI jobs:
[`before_script`](../yaml/README.md#before_script), [`before_script`](../yaml/README.md#before_script),
[`script`](../yaml/README.md#script), [`script`](../yaml/README.md#script),
and [`after_script`](../yaml/README.md#after_script)). and [`after_script`](../yaml/README.md#after_script)).
1. The runner sends the script to the container's shell STDIN and receives the 1. The runner sends the script to the container's shell `stdin` and receives the
output. output.
To override the entrypoint of a Docker image, the recommended solution is to To override the entrypoint of a Docker image, you should
define an empty `entrypoint` in `.gitlab-ci.yml`, so the runner does not start define an empty `entrypoint` in `.gitlab-ci.yml`, so the runner does not start
a useless shell layer. However, that does not work for all Docker versions, and a useless shell layer. However, that does not work for all Docker versions, and
you should check which one your runner is using. Specifically: you should check which one your runner is using:
- If Docker 17.06 or later is used, the `entrypoint` can be set to an empty value. - _If Docker 17.06 or later is used,_ the `entrypoint` can be set to an empty value.
- If Docker 17.03 or previous versions are used, the `entrypoint` can be set to - _If Docker 17.03 or previous versions are used,_ the `entrypoint` can be set to
`/bin/sh -c`, `/bin/bash -c` or an equivalent shell available in the image. `/bin/sh -c`, `/bin/bash -c` or an equivalent shell available in the image.
The syntax of `image:entrypoint` is similar to [Dockerfile's `ENTRYPOINT`](https://docs.docker.com/engine/reference/builder/#entrypoint). The syntax of `image:entrypoint` is similar to [Dockerfile's `ENTRYPOINT`](https://docs.docker.com/engine/reference/builder/#entrypoint).
Let's assume you have a `super/sql:experimental` image with some SQL database Let's assume you have a `super/sql:experimental` image with a SQL database
inside it and you would like to use it as a base image for your job because you in it. You want to use it as a base image for your job because you
want to execute some tests with this database binary. Let's also assume that want to execute some tests with this database binary. Let's also assume that
this image is configured with `/usr/bin/super-sql run` as an entrypoint. That this image is configured with `/usr/bin/super-sql run` as an entrypoint. When
means that when starting the container without additional options, it runs the container starts without additional options, it runs
the database's process, while the runner expects that the image has no the database's process. The runner expects that the image has no
entrypoint or that the entrypoint is prepared to start a shell command. entrypoint or that the entrypoint is prepared to start a shell command.
With the extended Docker configuration options, instead of creating your With the extended Docker configuration options, instead of:
own image based on `super/sql:experimental`, setting the `ENTRYPOINT`
to a shell, and then using the new image in your CI job, you can now simply - Creating your own image based on `super/sql:experimental`.
define an `entrypoint` in `.gitlab-ci.yml`. - Setting the `ENTRYPOINT` to a shell.
- Using the new image in your CI job.
You can now define an `entrypoint` in the `.gitlab-ci.yml` file.
**For Docker 17.06+:** **For Docker 17.06+:**
...@@ -508,7 +514,7 @@ Look for the `[runners.docker]` section: ...@@ -508,7 +514,7 @@ Look for the `[runners.docker]` section:
services = ["mysql:latest", "postgres:latest"] services = ["mysql:latest", "postgres:latest"]
``` ```
The image and services defined this way are added to all job run by The image and services defined this way are added to all jobs run by
that runner. that runner.
## Define an image from a private Container Registry ## Define an image from a private Container Registry
...@@ -516,8 +522,8 @@ that runner. ...@@ -516,8 +522,8 @@ that runner.
To access private container registries, the GitLab Runner process can use: To access private container registries, the GitLab Runner process can use:
- [Statically defined credentials](#using-statically-defined-credentials). That is, a username and password for a specific registry. - [Statically defined credentials](#using-statically-defined-credentials). That is, a username and password for a specific registry.
- [Credentials Store](#using-credentials-store). For more information, see [the relevant Docker documentation](https://docs.docker.com/engine/reference/commandline/login/#credentials-store). - [Credentials Store](#using-credentials-store). For more information, read [the relevant Docker documentation](https://docs.docker.com/engine/reference/commandline/login/#credentials-store).
- [Credential Helpers](#using-credential-helpers). For more information, see [the relevant Docker documentation](https://docs.docker.com/engine/reference/commandline/login/#credential-helpers). - [Credential Helpers](#using-credential-helpers). For more information, read [the relevant Docker documentation](https://docs.docker.com/engine/reference/commandline/login/#credential-helpers).
To define which should be used, the GitLab Runner process reads the configuration in the following order: To define which should be used, the GitLab Runner process reads the configuration in the following order:
...@@ -531,7 +537,7 @@ To define which should be used, the GitLab Runner process reads the configuratio ...@@ -531,7 +537,7 @@ To define which should be used, the GitLab Runner process reads the configuratio
GitLab Runner reads this configuration **only** from `config.toml` and ignores it if GitLab Runner reads this configuration **only** from `config.toml` and ignores it if
it's provided as an environment variable. This is because GitLab Runner uses **only** it's provided as an environment variable. This is because GitLab Runner uses **only**
`config.toml` configuration and does not interpolate **ANY** environment variables at `config.toml` configuration and does not interpolate **any** environment variables at
runtime. runtime.
### Requirements and limitations ### Requirements and limitations
...@@ -543,7 +549,7 @@ runtime. ...@@ -543,7 +549,7 @@ runtime.
at least version **1.8** if you want to use private registries. at least version **1.8** if you want to use private registries.
- Available for [Kubernetes executor](https://docs.gitlab.com/runner/executors/kubernetes.html) - Available for [Kubernetes executor](https://docs.gitlab.com/runner/executors/kubernetes.html)
in GitLab Runner 13.1 and later. in GitLab Runner 13.1 and later.
- [Credentials Store](#using-credentials-store) and [Credential Helpers](#using-credential-helpers) require binaries to be added to the GitLab Runner's `$PATH`, and require access to do so. Therefore, these features are not available on shared runners or any other runner where the user does not have access to the environment where the runner is installed. - [Credentials Store](#using-credentials-store) and [Credential Helpers](#using-credential-helpers) require binaries to be added to the GitLab Runner's `$PATH`, and require access to do so. Therefore, these features are not available on shared runners, or any other runner where the user does not have access to the environment where the runner is installed.
### Using statically-defined credentials ### Using statically-defined credentials
...@@ -562,7 +568,7 @@ See below for examples of each. ...@@ -562,7 +568,7 @@ See below for examples of each.
#### Determining your `DOCKER_AUTH_CONFIG` data #### Determining your `DOCKER_AUTH_CONFIG` data
As an example, let's assume you want to use the `registry.example.com:5000/private/image:latest` As an example, let's assume you want to use the `registry.example.com:5000/private/image:latest`
image, which is private and requires you to sign in to a private container image. This image is private and requires you to sign in to a private container
registry. registry.
Let's also assume that these are the sign-in credentials: Let's also assume that these are the sign-in credentials:
...@@ -592,7 +598,7 @@ Use one of the following methods to determine the value of `DOCKER_AUTH_CONFIG`: ...@@ -592,7 +598,7 @@ Use one of the following methods to determine the value of `DOCKER_AUTH_CONFIG`:
- In some setups, it's possible that Docker client uses the available system key - In some setups, it's possible that Docker client uses the available system key
store to store the result of `docker login`. In that case, it's impossible to store to store the result of `docker login`. In that case, it's impossible to
read `~/.docker/config.json`, so you need to prepare the required read `~/.docker/config.json`, so you must prepare the required
base64-encoded version of `${username}:${password}` and create the Docker base64-encoded version of `${username}:${password}` and create the Docker
configuration JSON manually. Open a terminal and execute the following command: configuration JSON manually. Open a terminal and execute the following command:
...@@ -691,7 +697,7 @@ To add `DOCKER_AUTH_CONFIG` to a runner: ...@@ -691,7 +697,7 @@ To add `DOCKER_AUTH_CONFIG` to a runner:
To configure credentials store, follow these steps: To configure credentials store, follow these steps:
1. To use a credentials store, you need an external helper program to interact with a specific keychain or external store. 1. To use a credentials store, you need an external helper program to interact with a specific keychain or external store.
Make sure helper program is available in GitLab Runner `$PATH`. Make sure the helper program is available in GitLab Runner `$PATH`.
1. Make GitLab Runner use it. There are two ways to accomplish this. Either: 1. Make GitLab Runner use it. There are two ways to accomplish this. Either:
...@@ -710,16 +716,16 @@ To configure credentials store, follow these steps: ...@@ -710,16 +716,16 @@ To configure credentials store, follow these steps:
`${GITLAB_RUNNER_HOME}/.docker/config.json`. GitLab Runner reads this configuration file `${GITLAB_RUNNER_HOME}/.docker/config.json`. GitLab Runner reads this configuration file
and uses the needed helper for this specific repository. and uses the needed helper for this specific repository.
`credsStore` is used to access ALL the registries. `credsStore` is used to access **all** the registries.
If you want to use both images from private registry and public images from Docker Hub, If you use both images from a private registry and public images from Docker Hub,
pulling from Docker Hub would fail, because Docker daemon tries to use the same credentials for **ALL** the registries. pulling from Docker Hub fails. Docker daemon tries to use the same credentials for **all** the registries.
### Using Credential Helpers ### Using Credential Helpers
> Support for using Credential Helpers was added in GitLab Runner 12.0 > Support for using Credential Helpers was added in GitLab Runner 12.0
As an example, let's assume that you want to use the `aws_account_id.dkr.ecr.region.amazonaws.com/private/image:latest` As an example, let's assume that you want to use the `aws_account_id.dkr.ecr.region.amazonaws.com/private/image:latest`
image which is private and requires you to log in into a private container registry. image. This image is private and requires you to log in into a private container registry.
To configure access for `aws_account_id.dkr.ecr.region.amazonaws.com`, follow these steps: To configure access for `aws_account_id.dkr.ecr.region.amazonaws.com`, follow these steps:
...@@ -750,7 +756,7 @@ To configure access for `aws_account_id.dkr.ecr.region.amazonaws.com`, follow th ...@@ -750,7 +756,7 @@ To configure access for `aws_account_id.dkr.ecr.region.amazonaws.com`, follow th
} }
``` ```
This configures Docker to use the credential helper for all Amazon ECR registries. This configures Docker to use the credential helper for all Amazon Elastic Container Registry (ECR) registries.
- Or, if you're running self-managed runners, - Or, if you're running self-managed runners,
add the above JSON to `${GITLAB_RUNNER_HOME}/.docker/config.json`. add the above JSON to `${GITLAB_RUNNER_HOME}/.docker/config.json`.
...@@ -772,13 +778,13 @@ registries to the `"credHelpers"` hash as described above. ...@@ -772,13 +778,13 @@ registries to the `"credHelpers"` hash as described above.
## Configuring services ## Configuring services
Many services accept environment variables which allow you to easily change Many services accept environment variables, which you can use to change
database names or set account names depending on the environment. database names or set account names, depending on the environment.
GitLab Runner 0.5.0 and up passes all YAML-defined variables to the created GitLab Runner 0.5.0 and up passes all YAML-defined variables to the created
service containers. service containers.
For all possible configuration variables check the documentation of each image For all possible configuration variables, check the documentation of each image
provided in their corresponding Docker hub page. provided in their corresponding Docker hub page.
All variables are passed to all services containers. It's not All variables are passed to all services containers. It's not
...@@ -786,12 +792,12 @@ designed to distinguish which variable should go where. ...@@ -786,12 +792,12 @@ designed to distinguish which variable should go where.
### PostgreSQL service example ### PostgreSQL service example
See the specific documentation for Read the specific documentation for
[using PostgreSQL as a service](../services/postgres.md). [using PostgreSQL as a service](../services/postgres.md).
### MySQL service example ### MySQL service example
See the specific documentation for Read the specific documentation for
[using MySQL as a service](../services/mysql.md). [using MySQL as a service](../services/mysql.md).
## How Docker integration works ## How Docker integration works
...@@ -800,15 +806,15 @@ Below is a high level overview of the steps performed by Docker during job ...@@ -800,15 +806,15 @@ Below is a high level overview of the steps performed by Docker during job
time. time.
1. Create any service container: `mysql`, `postgresql`, `mongodb`, `redis`. 1. Create any service container: `mysql`, `postgresql`, `mongodb`, `redis`.
1. Create cache container to store all volumes as defined in `config.toml` and 1. Create a cache container to store all volumes as defined in `config.toml` and
`Dockerfile` of build image (`ruby:2.6` as in above example). `Dockerfile` of build image (`ruby:2.6` as in above example).
1. Create build container and link any service container to build container. 1. Create a build container and link any service container to build container.
1. Start build container and send job script to the container. 1. Start the build container, and send a job script to the container.
1. Run job script. 1. Run the job script.
1. Checkout code in: `/builds/group-name/project-name/`. 1. Checkout code in: `/builds/group-name/project-name/`.
1. Run any step defined in `.gitlab-ci.yml`. 1. Run any step defined in `.gitlab-ci.yml`.
1. Check exit status of build script. 1. Check the exit status of build script.
1. Remove build container and all created service containers. 1. Remove the build container and all created service containers.
## How to debug a job locally ## How to debug a job locally
...@@ -827,8 +833,7 @@ EOF ...@@ -827,8 +833,7 @@ EOF
Here we use as an example the GitLab Runner repository which contains a Here we use as an example the GitLab Runner repository which contains a
Makefile, so running `make` executes the commands defined in the Makefile. Makefile, so running `make` executes the commands defined in the Makefile.
Your mileage may vary, so instead of `make` you could run the command which Instead of `make`, you could run the command which is specific to your project.
is specific to your project.
Then create some service containers: Then create some service containers:
...@@ -850,7 +855,7 @@ docker run --name build -i --link=service-mysql:mysql --link=service-postgres:po ...@@ -850,7 +855,7 @@ docker run --name build -i --link=service-mysql:mysql --link=service-postgres:po
The above command creates a container named `build` that's spawned from The above command creates a container named `build` that's spawned from
the `ruby:2.6` image and has two services linked to it. The `build_script` is the `ruby:2.6` image and has two services linked to it. The `build_script` is
piped using STDIN to the bash interpreter which in turn executes the piped using `stdin` to the bash interpreter which in turn executes the
`build_script` in the `build` container. `build_script` in the `build` container.
When you finish testing and no longer need the containers, you can remove them When you finish testing and no longer need the containers, you can remove them
...@@ -861,5 +866,5 @@ docker rm -f -v build service-mysql service-postgres ...@@ -861,5 +866,5 @@ docker rm -f -v build service-mysql service-postgres
``` ```
This forcefully (`-f`) removes the `build` container, the two service This forcefully (`-f`) removes the `build` container, the two service
containers as well as all volumes (`-v`) that were created with the container containers, and all volumes (`-v`) that were created with the container
creation. creation.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment