Tasks: Building Docker Images
Before deploying anything, you will most of the time want ContinuousPipe to build your Docker images. For this you need to use the build
task, which is one of the inbuilt tasks.
The only mandatory parameter of build
is the image name you want to build:
tasks:
images:
build:
services:
web:
image: docker.io/your-namespace/your-application
You can obviously use any other image name as long as it contains the Docker registry as first part of it. You can also see that it’s configured per service, here we have only one (named web
) that we need to deploy.
ContinuousPipe is getting parameters from your docker-compose.yml
file. The image
is the only required value if you have such a Docker Compose file.
Warning
Always think carefully before pushing your images to a public Docker repository. If you are using a private Git repository or your build contains secrets (e.g. Github token, database passwords) then you need to ensure that you use a private Docker repository. Docker Hub and Quay.io both offer private repositories as part of their subscription plans.
Naming Strategy
At the moment, there are two naming strategies: the default one being the sha1
strategy, which basically builds a tag per commit SHA1. If you require it you can instead use the branch
strategy, which will create a tag per branch.
tasks:
images:
build:
services:
web:
# ...
naming_strategy: branch
Warning
The branch naming strategy is not recommended, as sometimes when clusters are updated they do not force pull the new image while rolling-updating the services.
Arguments
If you need to inject token or strings in your build process in order to download private dependencies for instance, you can use Docker build arguments.
The following example shows how to install PHP private dependencies (using Composer) using a private GitHub token:
tasks:
images:
build:
environment:
- name: GITHUB_TOKEN
value: ${GITHUB_TOKEN}
# ...
Note
This assumes that you have defined the GITHUB_TOKEN
variable somewhere. You can refer to the variable section.
The following is an example Docker file to demonstrate how the GITHUB_TOKEN
will be used during the build:
Dockerfile
# ... ARG GITHUB_TOKEN= RUN composer config github-oauth.github.com $GITHUB_TOKEN && \ composer install -o --no-interaction && \ composer clear-cache
If you want to build multiple services at the same time, you can also provide the build argument per service:
tasks:
images:
build:
services:
api:
environment:
- name: GITHUB_TOKEN
value: ${GITHUB_TOKEN}
# ...
Artifacts
In order to build small images and/or hide secret values required during the build process, you can use artifacts. These artifacts will allow you to share files or folders between different build steps that use a combination of Dockerfiles, context and build arguments.
For more information see the artifacts documentation.