Reputation: 121
I'm running a Django application on Heroku in a Docker container. (The container is necessary to install a couple of extra drivers.) I'm pushing the image from gitlab CI in a gitlab-ci.yml
file. My problem is that it takes a while for the image to build. That is because gitlab has no cache of the image. When I pull the image from Heroku first, it seems that it is ignored by gitlab. My .gitlab-ci.yml
file looks like this:
image: docker:latest
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay
stages:
- build
docker-build:
stage: build
script:
- docker login -u _ -p $HEROKU_TOKEN registry.heroku.com
- docker pull registry.heroku.com/xxx/web
- docker build . -f Dockerfile --iidfile imageid.txt -t registry.heroku.com/xxx/web
- docker push registry.heroku.com/xxx/web
The code is working just fine, but it just takes a while to build because it has no cache. Can anyone help me speeding up my deployments? Thanks!
Upvotes: 1
Views: 564
Reputation: 124
Depending on your Gitlab setup, the Ci runner may run directly on a host or in a distributed environment. In the latter case, Gitlab documentation mentions using —from-cache option when building docker images: https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#using-docker-caching
Essentially it’ll pull the latest version of the image being built from Heroku docker registry and use it to build only layers that have changed on the updated image.
In order to update the latest tag on docker registry and use the freshest image version as cache in the next build, you can tag your built image with both its version and “latest” before pushing it back to the registry.
Upvotes: 1