ci: Only build custom images that need to be rebuilt

Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
Rémy Coutable 2023-01-25 18:39:28 +01:00
parent ccd8e00291
commit 684f0ce8ef
No known key found for this signature in database
10 changed files with 125 additions and 62 deletions

View file

@ -5,7 +5,13 @@ include:
workflow: workflow:
rules: rules:
- if: $CI_MERGE_REQUEST_IID - if: $CI_MERGE_REQUEST_IID
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_SERVER_HOST == "gitlab.com"'
variables:
PUSH_CUSTOM_IMAGE: "true"
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && ($CI_SERVER_HOST == "ops.gitlab.net" || $CI_SERVER_HOST == "dev.gitlab.org")'
variables:
PUSH_CUSTOM_IMAGE: "true"
BASE_BUILD_REGISTRY_IMAGE: $CI_REGISTRY_IMAGE
default: default:
interruptible: true interruptible: true

View file

@ -1,72 +1,54 @@
.build_and_deploy:
extends: .build_and_push
script:
# Hack to set an array in /bin/sh
# http://unix.stackexchange.com/a/137571
- set -- $CI_JOB_NAME
- |
docker buildx build \
--cache-to=type=inline \
--cache-from="$CI_REGISTRY_IMAGE:$1" \
--platform=linux/${ARCH:-amd64} \
--push="${PUSH_CUSTOM_IMAGE:-false}" \
--label "ci_pipeline_url=$CI_PIPELINE_URL" \
--label "ci_job_url=$CI_JOB_URL" \
-t "$CI_REGISTRY_IMAGE:$1" \
-f "Dockerfile.$1" \
.
danger: danger:
extends: .build_and_deploy extends: .build_static_image
gitlab-charts-build-base-helm-3.7: gitlab-charts-build-base-helm-3.7:
extends: .build_and_deploy extends: .build_static_image
gitlab-helm3.5-kubectl1.17: gitlab-helm3.5-kubectl1.17:
extends: .build_and_deploy extends: .build_static_image
gitlab-vscode-nodeless: gitlab-vscode-nodeless:
extends: .build_and_deploy extends: .build_static_image
kaniko: kaniko:
extends: .build_and_deploy extends: .build_static_image
release-tools: release-tools:
extends: .build_and_deploy extends: .build_static_image
triage-ops-ruby-2.7: triage-ops-ruby-2.7:
extends: .build_and_deploy extends: .build_static_image
sitespeed-gitlab: sitespeed-gitlab:
extends: .build_and_deploy extends: .build_static_image
ubi-release: ubi-release:
extends: .build_and_deploy extends: .build_static_image
www-gitlab-com-debian-bullseye-ruby-3.0-node-16: www-gitlab-com-debian-bullseye-ruby-3.0-node-16:
extends: .build_and_deploy extends: .build_static_image
build-git: build-git:
extends: .build_and_deploy extends: .build_static_image
# Used by GitLab: https://gitlab.com/gitlab-org/gitlab/-/blob/13-8-stable-ee/lib/gitlab/ci/templates/Terraform.gitlab-ci.yml # Used by GitLab: https://gitlab.com/gitlab-org/gitlab/-/blob/13-8-stable-ee/lib/gitlab/ci/templates/Terraform.gitlab-ci.yml
terraform: terraform:
extends: .build_and_deploy extends: .build_static_image
# Used by go projects for linting https://gitlab.com/gitlab-org/gitlab/blob/master/doc/development/go_guide/index.md#automatic-linting # Used by go projects for linting https://gitlab.com/gitlab-org/gitlab/blob/master/doc/development/go_guide/index.md#automatic-linting
golangci-lint-alpine: golangci-lint-alpine:
extends: .build_and_deploy extends: .build_static_image
# Used by gitlab-operator: https://gitlab.com/gitlab-org/cloud-native/gitlab-operator # Used by gitlab-operator: https://gitlab.com/gitlab-org/cloud-native/gitlab-operator
gitlab-operator-build-base-golang-1.18: gitlab-operator-build-base-golang-1.18:
extends: .build_and_deploy extends: .build_static_image
alpine-bash-jq-curl-git: alpine-bash-jq-curl-git:
extends: .build_and_deploy extends: .build_static_image
# Used by frontend related tasks for linting GraphQL # Used by frontend related tasks for linting GraphQL
apollo: apollo:
extends: .build_and_deploy extends: .build_static_image
zoekt-ci-image: zoekt-ci-image:
extends: .build_and_deploy extends: .build_static_image

View file

