The way I do this is that I have custom images on the Docker Hub for each of our projects and links to them from .gitlab-ci.yml . If I need a new dependency, I edit the Docker file, which is used to create the original image, rebuilds the image and places it using a specific tag and clicks on the Docker Hub.
cat "RUN apt-get install gcc" >> Dockerfile ID=$(docker build) docker tag $ID ACCOUNT/gitlab_ci_image:gcc docker push ACCOUNT/gitlab_ci_image
Then I update the .gitlab-ci.yml file to point to this particular version of the image.
image: ACCOUNT/gitlab_ci_image:gcc build: script: - cd project && make
This allows me to have different dependencies, depending on which commit I'm trying to test (since the gitlab-ci.yml inside this command indicates the runner to use). It also prevents the need to install dependencies every time a test is run on a particular runner, as the runner will reuse the same image if it does not change.
Another nice fact is that with images hosted on the Docker Hub, if the runner needs a specific tag that he doesn’t have on the local computer, he will automatically capture the correct one, so you can have 10 runners and only support one image, and that’s maintenance can be performed on your workstation or on any machine.
I personally think this is a much better solution than trying to cache anything in the runner’s image. This is especially true if you create a new branch to check the code on a newer version of the dependencies. If you had caching, you were having problems with different test environments for your stable and dev branches. Also, in my opinion, tests should be performed in the cleanest environment possible, and this setup does this.
Suver source share