stages: - build variables: DOCKER_DRIVER: overlay2 DOCKER_TLS_CERTDIR: '' simple-build-job: image: docker:stable services: - docker:dind stage: build variables: IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - docker pull $IMAGE_TAG || true - docker build --pull -f Dockerfile -t $IMAGE_TAG --cache-from $IMAGE_TAG . - docker push $IMAGE_TAG speedup-build-job: image: docker:stable services: - docker:dind stage: build variables: IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - docker pull $IMAGE_TAG || true - docker build --pull -f Dockerfile -t $IMAGE_TAG --cache-from $IMAGE_TAG . - docker push $IMAGE_TAG speedup-multistage-build-job: image: docker:stable services: - docker:dind stage: build variables: IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - docker pull "$(echo $IMAGE_TAG)-builder" || true - docker pull $IMAGE_TAG || true - docker build --pull -f Dockerfile -t "$(echo $IMAGE_TAG)-builder" --target build-stage --cache-from "$(echo $IMAGE_TAG)-builder" --cache-from $IMAGE_TAG . - docker build --pull -f Dockerfile -t $IMAGE_TAG --cache-from "$(echo $IMAGE_TAG)-builder" --cache-from $IMAGE_TAG . - docker push "$(echo $IMAGE_TAG)-builder" - docker push $IMAGE_TAG
ci, docker, gitlab, pipeline — May 5, 2021