mirror of
https://ops.gitlab.net/gitlab-org/gitlab-build-images.git
synced 2025-12-10 18:42:55 +01:00
Use buildkit and inline cache to speed up builds
This commit is contained in:
parent
be7af7d540
commit
e5885af2fb
3 changed files with 7 additions and 7 deletions
|
|
@ -4,8 +4,7 @@
|
||||||
# Hack to set an array in /bin/sh
|
# Hack to set an array in /bin/sh
|
||||||
# http://unix.stackexchange.com/a/137571
|
# http://unix.stackexchange.com/a/137571
|
||||||
- set -- $CI_JOB_NAME
|
- set -- $CI_JOB_NAME
|
||||||
- docker pull --quiet "$CI_REGISTRY_IMAGE:$1" || true
|
- docker build --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from="$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: .deploy
|
extends: .deploy
|
||||||
|
|
@ -13,8 +12,7 @@
|
||||||
# Hack to set an array in /bin/sh
|
# Hack to set an array in /bin/sh
|
||||||
# http://unix.stackexchange.com/a/137571
|
# http://unix.stackexchange.com/a/137571
|
||||||
- set -- $CI_JOB_NAME
|
- set -- $CI_JOB_NAME
|
||||||
- docker pull --quiet "$CI_REGISTRY_IMAGE:$1" || true
|
- docker build --build-arg BUILDKIT_INLINE_CACHE=1 --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 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:$1"
|
- docker push "$CI_REGISTRY_IMAGE:$1"
|
||||||
|
|
||||||
# Used by https://gitlab.com/gitlab-org/charts/auto-deploy-app/-/blob/master/.gitlab-ci.yml
|
# Used by https://gitlab.com/gitlab-org/charts/auto-deploy-app/-/blob/master/.gitlab-ci.yml
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,16 @@
|
||||||
# Run test job always
|
# Run test job always
|
||||||
.test:
|
.test:
|
||||||
stage: test
|
stage: test
|
||||||
|
variables:
|
||||||
|
DOCKER_BUILDKIT: 1
|
||||||
rules:
|
rules:
|
||||||
- when: always
|
- when: always
|
||||||
|
|
||||||
# Run build job only on a default branch when triggered manually
|
# Run build job only on a default branch when triggered manually
|
||||||
.deploy:
|
.deploy:
|
||||||
stage: deploy
|
stage: deploy
|
||||||
|
variables:
|
||||||
|
DOCKER_BUILDKIT: 1
|
||||||
rules:
|
rules:
|
||||||
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
||||||
when: manual
|
when: manual
|
||||||
|
|
|
||||||
|
|
@ -265,9 +265,7 @@ function build_custom_if_needed() {
|
||||||
echo "Building image $build_image_name"
|
echo "Building image $build_image_name"
|
||||||
full_image_name="$CI_REGISTRY_IMAGE:$build_image_name"
|
full_image_name="$CI_REGISTRY_IMAGE:$build_image_name"
|
||||||
|
|
||||||
# This re-uses and builds an existing image if needed
|
docker_command=$(generate_command $@ --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from="$full_image_name" -t "$full_image_name")
|
||||||
docker pull --quiet "$full_image" || true
|
|
||||||
docker_command=$(generate_command $@ --cache-from="$full_image_name" -t "$full_image_name")
|
|
||||||
echo "Docker command:"
|
echo "Docker command:"
|
||||||
printf "\t%s" "$docker_command"
|
printf "\t%s" "$docker_command"
|
||||||
eval $docker_command
|
eval $docker_command
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue