Build images using buildx plugin and automatically push on main branch

This commit is contained in:
Andrejs Cunskis 2022-05-10 17:17:46 +03:00
parent 5a79c03924
commit fe331541d7
No known key found for this signature in database
GPG key ID: 87CB75083F227241
15 changed files with 213 additions and 357 deletions

View file

@ -1,238 +1,125 @@
.test_build:
extends: .test
script:
# Hack to set an array in /bin/sh
# http://unix.stackexchange.com/a/137571
- set -- $CI_JOB_NAME
- docker build --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from="$CI_REGISTRY_IMAGE:$1" -f "Dockerfile.$1" .
.build_and_deploy:
extends: .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 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 push "$CI_REGISTRY_IMAGE:$1"
- docker buildx build --cache-from="$CI_REGISTRY_IMAGE:$1" --cache-to=type=inline --label "ci_pipeline_url=$CI_PIPELINE_URL" --label "ci_job_url=$CI_JOB_URL" -t "$CI_REGISTRY_IMAGE:$1" -f "Dockerfile.$1" .
# Used by https://gitlab.com/gitlab-org/charts/auto-deploy-app/-/blob/master/.gitlab-ci.yml
alpine-helm test:
extends: .test_build
alpine-helm:
extends: .build_and_deploy
# Used by charts CI
# - https://gitlab.com/gitlab-org/charts/elastic-stack/-/blob/master/.gitlab-ci.yml
# - https://gitlab.com/gitlab-org/charts/gitlab/-/blob/master/.gitlab-ci.yml
# - https://gitlab.com/gitlab-org/charts/gitlab-runner/-/blob/main/.gitlab-ci.yml
# - https://gitlab.com/charts/charts.gitlab.io/-/blob/master/.gitlab-ci.yml
gitlab-charts-build-base-helm-3 test:
extends: .test_build
gitlab-charts-build-base-helm-3.7 test:
extends: .test_build
danger:
extends: .build_and_deploy
danger test:
extends: .test_build
danger-ruby-2.6.6 test:
extends: .test_build
gitlab-helm3.5-kubectl1.17 test:
extends: .test_build
gitlab-qa-ruby-2.7 test:
extends: .test_build
gitlab-qa-ruby-3.0 test:
extends: .test_build
gitlab-qa-alpine-ruby-2.7 test:
extends: .test_build
gitlab-qa-alpine-ruby-3.0 test:
extends: .test_build
gitlab-puppeteer test:
extends: .test_build
kaniko test:
extends: .test_build
omnibus-gitlab-bionic test:
extends: .test_build
omnibus-gitlab-centos7 test:
extends: .test_build
omnibus-gitlab-centos8 test:
extends: .test_build
omnibus-gitlab-jessie test:
extends: .test_build
omnibus-gitlab-opensuse15.1 test:
extends: .test_build
omnibus-gitlab-opensuse15.2 test:
extends: .test_build
omnibus-gitlab-opensuse15.3 test:
extends: .test_build
omnibus-gitlab-stretch test:
extends: .test_build
omnibus-gitlab-buster test:
extends: .test_build
omnibus-gitlab-bullseye test:
extends: .test_build
omnibus-gitlab-xenial test:
extends: .test_build
omnibus-gitlab-focal test:
extends: .test_build
omnibus-gitlab-amazonlinux2 test:
extends: .test_build
omnibus-gitlab-depscan test:
extends: .test_build
omnibus-gitlab-cve-search test:
extends: .test_build
danger-ruby-2.6.6:
extends: .build_and_deploy
gitlab-charts-build-base-helm-3:
extends: .build_and_deploy
gitlab-charts-build-base-helm-3.7:
extends: .build_and_deploy
gitlab-helm3.5-kubectl1.17:
extends: .build_and_deploy
gitlab-qa-ruby-2.7:
extends: .build_and_deploy
gitlab-qa-ruby-3.0:
extends: .build_and_deploy
gitlab-qa-alpine-ruby-2.7:
extends: .build_and_deploy
gitlab-qa-alpine-ruby-3.0:
extends: .build_and_deploy
gitlab-puppeteer:
extends: .build_and_deploy
kaniko:
extends: .build_and_deploy
omnibus-gitlab-bionic:
extends: .build_and_deploy
omnibus-gitlab-centos7:
extends: .build_and_deploy
omnibus-gitlab-centos8:
extends: .build_and_deploy
omnibus-gitlab-jessie:
extends: .build_and_deploy
omnibus-gitlab-opensuse15.1:
extends: .build_and_deploy
omnibus-gitlab-opensuse15.2:
extends: .build_and_deploy
omnibus-gitlab-opensuse15.3:
extends: .build_and_deploy
omnibus-gitlab-stretch:
extends: .build_and_deploy
omnibus-gitlab-buster:
extends: .build_and_deploy
omnibus-gitlab-bullseye:
extends: .build_and_deploy
omnibus-gitlab-xenial:
extends: .build_and_deploy
omnibus-gitlab-focal:
extends: .build_and_deploy
omnibus-gitlab-amazonlinux2:
extends: .build_and_deploy
omnibus-gitlab-depscan:
extends: .build_and_deploy
omnibus-gitlab-cve-search:
extends: .build_and_deploy
release-tools:
extends: .build_and_deploy
triage-ops-ruby-2.7:
extends: .build_and_deploy
sitespeed-gitlab:
extends: .build_and_deploy
ubi-release:
extends: .build_and_deploy
www-gitlab-com-ruby-3.0-node-16:
extends: .build_and_deploy
build-git:
extends: .build_and_deploy
release-tools test:
extends: .test_build
triage-ops-ruby-2.7 test:
extends: .test_build
sitespeed-gitlab test:
extends: .test_build
ubi-release test:
extends: .test_build
www-gitlab-com-ruby-3.0-node-16 test:
extends: .test_build
build-git test:
extends: .test_build
# Used by GitLab: https://gitlab.com/gitlab-org/gitlab/-/blob/13-8-stable-ee/lib/gitlab/ci/templates/Terraform.gitlab-ci.yml
terraform test:
extends: .test_build
# 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 test:
extends: .test_build
# Used by gitlab-operator: https://gitlab.com/gitlab-org/gl-openshift/gitlab-operator
gitlab-operator-build-base test:
extends: .test_build
terraform:
extends: .build_and_deploy
alpine-bash-jq-curl-git test:
extends: .test_build
# 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:
extends: .build_and_deploy
# Used by gitlab-operator: https://gitlab.com/gitlab-org/gl-openshift/gitlab-operator
gitlab-operator-build-base:
extends: .build_and_deploy
alpine-bash-jq-curl-git:
extends: .build_and_deploy
# Used by frontend related tasks for linting GraphQL
apollo test:
extends: .test_build
# Used by https://gitlab.com/gitlab-org/charts/auto-deploy-app/-/blob/master/.gitlab-ci.yml
alpine-helm push:
apollo:
extends: .build_and_deploy
needs: ["alpine-helm test"]
# Used by charts CI
# - https://gitlab.com/gitlab-org/charts/elastic-stack/-/blob/master/.gitlab-ci.yml
# - https://gitlab.com/gitlab-org/charts/gitlab/-/blob/master/.gitlab-ci.yml
# - https://gitlab.com/gitlab-org/charts/gitlab-runner/-/blob/main/.gitlab-ci.yml
# - https://gitlab.com/charts/charts.gitlab.io/-/blob/master/.gitlab-ci.yml
gitlab-charts-build-base-helm-3 push:
extends: .build_and_deploy
needs: ["gitlab-charts-build-base-helm-3 test"]
gitlab-charts-build-base-helm-3.7 push:
extends: .build_and_deploy
needs: ["gitlab-charts-build-base-helm-3.7 test"]
danger push:
extends: .build_and_deploy
needs: ["danger test"]
danger-ruby-2.6.6 push:
extends: .build_and_deploy
needs: ["danger-ruby-2.6.6 test"]
gitlab-helm3.5-kubectl1.17 push:
extends: .build_and_deploy
needs: ["gitlab-helm3.5-kubectl1.17 test"]
gitlab-qa-ruby-2.7 push:
extends: .build_and_deploy
needs: ["gitlab-qa-ruby-2.7 test"]
gitlab-qa-ruby-3.0 push:
extends: .build_and_deploy
needs: ["gitlab-qa-ruby-3.0 test"]
gitlab-qa-alpine-ruby-2.7 push:
extends: .build_and_deploy
needs: ["gitlab-qa-alpine-ruby-2.7 test"]
gitlab-qa-alpine-ruby-3.0 push:
extends: .build_and_deploy
needs: ["gitlab-qa-alpine-ruby-3.0 test"]
gitlab-puppeteer push:
extends: .build_and_deploy
needs: ["gitlab-puppeteer test"]
kaniko push:
extends: .build_and_deploy
needs: ["kaniko test"]
omnibus-gitlab-bionic push:
extends: .build_and_deploy
needs: ["omnibus-gitlab-bionic test"]
omnibus-gitlab-centos7 push:
extends: .build_and_deploy
needs: ["omnibus-gitlab-centos7 test"]
omnibus-gitlab-centos8 push:
extends: .build_and_deploy
needs: ["omnibus-gitlab-centos8 test"]
omnibus-gitlab-jessie push:
extends: .build_and_deploy
needs: ["omnibus-gitlab-jessie test"]
omnibus-gitlab-opensuse15.1 push:
extends: .build_and_deploy
needs: ["omnibus-gitlab-opensuse15.1 test"]
omnibus-gitlab-opensuse15.2 push:
extends: .build_and_deploy
needs: ["omnibus-gitlab-opensuse15.2 test"]
omnibus-gitlab-opensuse15.3 push:
extends: .build_and_deploy
needs: ["omnibus-gitlab-opensuse15.3 test"]
omnibus-gitlab-stretch push:
extends: .build_and_deploy
needs: ["omnibus-gitlab-stretch test"]
omnibus-gitlab-buster push:
extends: .build_and_deploy
needs: ["omnibus-gitlab-buster test"]
omnibus-gitlab-bullseye push:
extends: .build_and_deploy
needs: ["omnibus-gitlab-bullseye test"]
omnibus-gitlab-xenial push:
extends: .build_and_deploy
needs: ["omnibus-gitlab-xenial test"]
omnibus-gitlab-focal push:
extends: .build_and_deploy
needs: ["omnibus-gitlab-focal test"]
omnibus-gitlab-amazonlinux2 push:
extends: .build_and_deploy
needs: ["omnibus-gitlab-amazonlinux2 test"]
omnibus-gitlab-depscan push:
extends: .build_and_deploy
needs: ["omnibus-gitlab-depscan test"]
omnibus-gitlab-cve-search push:
extends: .build_and_deploy
needs: ["omnibus-gitlab-cve-search test"]
release-tools push:
extends: .build_and_deploy
needs: ["release-tools test"]
triage-ops-ruby-2.7 push:
extends: .build_and_deploy
needs: ["triage-ops-ruby-2.7 test"]
sitespeed-gitlab push:
extends: .build_and_deploy
needs: ["sitespeed-gitlab test"]
ubi-release push:
extends: .build_and_deploy
needs: ["ubi-release test"]
www-gitlab-com-ruby-3.0-node-16 push:
extends: .build_and_deploy
needs: ["www-gitlab-com-ruby-3.0-node-16 test"]
build-git push:
extends: .build_and_deploy
needs: ["build-git test"]
# Used by GitLab: https://gitlab.com/gitlab-org/gitlab/-/blob/13-8-stable-ee/lib/gitlab/ci/templates/Terraform.gitlab-ci.yml
terraform push:
extends: .build_and_deploy
needs: ["terraform test"]
# 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 push:
extends: .build_and_deploy
needs: ["golangci-lint-alpine test"]
# Used by gitlab-operator: https://gitlab.com/gitlab-org/gl-openshift/gitlab-operator
gitlab-operator-build-base push:
extends: .build_and_deploy
needs: ["gitlab-operator-build-base test"]
alpine-bash-jq-curl-git push:
extends: .build_and_deploy
needs: ["alpine-bash-jq-curl-git test"]
# Used by frontend related tasks for linting GraphQL
apollo push:
extends: .build_and_deploy
needs: ["apollo test"]

