Let's say you have a ruby project. You write tests using rspec and you write documentation inside the code. And you are using awesome GitLab to host your git repo, run CI pipelines and store your docker images in registry.
First we need to build an image. But we want to leverage docker layer caching, because libraries (rubygems) doesn't update very often. That's why we do docker pull first, and docker build --cache-from after.
If you make a feature branch and update some libraries, you can't use layer with libraries form the master branch. That's why we try to docker pull for feature branch first, and docker pull for master branch after.
And we push built image after to the registry.
We use our just built image by setting image for the job. We already have the code inside the image and we don't need to check it out again.
BUT there is a gotcha, current working directory is $CI_PROJECT_DIR and our source code lays in /app. Do cd /app in before_script.
When GitLab runner starts a job with you image, it creates a project directory on the host, run a new docker container with the image and mounts project directory as a volume.
After pages is generated, GitLab waits for it in the project directory, that's why we need to move the docs from our docker container to the project directory.
#docker #gitlab-ci