Docker Builder is a way for Open Source projects to build and publish Docker Images to Docker Registries of their choice.
In essence, a
docker_builder is basically a
task that is executed in a VM with pre-installed Docker.
docker_builder can be defined the same way as a
docker_builder: build_script: docker build --tag myrepo/foo:latest .
In the example below, a
docker_builder will be only executed on a tag creation, once both
tasks have finished successfully:
test_task: ... lint_task: ... docker_builder: only_if: $CIRRUS_TAG != '' depends_on: - test - lint env: DOCKER_USERNAME: ENCRYPTED[...] DOCKER_PASSWORD: ENCRYPTED[...] build_script: docker build --tag myrepo/foo:$CIRRUS_TAG . login_script: docker login --username $DOCKER_USERNAME --password $DOCKER_PASSWORD push_script: docker push myrepo/foo:$CIRRUS_TAG
For more examples please check how we use Docker Builder to build and publish Cirrus CI's Docker Images for Android.
--cache-from flag which allows to use a previously built image as a cache source. This way only changed
layers will be rebuilt which can drastically improve performance of
build_script. Here is a snippet that uses
# pull an image if available docker pull myrepo/foo:latest || true docker build --cache-from myrepo/foo:latest \ --tag myrepo/foo:$CIRRUS_TAG \ --tag myrepo/foo:latest .