diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2d0f0e3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +.git/ +.gitlab/ +scripts/lib/ + +Dockerfile* +.gitlab-ci.yml +CODEOWNERS +CONTRIBUTING.md +LICENSE +README.md diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2d03e6d..ce9cb17 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,27 +4,26 @@ include: - local: '.gitlab/ci/*.yml' default: - image: docker:20.10.14-git + image: ${CI_REGISTRY_IMAGE}/debian-bullseye:docker-20.10.14-buildx-0.8 services: - docker:20.10.14-dind before_script: - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY" - - apk add -U bash tags: - gitlab-org-docker stages: - - test - - deploy - - deploy-gitlab - - deploy-gitlab-assets - - deploy-gitaly + - custom + - gitlab + - gitlab-assets + - gitaly - automation variables: - DOCKER_DRIVER: overlay2 - DOCKER_HOST: tcp://docker:2375 - DOCKER_BUILDKIT: 1 + DOCKER_HOST: tcp://docker:2376 + DOCKER_TLS_CERTDIR: /certs + DOCKER_CERT_PATH: /certs/client + DOCKER_TLS_VERIFY: 1 cache-google-chrome: image: debian:bullseye-slim diff --git a/.gitlab/ci/custom.images.yml b/.gitlab/ci/custom.images.yml index 5cf0548..8628e49 100644 --- a/.gitlab/ci/custom.images.yml +++ b/.gitlab/ci/custom.images.yml @@ -1,238 +1,134 @@ -.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-to=type=inline \ + --cache-from="$CI_REGISTRY_IMAGE:$1" \ + --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" \ + . # 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"] diff --git a/.gitlab/ci/customers.images.yml b/.gitlab/ci/customers.images.yml index 47b9c77..cd9cc77 100644 --- a/.gitlab/ci/customers.images.yml +++ b/.gitlab/ci/customers.images.yml @@ -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"] diff --git a/.gitlab/ci/definitions.yml b/.gitlab/ci/definitions.yml index ff0d3ad..9b34ece 100644 --- a/.gitlab/ci/definitions.yml +++ b/.gitlab/ci/definitions.yml @@ -1,25 +1,10 @@ -# Run test job always -.test: - stage: test - rules: - - when: always - -# Run build job only on a default branch when triggered manually -.deploy: - stage: deploy +.build_and_push: + stage: custom + needs: [] + script: + - ./scripts/lib/custom-docker-build rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" - 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" diff --git a/.gitlab/ci/docker.images.yml b/.gitlab/ci/docker.images.yml new file mode 100644 index 0000000..df944c8 --- /dev/null +++ b/.gitlab/ci/docker.images.yml @@ -0,0 +1,8 @@ +# Docker image with buildx plugin +docker: + variables: + DEBIAN: bullseye + DOCKER: '20.10.14' + BUILDX: '0.8' + extends: + - .build_and_push diff --git a/.gitlab/ci/e2e.images.yml b/.gitlab/ci/e2e.images.yml index 63c22ce..2fc5ab5 100644 --- a/.gitlab/ci/e2e.images.yml +++ b/.gitlab/ci/e2e.images.yml @@ -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 diff --git a/.gitlab/ci/gitaly.images.yml b/.gitlab/ci/gitaly.images.yml index 035e4ed..4896b4e 100644 --- a/.gitlab/ci/gitaly.images.yml +++ b/.gitlab/ci/gitaly.images.yml @@ -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: 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"] diff --git a/.gitlab/ci/gitlab.images.yml b/.gitlab/ci/gitlab.images.yml index 115c64f..991ac48 100644 --- a/.gitlab/ci/gitlab.images.yml +++ b/.gitlab/ci/gitlab.images.yml @@ -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: 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: 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"] diff --git a/.gitlab/ci/kas.images.yml b/.gitlab/ci/kas.images.yml index ab8a66f..74c7430 100644 --- a/.gitlab/ci/kas.images.yml +++ b/.gitlab/ci/kas.images.yml @@ -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"] diff --git a/Dockerfile.custom b/Dockerfile.custom index 446ec83..4cb3136 100644 --- a/Dockerfile.custom +++ b/Dockerfile.custom @@ -71,6 +71,12 @@ ARG DEBIAN_VERSION RUN if [ -n "$DOCKER_VERSION" ]; then /scripts/install-docker $DOCKER_VERSION $DEBIAN_VERSION; fi +# Docker buildx plugin +ARG BUILDX_VERSION +ARG BUILDX_DOWNLOAD_SHA256 + +RUN if [ -n "$BUILDX_VERSION" ]; then /scripts/install-buildx $BUILDX_VERSION $BUILDX_DOWNLOAD_SHA256; fi + # PgBouncer ARG PGBOUNCER_VERSION ARG PGBOUNCER_DOWNLOAD_SHA256 diff --git a/scripts/install-buildx b/scripts/install-buildx new file mode 100755 index 0000000..6794fd1 --- /dev/null +++ b/scripts/install-buildx @@ -0,0 +1,13 @@ +#!/bin/bash + +set -xeou pipefail + +BUILDX_VERSION=${1} +BUILDX_DOWNLOAD_SHA256=${2} +BUILDX_DOWNLOAD_URL="https://github.com/docker/buildx/releases/download/v${BUILDX_VERSION}/buildx-v${BUILDX_VERSION}.linux-$(dpkg --print-architecture)" + +curl -fsSL "${BUILDX_DOWNLOAD_URL}" -o docker-buildx +echo "${BUILDX_DOWNLOAD_SHA256} docker-buildx" | sha256sum -c - + +mkdir -p /usr/local/lib/docker/cli-plugins +chmod +x docker-buildx && mv docker-buildx /usr/local/lib/docker/cli-plugins/ diff --git a/scripts/custom-docker-build b/scripts/lib/custom-docker-build similarity index 92% rename from scripts/custom-docker-build rename to scripts/lib/custom-docker-build index a4ef11e..4d32d1a 100755 --- a/scripts/custom-docker-build +++ b/scripts/lib/custom-docker-build @@ -3,7 +3,7 @@ set -e IFS=$'\n\t' SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -source "$SCRIPT_DIR/lib/custom-docker.sh" +source "$SCRIPT_DIR/custom-docker.sh" function print_golang_args() { declare -A GOLANG_DOWNLOAD_SHA256 @@ -142,6 +142,22 @@ function print_docker_args() { printf -- "--build-arg DOCKER_VERSION=%s " "$1" } +function print_buildx_args() { + declare -A BUILDX_DOWNLOAD_SHA256 + + case "$1" in + 0.8) + BUILDX_VERSION=0.8.2 + BUILDX_DOWNLOAD_SHA256[amd64]=c64de4f3c30f7a73ff9db637660c7aa0f00234368105b0a09fa8e24eebe910c3 + BUILDX_DOWNLOAD_SHA256[arm64v8]=304d3d9822c75f98ad9cf57f0c234bcf326bbb96d791d551728cadd72a7a377f + ;; + *) echo "Unknown buildx version $1"; exit 1; + esac + + printf -- "--build-arg BUILDX_VERSION=%s " "$BUILDX_VERSION" + printf -- "--build-arg BUILDX_DOWNLOAD_SHA256=%s " "${BUILDX_DOWNLOAD_SHA256[$CUSTOM_DOCKER_ARCH]}" +} + function print_graphicsmagick_args() { case "$1" in 1.3.29) @@ -300,6 +316,7 @@ function parse_arguments() { GOLANG) print_golang_args $version ;; CHROME) print_chrome_args $version ;; DOCKER) print_docker_args $version ;; + BUILDX) print_buildx_args $version ;; GIT) print_git_args $version ;; LFS) print_lfs_args $version ;; NODE) print_node_args $version ;; @@ -323,13 +340,15 @@ function parse_arguments() { } function generate_command() { - printf -- "docker build " + printf -- "docker buildx build " parse_arguments for i in "$@" do printf -- "%s " "$i" done + + printf -- "--push=${PUSH_CUSTOM_IMAGE:-false} " printf -- ".\\n" } @@ -339,12 +358,11 @@ function build_custom_if_needed() { full_image_name="$build_image_path:$build_image_tag" echo "Building image $full_image_name" - docker_command=$(generate_command $@ --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from="$full_image_name" -t "$full_image_name") + docker_command=$(generate_command $@ --cache-to=type=inline --cache-from="$full_image_name" -t "$full_image_name") echo "Docker command:" - printf "\t%s" "$docker_command" + printf "\t%s\n" "$docker_command" eval $docker_command - printf "\n\nSUCCESS - Successfully built:\n\t%s" "$full_image_name" - echo "" + printf "\n\nSUCCESS - Successfully built:\n\t%s\n" "$full_image_name" } build_custom_if_needed $@ diff --git a/scripts/custom-docker-push b/scripts/lib/custom-docker-push similarity index 91% rename from scripts/custom-docker-push rename to scripts/lib/custom-docker-push index c92db85..b43bad4 100755 --- a/scripts/custom-docker-push +++ b/scripts/lib/custom-docker-push @@ -3,7 +3,7 @@ set -e IFS=$'\n\t' SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -source "$SCRIPT_DIR/lib/custom-docker.sh" +source "$SCRIPT_DIR/custom-docker.sh" function custom_push() { build_image_path=$(get_image_path) diff --git a/scripts/lib/custom-docker.sh b/scripts/lib/custom-docker.sh index 505f42a..6679433 100644 --- a/scripts/lib/custom-docker.sh +++ b/scripts/lib/custom-docker.sh @@ -1,5 +1,5 @@ PATH_TOOLS=(DEBIAN RUBY GOLANG NODE POSTGRESQL) -TAG_TOOLS=(BUNDLER GIT LFS CHROME YARN GRAPHICSMAGICK PGBOUNCER BAZELISK DOCKER GCLOUD KUBECTL) +TAG_TOOLS=(BUNDLER GIT LFS CHROME YARN GRAPHICSMAGICK PGBOUNCER BAZELISK DOCKER BUILDX GCLOUD KUBECTL) function get_image_path() { local path