@ -1,7 +1,16 @@
.customers:
extends:
- .build_dynamic_image
rules:
- !reference [.build_dynamic_image, rules]
- changes:
- "scripts/lib/custom-docker-build"
- ".gitlab/ci/customers.images.yml"
# Used by customers-gitlab-com rspec job: https://gitlab.com/gitlab-org/customers-gitlab-com/-/blob/staging/.gitlab-ci.yml # Used by customers-gitlab-com rspec job: https://gitlab.com/gitlab-org/customers-gitlab-com/-/blob/staging/.gitlab-ci.yml
customers: customers:
extends: extends:
- .build_and_push - .customers
variables: variables:
LFS: '2.9' LFS: '2.9'
CHROME: '107' CHROME: '107'
@ -17,7 +26,7 @@ customers:
# Used by customers-gitlab-com qa e2e test: https://gitlab.com/gitlab-org/customers-gitlab-com/-/blob/staging/.gitlab/ci/e2e.gitlab-ci.yml # Used by customers-gitlab-com qa e2e test: https://gitlab.com/gitlab-org/customers-gitlab-com/-/blob/staging/.gitlab/ci/e2e.gitlab-ci.yml
customers-qa-assets: customers-qa-assets:
extends: extends:
- .build_and_push - .customers
variables: variables:
CHROME: '107' CHROME: '107'
NODE: '16.14' NODE: '16.14'

View file

@ -19,7 +19,7 @@
fi fi
- docker buildx create --use # creates and set's to active buildkit builder - docker buildx create --use # creates and set's to active buildkit builder
.build_and_push: .build_dynamic_image:
stage: custom stage: custom
extends: .install-qemu extends: .install-qemu
needs: [] needs: []
@ -28,14 +28,38 @@
rules: rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"' - if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never when: never
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_SERVER_HOST == "gitlab.com"'
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_SERVER_HOST == "gitlab.com"' .build_static_image:
variables: stage: custom
PUSH_CUSTOM_IMAGE: "true" extends: .install-qemu
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && ($CI_SERVER_HOST == "ops.gitlab.net" || $CI_SERVER_HOST == "dev.gitlab.org")' needs: []
variables: script:
PUSH_CUSTOM_IMAGE: "true" # Hack to set an array in /bin/sh
BASE_BUILD_REGISTRY_IMAGE: $CI_REGISTRY_IMAGE # http://unix.stackexchange.com/a/137571
- set -- $CI_JOB_NAME
- |
docker buildx build \
--cache-to=type=inline \
--cache-from="$CI_REGISTRY_IMAGE:$1" \
--platform=linux/${ARCH:-amd64} \
--push="${PUSH_CUSTOM_IMAGE:-false}" \
--label "ci_pipeline_url=$CI_PIPELINE_URL" \
--label "ci_job_url=$CI_JOB_URL" \
-t "$CI_REGISTRY_IMAGE:$1" \
-f "Dockerfile.$1" \
.
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
- if: '$CI_MERGE_REQUEST_IID'
changes:
- "Dockerfile.${CI_JOB_NAME}"
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
changes:
- "Dockerfile.${CI_JOB_NAME}"
# In all other cases, make the job manual
- when: manual
allow_failure: true
.cache-google-chrome: .cache-google-chrome:
stage: automation stage: automation
@ -63,9 +87,11 @@
-f "Dockerfile.cache-chrome" \ -f "Dockerfile.cache-chrome" \
. .
rules: rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_SERVER_HOST == "gitlab.com"' - if: '$CI_SERVER_HOST != "gitlab.com"'
- if: '$CI_PIPELINE_SOURCE == "schedule" && $CI_SERVER_HOST == "gitlab.com"' when: never
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_SERVER_HOST == "gitlab.com"' - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- if: '$CI_PIPELINE_SOURCE == "schedule"'
- if: '$CI_MERGE_REQUEST_IID'
when: manual when: manual
allow_failure: true allow_failure: true

View file

@ -1,19 +1,24 @@
# Docker image with buildx plugin # Docker image with buildx plugin
.docker: .docker:
extends:
- .build_dynamic_image
variables: variables:
DOCKER: '20.10.21' DOCKER: '20.10.21'
BUILDX: '0.9' BUILDX: '0.9'
rules:
- !reference [.build_dynamic_image, rules]
- changes:
- "scripts/lib/custom-docker-build"
- ".gitlab/ci/docker.images.yml"
docker: docker:
extends: extends:
- .docker - .docker
- .build_and_push
variables: variables:
OS: "debian:bullseye" OS: "debian:bullseye"
docker-slim: docker-slim:
extends: extends:
- .docker - .docker
- .build_and_push
variables: variables:
OS: "debian:bullseye-slim" OS: "debian:bullseye-slim"