View file

@ -1,5 +1,7 @@
# Used by customers-gitlab-com rspec job: https://gitlab.com/gitlab-org/customers-gitlab-com/-/blob/staging/.gitlab-ci.yml
.customers-matrix:
customers:
extends:
- .build_and_push
variables:
LFS: '2.9'
CHROME: '89'
@ -12,19 +14,10 @@
GIT: ['2.33']
DOCKER: ['19.03.1', '']
customers test:
extends:
- .customers-matrix
- .test_custom
customers push:
extends:
- .customers-matrix
- .build_and_deploy_custom
needs: ["customers test"]
# 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-matrix:
customers-qa-assets:
extends:
- .build_and_push
variables:
CHROME: '89'
NODE: '16.14'
@ -34,14 +27,3 @@ customers push:
matrix:
- RUBY: ['2.7.6']
GIT: ['2.33']
customers-qa-assets test:
extends:
- .customers-qa-matrix
- .test_custom
customers-qa-assets push:
extends:
- .customers-qa-matrix
- .build_and_deploy_custom
needs: ["customers-qa-assets test"]

View file

@ -1,25 +1,12 @@
# Run test job always
.test:
stage: test
rules:
- when: always
# Run build job only on a default branch when triggered manually
.deploy:
.build_and_push:
stage: deploy
needs: []
script:
- ./scripts/lib/custom-docker-build
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
variables:
PUSH_CUSTOM_IMAGE: "false"
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: manual
.test_custom:
extends: .test
script:
- ./scripts/custom-docker-build
rules:
- when: always
.build_and_deploy_custom:
extends: .deploy
script:
- ./scripts/custom-docker-build --label "ci_pipeline_url=$CI_PIPELINE_URL" --label "ci_job_url=$CI_JOB_URL"
- ./scripts/custom-docker-push
variables:
PUSH_CUSTOM_IMAGE: "true"

