diff --git a/.gitlab/ci/custom.images.yml b/.gitlab/ci/custom.images.yml index d5562c7..fda9ab4 100644 --- a/.gitlab/ci/custom.images.yml +++ b/.gitlab/ci/custom.images.yml @@ -8,6 +8,7 @@ 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" \ diff --git a/.gitlab/ci/definitions.yml b/.gitlab/ci/definitions.yml index 470cb2f..0042c71 100644 --- a/.gitlab/ci/definitions.yml +++ b/.gitlab/ci/definitions.yml @@ -1,6 +1,16 @@ .build_and_push: stage: custom needs: [] + variables: + QEMU_IMAGE: tonistiigi/binfmt:qemu-v6.2.0 + before_script: + - | + if [ "${ARCH:-amd64}" != "amd64" ]; then + echo -e "\033[1;33mInstalling latest qemu emulators\033[0m" + docker pull -q ${QEMU_IMAGE}; + docker run --rm --privileged ${QEMU_IMAGE} --uninstall qemu-*; + docker run --rm --privileged ${QEMU_IMAGE} --install all; + fi script: - ./scripts/lib/custom-docker-build rules: diff --git a/Dockerfile.custom b/Dockerfile.custom index ace788d..c3713ff 100644 --- a/Dockerfile.custom +++ b/Dockerfile.custom @@ -7,7 +7,8 @@ ARG CUSTOM_BASE_IMAGE FROM ${CUSTOM_BASE_IMAGE} ARG BUILD_OS -ARG BUILD_ARCH +# TARGETARCH is automatically populated by buildx --platform argument +ARG TARGETARCH ADD / / diff --git a/scripts/install-bazelisk b/scripts/install-bazelisk index d3dcbdb..74e051e 100755 --- a/scripts/install-bazelisk +++ b/scripts/install-bazelisk @@ -5,7 +5,7 @@ set -xeou pipefail BAZELISK_VERSION=${1} BAZELISK_DOWNLOAD_SHA256=${2} -BAZELISK_DOWNLOAD_URL="https://github.com/bazelbuild/bazelisk/releases/download/v${BAZELISK_VERSION}/bazelisk-linux-amd64" +BAZELISK_DOWNLOAD_URL="https://github.com/bazelbuild/bazelisk/releases/download/v${BAZELISK_VERSION}/bazelisk-linux-${TARGETARCH:-amd64}" curl -fsSL "$BAZELISK_DOWNLOAD_URL" -o bazelisk echo "${BAZELISK_DOWNLOAD_SHA256} bazelisk" | sha256sum -c - diff --git a/scripts/install-buildx b/scripts/install-buildx index 6794fd1..d104b1d 100755 --- a/scripts/install-buildx +++ b/scripts/install-buildx @@ -4,7 +4,7 @@ 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)" +BUILDX_DOWNLOAD_URL="https://github.com/docker/buildx/releases/download/v${BUILDX_VERSION}/buildx-v${BUILDX_VERSION}.linux-${TARGETARCH:-amd64}" curl -fsSL "${BUILDX_DOWNLOAD_URL}" -o docker-buildx echo "${BUILDX_DOWNLOAD_SHA256} docker-buildx" | sha256sum -c - diff --git a/scripts/install-chrome b/scripts/install-chrome index a17c100..32bec58 100755 --- a/scripts/install-chrome +++ b/scripts/install-chrome @@ -4,7 +4,9 @@ set -xeuo pipefail IFS=$'\n\t' function build_debian() { - if [[ $(dpkg --print-architecture) == arm64 ]]; then + ARCH="${TARGETARCH:-amd64}" + + if [[ "${ARCH}" == "arm64" ]]; then echo "The arm64 does not have prebuilt chrome. Using chromium instead." apt-get update -q -y apt-get install -y chromium chromium-driver @@ -32,7 +34,7 @@ function build_debian() { apt-cache policy google-chrome-stable if [[ -z $CHECK_VERSION ]]; then - CHROME_DEB="google-chrome-stable_${CHROME_VERSION}_$(dpkg --print-architecture).deb" + CHROME_DEB="google-chrome-stable_${CHROME_VERSION}_${ARCH}.deb" CHROME_URL="${CHROME_DOWNLOAD_URL_BASE}/${CHROME_VERSION}/${CHROME_DEB}" echo "Downloading from our Package registry: $CHROME_URL" curl --silent --show-error --fail -O $CHROME_URL diff --git a/scripts/install-docker b/scripts/install-docker index 2dedc30..0902fa8 100755 --- a/scripts/install-docker +++ b/scripts/install-docker @@ -17,7 +17,7 @@ apt-get -y install \ curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - -echo "deb [arch=amd64] https://download.docker.com/linux/debian ${DEBIAN_VERSION} stable" >> /etc/apt/sources.list.d/docker.list +echo "deb https://download.docker.com/linux/debian ${DEBIAN_VERSION} stable" >> /etc/apt/sources.list.d/docker.list apt-get update PACKAGE_VERSION=$(apt-cache policy docker-ce | awk -v dv=${DOCKER_VERSION}~ '$1 ~ dv {print $1}') diff --git a/scripts/install-golang b/scripts/install-golang index ce543a5..99a0603 100755 --- a/scripts/install-golang +++ b/scripts/install-golang @@ -5,7 +5,7 @@ set -xeou pipefail INSTALL_GOLANG_VERSION=${1} GOLANG_DOWNLOAD_SHA256=${2} -GOLANG_DOWNLOAD_URL="https://golang.org/dl/go${INSTALL_GOLANG_VERSION}.linux-${BUILD_ARCH}.tar.gz" +GOLANG_DOWNLOAD_URL="https://golang.org/dl/go${INSTALL_GOLANG_VERSION}.linux-${TARGETARCH:-amd64}.tar.gz" function build_debian() { curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz diff --git a/scripts/install-helm b/scripts/install-helm index e0dbec7..993d65e 100755 --- a/scripts/install-helm +++ b/scripts/install-helm @@ -4,7 +4,7 @@ set -xeou pipefail HELM_VERSION=${1} HELM_DOWNLOAD_SHA256=${2} -HELM_DOWNLOAD_URL="https://get.helm.sh/helm-v${HELM_VERSION}-linux-$(dpkg --print-architecture).tar.gz" +HELM_DOWNLOAD_URL="https://get.helm.sh/helm-v${HELM_VERSION}-linux-${TARGETARCH:-amd64}.tar.gz" curl -fsSL "${HELM_DOWNLOAD_URL}" -o helm.tar.gz echo "${HELM_DOWNLOAD_SHA256} helm.tar.gz" | sha256sum -c - diff --git a/scripts/install-kubectl b/scripts/install-kubectl index ad6b5c8..beb4856 100755 --- a/scripts/install-kubectl +++ b/scripts/install-kubectl @@ -4,7 +4,7 @@ set -xeou pipefail KUBECTL_VERSION=${1} KUBECTL_DOWNLOAD_SHA256=${2} -KUBECTL_DOWNLOAD_URL="https://dl.k8s.io/release/v${KUBECTL_VERSION}/bin/linux/$(dpkg --print-architecture)/kubectl" +KUBECTL_DOWNLOAD_URL="https://dl.k8s.io/release/v${KUBECTL_VERSION}/bin/linux/${TARGETARCH:-amd64}/kubectl" curl -fsSL "${KUBECTL_DOWNLOAD_URL}" -o kubectl echo "${KUBECTL_DOWNLOAD_SHA256} kubectl" | sha256sum -c - diff --git a/scripts/install-lfs b/scripts/install-lfs index 244443a..46e95bc 100755 --- a/scripts/install-lfs +++ b/scripts/install-lfs @@ -3,7 +3,7 @@ set -xeuo pipefail IFS=$'\n\t' -LFS_DOWNLOAD_URL="https://github.com/git-lfs/git-lfs/releases/download/v${LFS_VERSION}/git-lfs-linux-$(dpkg --print-architecture)-v${LFS_VERSION}.tar.gz" +LFS_DOWNLOAD_URL="https://github.com/git-lfs/git-lfs/releases/download/v${LFS_VERSION}/git-lfs-linux-${TARGETARCH:-amd64}-v${LFS_VERSION}.tar.gz" mkdir build \ && curl -fsSL "$LFS_DOWNLOAD_URL" -o git-lfs.tar.gz \ diff --git a/scripts/install-node b/scripts/install-node index 9d60e69..20f19d2 100755 --- a/scripts/install-node +++ b/scripts/install-node @@ -13,7 +13,7 @@ curl -sS -L https://deb.nodesource.com/setup_${NODE_MAJOR} | bash - apt-get update -NODE_FILE_NAME="nodejs_$NODE_INSTALL_VERSION-deb-1nodesource1_$(dpkg --print-architecture).deb" +NODE_FILE_NAME="nodejs_$NODE_INSTALL_VERSION-deb-1nodesource1_${TARGETARCH:-amd64}.deb" curl -s -O "https://deb.nodesource.com/node_$NODE_MAJOR/pool/main/n/nodejs/$NODE_FILE_NAME" dpkg -i "$NODE_FILE_NAME" rm -f "$NODE_FILE_NAME" diff --git a/scripts/install-www-gitlab-com b/scripts/install-www-gitlab-com index bb337b2..ad7af71 100755 --- a/scripts/install-www-gitlab-com +++ b/scripts/install-www-gitlab-com @@ -25,7 +25,7 @@ function build_debian() { /scripts/install-node $NODE_INSTALL_VERSION $YARN_INSTALL_VERSION && node --version && yarn --version # Install gitlab-runner - curl -O -J -L https://gitlab-ci-multi-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-ci-multi-runner-linux-amd64 + curl -O -J -L "https://gitlab-ci-multi-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-ci-multi-runner-linux-${TARGETARCH:-amd64}" mv gitlab-ci-multi-runner-linux-amd64 /usr/bin/gitlab-runner-helper chmod +x /usr/bin/gitlab-runner-helper diff --git a/scripts/lib/custom-docker-build b/scripts/lib/custom-docker-build index 2916138..575b4e0 100755 --- a/scripts/lib/custom-docker-build +++ b/scripts/lib/custom-docker-build @@ -7,7 +7,7 @@ source "$SCRIPT_DIR/custom-docker.sh" function get_base_image_reference() { if [[ $1 =~ ^debian ]]; then - echo "$CUSTOM_DOCKER_ARCH/$1" + echo "$1" elif [[ $1 =~ ^ubi:8 ]]; then echo "registry.access.redhat.com/ubi8/$1" fi @@ -20,23 +20,23 @@ function print_golang_args() { 1.16) INSTALL_GOLANG_VERSION=1.16.12 GOLANG_DOWNLOAD_SHA256[amd64]=7d657e86493ac1d5892f340a7d88b862b12edb5ac6e73c099e8e0668a6c916b7 - GOLANG_DOWNLOAD_SHA256[arm64v8]=7dbf50ab2e665ecd6c86a3f1ce8c04f7167f9895b91921e25cf1bdc1cb9b5fd7 + GOLANG_DOWNLOAD_SHA256[arm64]=7dbf50ab2e665ecd6c86a3f1ce8c04f7167f9895b91921e25cf1bdc1cb9b5fd7 ;; 1.17) INSTALL_GOLANG_VERSION=1.17.10 GOLANG_DOWNLOAD_SHA256[amd64]=87fc728c9c731e2f74e4a999ef53cf07302d7ed3504b0839027bd9c10edaa3fd - GOLANG_DOWNLOAD_SHA256[arm64v8]=649141201efa7195403eb1301b95dc79c5b3e65968986a391da1370521701b0c + GOLANG_DOWNLOAD_SHA256[arm64]=649141201efa7195403eb1301b95dc79c5b3e65968986a391da1370521701b0c ;; 1.18) INSTALL_GOLANG_VERSION=1.18.2 GOLANG_DOWNLOAD_SHA256[amd64]=e54bec97a1a5d230fc2f9ad0880fcbabb5888f30ed9666eca4a91c5a32e86cbc - GOLANG_DOWNLOAD_SHA256[arm64v8]=fc4ad28d0501eaa9c9d6190de3888c9d44d8b5fb02183ce4ae93713f67b8a35b + GOLANG_DOWNLOAD_SHA256[arm64]=fc4ad28d0501eaa9c9d6190de3888c9d44d8b5fb02183ce4ae93713f67b8a35b ;; *) echo "Unknown golang version $1"; exit 1; esac printf -- "--build-arg INSTALL_GOLANG_VERSION=%s " "$INSTALL_GOLANG_VERSION" - printf -- "--build-arg GOLANG_DOWNLOAD_SHA256=%s " "${GOLANG_DOWNLOAD_SHA256[$CUSTOM_DOCKER_ARCH]}" + printf -- "--build-arg GOLANG_DOWNLOAD_SHA256=%s " "${GOLANG_DOWNLOAD_SHA256[$TARGETARCH]}" } # If you add a new minor version here, be sure to check that the @@ -93,13 +93,13 @@ function print_lfs_args() { 2.9) LFS_VERSION=2.9.1 LFS_DOWNLOAD_SHA256[amd64]=2a8e60cf51ec45aa0f4332aa0521d60ec75c76e485d13ebaeea915b9d70ea466 - LFS_DOWNLOAD_SHA256[arm64v8]=ff2f8472a5ac0e808108bad0cc6be5ca1849eb970228b1aa3d627bcbc8228ad9 + LFS_DOWNLOAD_SHA256[arm64]=ff2f8472a5ac0e808108bad0cc6be5ca1849eb970228b1aa3d627bcbc8228ad9 ;; *) echo "Unknown Git LFS version $1"; exit 1; esac printf -- "--build-arg LFS_VERSION=%s " "$LFS_VERSION" - printf -- "--build-arg LFS_DOWNLOAD_SHA256=%s " "${LFS_DOWNLOAD_SHA256[$CUSTOM_DOCKER_ARCH]}" + printf -- "--build-arg LFS_DOWNLOAD_SHA256=%s " "${LFS_DOWNLOAD_SHA256[$TARGETARCH]}" } function print_node_args() { @@ -138,13 +138,13 @@ function print_buildx_args() { 0.8) BUILDX_VERSION=0.8.2 BUILDX_DOWNLOAD_SHA256[amd64]=c64de4f3c30f7a73ff9db637660c7aa0f00234368105b0a09fa8e24eebe910c3 - BUILDX_DOWNLOAD_SHA256[arm64v8]=304d3d9822c75f98ad9cf57f0c234bcf326bbb96d791d551728cadd72a7a377f + BUILDX_DOWNLOAD_SHA256[arm64]=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]}" + printf -- "--build-arg BUILDX_DOWNLOAD_SHA256=%s " "${BUILDX_DOWNLOAD_SHA256[$TARGETARCH]}" } function print_graphicsmagick_args() { @@ -268,7 +268,7 @@ function print_kubectl_args() { esac printf -- "--build-arg KUBECTL_VERSION=%s " "$KUBECTL_VERSION" - printf -- "--build-arg KUBECTL_DOWNLOAD_SHA256=%s " "${KUBECTL_DOWNLOAD_SHA256[$CUSTOM_DOCKER_ARCH]}" + printf -- "--build-arg KUBECTL_DOWNLOAD_SHA256=%s " "${KUBECTL_DOWNLOAD_SHA256[$TARGETARCH]}" } function print_helm_args() { @@ -284,57 +284,29 @@ function print_helm_args() { esac printf -- "--build-arg HELM_VERSION=%s " "$HELM_VERSION" - printf -- "--build-arg HELM_DOWNLOAD_SHA256=%s " "${HELM_DOWNLOAD_SHA256[$CUSTOM_DOCKER_ARCH]}" + printf -- "--build-arg HELM_DOWNLOAD_SHA256=%s " "${HELM_DOWNLOAD_SHA256[$TARGETARCH]}" } function parse_arguments() { printf -- "-f Dockerfile.custom " - # Mapping between sources of architectures - # - arch: a current image architecture (or uname -m if matching host, but can be different) - # - apk --print-arch: a alpine architecture for installed packages - # - dpkg --print-architecture: a debian architecture for installed packages - # - docker arch: a Docker Hub architecture for images - # - # arch | apk --print-arch | dpkg --print-architecture | docker arch - # x86_64 | x86_64 | amd64 | amd64 - # armhf | armhf | armhf | arm32v7 - # aarch64 | aarch64 | arm64 | arm64v8 - - # We make use of 4 variables related to the build environment. + # We make use of 2 variables related to the build environment. # 1. `CUSTOM_DOCKER_IMAGE` - Defines the reference of image used as # base for building images. Follows a # valid docker image reference format - # - "arm64v8/debian:buster" + # - "debian:buster" # - "registry.access.redhat.com/ubi8/ubi:8.6" - # 2. `CUSTOM_DOCKER_ARCH` - Defines the architecture of the docker - # image. Follows docker architecture - # format - `amd64`/`arm32v7`/`arm64v8`. - # 3. `BUILD_OS` - Used by installation scripts of various + # 2. `BUILD_OS` - Used by installation scripts of various # components to detect the OS being worked # on. Follows regular docker image:tag # format - "debian:buster" or "ubi:8.6". - # 4. `BUILD_ARCH` - Used by installation scripts of various - # components to detect the architecture - # being worked on. Follows general - # architecture names - `amd64`/`arm64`. - # - # The first two variables are used to pick the docker image used as - # base for builds. The last two variables are used to detect OS and - # architecture while building components. - # defaults - case $(arch) in - x86_64) CUSTOM_DOCKER_ARCH=amd64; BUILD_ARCH=amd64 ;; - aarch64) CUSTOM_DOCKER_ARCH=arm64v8; BUILD_ARCH=arm64 ;; - *) echo "unknown architecture $(arch)"; exit 1;; - esac + TARGETARCH=${ARCH:-amd64} for tool in "${PATH_TOOLS[@]}" "${TAG_TOOLS[@]}"; do if [ -n "${!tool}" ]; then version="${!tool}" case "$tool" in - ARCH) CUSTOM_DOCKER_ARCH=$version ;; OS) CUSTOM_BASE_IMAGE=$(get_base_image_reference $version) ;; RUBY) print_ruby_args $version ;; BUNDLER) print_bundler_args $version ;; @@ -358,15 +330,12 @@ function parse_arguments() { fi done - if [ -z "$CUSTOM_BASE_IMAGE" ]; then - CUSTOM_BASE_IMAGE="$CUSTOM_DOCKER_ARCH/debian:buster" - fi - + CUSTOM_BASE_IMAGE=${CUSTOM_BASE_IMAGE:-"debian:buster"} BUILD_OS=${OS:-"debian:buster"} printf -- "--build-arg CUSTOM_BASE_IMAGE=%s " "$CUSTOM_BASE_IMAGE" printf -- "--build-arg BUILD_OS=%s " "$BUILD_OS" - printf -- "--build-arg BUILD_ARCH=%s " "$BUILD_ARCH" + printf -- "--platform=linux/%s " "${TARGETARCH}" } function generate_command() {