View file

@ -1,9 +1,17 @@
# Used by gitlab e2e tests and other qa related tasks # Used by gitlab e2e tests and other qa related tasks
.e2e:
extends:
- .build_dynamic_image
rules:
- !reference [.build_dynamic_image, rules]
- changes:
- "scripts/lib/custom-docker-build"
- ".gitlab/ci/e2e.images.yml"
# Base image with just ruby and bundler # Base image with just ruby and bundler
e2e: e2e:
extends: extends:
- .build_and_push - .e2e
variables: variables:
OS: "debian:bullseye" OS: "debian:bullseye"
BUNDLER: '2.3' BUNDLER: '2.3'

View file

@ -1,8 +1,17 @@
# Used by Gitaly: https://gitlab.com/gitlab-org/gitaly/blob/master/.gitlab-ci.yml # Used by Gitaly: https://gitlab.com/gitlab-org/gitaly/blob/master/.gitlab-ci.yml
.gitaly:
extends:
- .build_dynamic_image
rules:
- !reference [.build_dynamic_image, rules]
- changes:
- "scripts/lib/custom-docker-build"
- ".gitlab/ci/gitaly.images.yml"
gitaly: gitaly:
needs: [] needs: []
extends: extends:
- .build_and_push - .gitaly
stage: gitaly stage: gitaly
parallel: parallel:
matrix: matrix:

View file

@ -1,7 +1,17 @@
# Used by GitLab: https://gitlab.com/gitlab-org/gitlab/blob/master/.gitlab-ci.yml # Used by GitLab: https://gitlab.com/gitlab-org/gitlab/blob/master/.gitlab-ci.yml
.gitlab:
extends:
- .build_dynamic_image
stage: gitlab
rules:
- !reference [.build_dynamic_image, rules]
- changes:
- "scripts/lib/custom-docker-build"
- ".gitlab/ci/gitlab.images.yml"
gitlab: gitlab:
extends: extends:
- .build_and_push - .gitlab
stage: gitlab stage: gitlab
variables: variables:
RUBYGEMS: '3.2' RUBYGEMS: '3.2'
@ -22,8 +32,7 @@ gitlab:
gitlab-ruby-3.2: gitlab-ruby-3.2:
extends: extends:
- .build_and_push - .gitlab
stage: gitlab
variables: variables:
RUBYGEMS: '3.4' RUBYGEMS: '3.4'
LFS: '2.9' LFS: '2.9'
@ -44,7 +53,7 @@ gitlab-ruby-3.2:
# Used by GitLab's compile-production-assets and compile-test-assets jobs # Used by GitLab's compile-production-assets and compile-test-assets jobs
gitlab-assets: gitlab-assets:
extends: extends:
- .build_and_push - .gitlab
stage: gitlab-assets stage: gitlab-assets
variables: variables:
RUBYGEMS: '3.2' RUBYGEMS: '3.2'
@ -62,7 +71,7 @@ gitlab-assets:
# Used by GitLab's Review app jobs # Used by GitLab's Review app jobs
gitlab-review-app: gitlab-review-app:
extends: extends:
- .build_and_push - .gitlab
stage: gitlab-review-app stage: gitlab-review-app
variables: variables:
RUBY: '3.0' RUBY: '3.0'

View file

@ -1,7 +1,16 @@
# Used by GitLab/KAS integration tests # Used by GitLab/KAS integration tests
.kas:
extends:
- .build_dynamic_image
rules:
- !reference [.build_dynamic_image, rules]
- changes:
- "scripts/lib/custom-docker-build"
- ".gitlab/ci/kas.images.yml"
gitlab-kas: gitlab-kas:
extends: extends:
- .build_and_push - .kas
variables: variables:
GOLANG: '1.19' GOLANG: '1.19'
RUST: '1.65.0' RUST: '1.65.0'

View file

@ -27,7 +27,7 @@ Assuming the image you want to add is called `new-image`:
```yml ```yml
new-image: new-image:
extends: .build_and_deploy extends: .build_static_image
``` ```
1. Add a Dockerfile: `Dockerfile.new-image`. 1. Add a Dockerfile: `Dockerfile.new-image`.
@ -84,7 +84,7 @@ following job definition would have to be created:
```yml ```yml
new_image: new_image:
extends: extends:
- .build_and_push - .build_dynamic_image
variables: variables:
OS: 'debian:bullseye' OS: 'debian:bullseye'
RUBY: '3.0' RUBY: '3.0'