View file

@ -0,0 +1,8 @@
# Docker image with buildx plugin
docker:
variables:
DEBIAN: bullseye
DOCKER: '20.10.14'
BUILDX: '0.8'
extends:
- .build_and_push

View file

@ -1,40 +1,22 @@
# Used by gitlab e2e tests and other qa related tasks
# Base image used by QA framework unit tests and other jobs not requiring full toolset
.e2e-base:
e2e-base:
variables:
DEBIAN: bullseye
GIT: '2.33'
RUBY: '2.7'
BUNDLER: '2.3'
CHROME: '99'
extends:
- .build_and_push
# Image used for running full e2e test suite
.e2e-full:
e2e-full:
variables:
LFS: '2.9'
GCLOUD: '383'
KUBECTL: '1.23'
DOCKER: '20.10.14'
e2e-base test:
extends:
- .e2e-base
- .test_custom
e2e-base push:
extends:
- .e2e-base
- .build_and_deploy_custom
needs: ["e2e-base test"]
e2e-full test:
extends:
- .e2e-base
- .e2e-full
- .test_custom
e2e-full push:
extends:
- .e2e-base
- .e2e-full
- .build_and_deploy_custom
needs: ["e2e-full test"]
- e2e-base

View file

@ -1,5 +1,9 @@
# Used by Gitaly: https://gitlab.com/gitlab-org/gitaly/blob/master/.gitlab-ci.yml
.gitaly-matrix:
gitaly:
needs: []
extends:
- .build_and_push
stage: deploy-gitaly
parallel:
matrix:
- DEBIAN: ['bullseye']
@ -8,16 +12,3 @@
GIT: ['2.33']
PGBOUNCER: ['1.14', '']
POSTGRESQL: ['11', '12', '13'] # We only use the postgresql-client
gitaly test:
needs: []
extends:
- .gitaly-matrix
- .test_custom
gitaly push:
extends:
- .gitaly-matrix
- .build_and_deploy_custom
stage: deploy-gitaly
needs: ["gitaly test"]

