From 2269f81b22fc1b52e867602e0b273ffff7af2d59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Tue, 2 Feb 2021 13:44:38 +0100 Subject: [PATCH] It is `cache-from` --- .gitlab-ci.yml | 16 +++++++++++----- scripts/custom-docker-build | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ae34a2d..5968ff3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -38,13 +38,16 @@ variables: # http://unix.stackexchange.com/a/137571 - set -- $CI_JOB_NAME - docker pull "$CI_REGISTRY_IMAGE:$1" || true - - docker build --from-cache="$CI_REGISTRY_IMAGE:$1" -f "Dockerfile.$1" . + - docker build --cache-from="$CI_REGISTRY_IMAGE:$1" -f "Dockerfile.$1" . .build_and_deploy: &build_and_deploy extends: .build script: + # Hack to set an array in /bin/sh + # http://unix.stackexchange.com/a/137571 + - set -- $CI_JOB_NAME - docker pull "$CI_REGISTRY_IMAGE:$1" || true - - docker build --from-cache="$CI_REGISTRY_IMAGE:$1" --label "ci_pipeline_url=$CI_PIPELINE_URL" --label "ci_job_url=$CI_JOB_URL" -t "$CI_REGISTRY_IMAGE:$CI_JOB_NAME" -f "Dockerfile.$CI_JOB_NAME" . + - docker build --cache-from="$CI_REGISTRY_IMAGE:$1" --label "ci_pipeline_url=$CI_PIPELINE_URL" --label "ci_job_url=$CI_JOB_URL" -t "$CI_REGISTRY_IMAGE:$1" -f "Dockerfile.$1" . - docker push "$CI_REGISTRY_IMAGE:$CI_JOB_NAME" .test_custom: &test_custom @@ -53,15 +56,18 @@ variables: # Hack to set an array in /bin/sh # http://unix.stackexchange.com/a/137571 - set -- $CI_JOB_NAME - - ./scripts/custom-docker-build $1 + - ./scripts/custom-docker-build "$1" rules: - when: always .build_and_deploy_custom: &build_and_deploy_custom extends: .build script: - - ./scripts/custom-docker-build $CI_JOB_NAME --label "ci_pipeline_url=$CI_PIPELINE_URL" --label "ci_job_url=$CI_JOB_URL" -t "$CI_REGISTRY_IMAGE:$CI_JOB_NAME" - - docker push "$CI_REGISTRY_IMAGE:$CI_JOB_NAME" + # Hack to set an array in /bin/sh + # http://unix.stackexchange.com/a/137571 + - set -- $CI_JOB_NAME + - ./scripts/custom-docker-build "$1" --label "ci_pipeline_url=$CI_PIPELINE_URL" --label "ci_job_url=$CI_JOB_URL" -t "$CI_REGISTRY_IMAGE:$1" + - docker push "$CI_REGISTRY_IMAGE:$1" # Tests diff --git a/scripts/custom-docker-build b/scripts/custom-docker-build index e207c35..d2e8fd2 100755 --- a/scripts/custom-docker-build +++ b/scripts/custom-docker-build @@ -305,7 +305,7 @@ function build_custom_if_needed() { # This re-uses and builds an existing image if needed docker pull "$full_image" || true - docker_command=$(generate_command $@ --from-cache="$full_image_name" ) + docker_command=$(generate_command $@ --cache-from="$full_image_name" ) echo "Building $build_image_name with $docker_command" eval $docker_command }