Possible solutions:
- Shell executer
https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-shell-executor
- Pro:
- Easy setup
- Runner can be added on system, group and on project level
- Con:
- Maintain additional runner for docker builds
- Tags for all runner and jobs to avoid running jobs on wrong runner if not already
- Pro:
- dind
https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-docker-in-docker-executor- Pro:
- Easy setup
- Con:
- No access control who can build
- Pro:
- Docker Socket binding
https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-docker-socket-binding- Pro:
- Easy setup
- Con:
- No access control who can build
- Everyone can control the docker daemon of the host!!!
- Pro:
- Docker TLS
https://docs.docker.com/engine/security/https/
https://docs.docker.com/config/daemon/#troubleshoot-conflicts-between-the-daemonjson-and-startup-scripts- Pro:
- Just projects / developer with access to the keys can control the docker daemon
- Con:
- Setup is more complex as you need a CA and a workflow to distribute the keys
- Pro:
- kaniko since GitLab 11.2
https://about.gitlab.com/2018/08/22/gitlab-11-2-released/#securely-build-docker-images-with-kaniko
https://docs.gitlab.com/ee/ci/docker/using_kaniko.html Not tested by myself yet!- Con:
- No docker-compose support ATM
- Con:
- https://docs.docker.com/engine/security/https/ (https://docs.docker.com/config/daemon/#troubleshoot-conflicts-between-the-daemonjson-and-startup-scripts)
The environment variables contain all necessary stuff to login to your GitLab Docker registry and to set the right image name for the project... https://docs.gitlab.com/ce/ci/variables/.
To structure multiple services just add a level to the image name, e.g. ${CI_REGISTRY_IMAGE}/web
.
You just have to add
- DOCKER_CA
- DOCKER_CERT
- DOCKER_KEY
as (protected) (group) vars to authenticate at your docker host. Protected vars are only available for builds of protected branches. So just users with the permission to merge to a protected branch can trigger a build/deployment.