View file

@ -1,5 +1,8 @@
# Used by GitLab: https://gitlab.com/gitlab-org/gitlab/blob/master/.gitlab-ci.yml
.gitlab-matrix:
gitlab:
extends:
- .build_and_push
stage: deploy-gitlab
variables:
LFS: '2.9'
YARN: '1.22'
@ -13,21 +16,13 @@
GOLANG: ['1.16', '1.17']
NODE: ['16.14']
CHROME: ['94', '99']
gitlab test:
extends:
- .gitlab-matrix
- .test_custom
gitlab push:
extends:
- .gitlab-matrix
- .build_and_deploy_custom
stage: deploy-gitlab
needs: ["gitlab test"]
# Used by GitLab's compile-production-assets and compile-test-assets jobs
.gitlab-assets-matrix:
gitlab-assets:
extends:
- .build_and_push
stage: deploy-gitlab-assets
variables:
LFS: '2.9'
YARN: '1.22'
@ -38,15 +33,3 @@ gitlab push:
RUBY: ['2.7', '3.0']
GIT: ['2.33']
NODE: ['16.14']
gitlab-assets test:
extends:
- .gitlab-assets-matrix
- .test_custom
gitlab-assets push:
extends:
- .gitlab-assets-matrix
- .build_and_deploy_custom
stage: deploy-gitlab-assets
needs: ["gitlab-assets test"]

View file

@ -1,5 +1,7 @@
# Used by GitLab/KAS integration tests
.gitlab-kas-matrix:
gitlab-kas:
extends:
- .build_and_push
variables:
GOLANG: '1.16'
LFS: '2.9'
@ -12,14 +14,3 @@
parallel:
matrix:
- RUBY: ['2.7.2.patched', '2.7.patched', '3.0.patched']
gitlab-kas test:
extends:
- .gitlab-kas-matrix
- .test_custom
gitlab-kas push:
extends:
- .gitlab-kas-matrix
- .build_and_deploy_custom
needs: ["gitlab-kas test"]