From b05db2befe77910245b91126c06ee4a49a6f3050 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Tue, 1 Feb 2022 14:17:47 +0100 Subject: [PATCH] Enable multi-arch builds in CI Signed-off-by: Evan Lezar --- .common-ci.yml | 33 ++++++++++++++++++++++----------- .gitlab-ci.yml | 16 +++++++++++++++- .nvidia-ci.yml | 10 +++++----- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/.common-ci.yml b/.common-ci.yml index 525df58c..5b270268 100644 --- a/.common-ci.yml +++ b/.common-ci.yml @@ -20,6 +20,7 @@ default: variables: GIT_SUBMODULE_STRATEGY: recursive BUILDIMAGE: "${CI_REGISTRY_IMAGE}/build:${CI_COMMIT_SHORT_SHA}" + BUILD_MULTI_ARCH_IMAGES: "true" stages: - image @@ -117,20 +118,30 @@ test-packaging: needs: - image-packaging +# Download the regctl binary for use in the release steps +.regctl-setup: + before_script: + - export REGCTL_VERSION=v0.3.10 + - apk add --no-cache curl + - mkdir -p bin + - curl -sSLo bin/regctl https://github.com/regclient/regclient/releases/download/${REGCTL_VERSION}/regctl-linux-amd64 + - chmod a+x bin/regctl + - export PATH=$(pwd)/bin:${PATH} + # .release forms the base of the deployment jobs which push images to the CI registry. # This is extended with the version to be deployed (e.g. the SHA or TAG) and the # target os. .release: - stage: - release + stage: release variables: # Define the source image for the release IMAGE_NAME: "${CI_REGISTRY_IMAGE}/container-toolkit" VERSION: "${CI_COMMIT_SHORT_SHA}" # OUT_IMAGE_VERSION is overridden for external releases OUT_IMAGE_VERSION: "${CI_COMMIT_SHORT_SHA}" - stage: release before_script: + - !reference [.regctl-setup, before_script] + # We ensure that the OUT_IMAGE_VERSION is set - 'echo Version: ${OUT_IMAGE_VERSION} ; [[ -n "${OUT_IMAGE_VERSION}" ]] || exit 1' @@ -138,16 +149,16 @@ test-packaging: # need to tag the image. # Note: a leading 'v' is stripped from the version if present - apk add --no-cache make bash - - 'echo "Logging in to CI registry ${CI_REGISTRY}"' - - docker login -u "${CI_REGISTRY_USER}" -p "${CI_REGISTRY_PASSWORD}" "${CI_REGISTRY}" - - docker pull "${IMAGE_NAME}:${VERSION}-${DIST}" script: - - docker tag "${IMAGE_NAME}:${VERSION}-${DIST}" "${OUT_IMAGE_NAME}:${OUT_IMAGE_VERSION}-${DIST}" # Log in to the "output" registry, tag the image and push the image - - 'echo "Logging in to output registry ${OUT_REGISTRY}"' - - docker logout - - docker login -u "${OUT_REGISTRY_USER}" -p "${OUT_REGISTRY_TOKEN}" "${OUT_REGISTRY}" - - make IMAGE_NAME=${OUT_IMAGE_NAME} VERSION=${OUT_IMAGE_VERSION} -f build/container/Makefile push-${DIST} + - 'echo "Logging in to CI registry ${CI_REGISTRY}"' + - regctl registry login "${CI_REGISTRY}" -u "${CI_REGISTRY_USER}" -p "${CI_REGISTRY_PASSWORD}" + - '[ ${CI_REGISTRY} = ${OUT_REGISTRY} ] || echo "Logging in to output registry ${OUT_REGISTRY}"' + - '[ ${CI_REGISTRY} = ${OUT_REGISTRY} ] || regctl registry login "${OUT_REGISTRY}" -u "${OUT_REGISTRY_USER}" -p "${OUT_REGISTRY_TOKEN}"' + + # Since OUT_IMAGE_NAME and OUT_IMAGE_VERSION are set, this will push the CI image to the + # Target + - make -f build/container/Makefile push-${DIST} # Define a staging release step that pushes an image to an internal "staging" repository # This is triggered for all pipelines (i.e. not only tags) to test the pipeline steps diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 779824a7..522b2399 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -194,19 +194,33 @@ package-ubuntu18.04-ppc64le: - .dist-ubuntu18.04 - .arch-ppc64le +.buildx-setup: + before_script: + - export BUILDX_VERSION=v0.6.3 + - apk add --no-cache curl + - mkdir -p ~/.docker/cli-plugins + - curl -sSLo ~/.docker/cli-plugins/docker-buildx "https://github.com/docker/buildx/releases/download/${BUILDX_VERSION}/buildx-${BUILDX_VERSION}.linux-amd64" + - chmod a+x ~/.docker/cli-plugins/docker-buildx + + - docker buildx create --use --platform=linux/amd64,linux/arm64 + + - '[[ -n "${SKIP_QEMU_SETUP}" ]] || docker run --rm --privileged multiarch/qemu-user-static --reset -p yes' + # Define the image build targets .image-build: stage: image-build variables: IMAGE_NAME: "${CI_REGISTRY_IMAGE}/container-toolkit" VERSION: "${CI_COMMIT_SHORT_SHA}" + PUSH_ON_BUILD: "true" before_script: + - !reference [.buildx-setup, before_script] + - apk add --no-cache bash make - 'echo "Logging in to CI registry ${CI_REGISTRY}"' - docker login -u "${CI_REGISTRY_USER}" -p "${CI_REGISTRY_PASSWORD}" "${CI_REGISTRY}" script: - make -f build/container/Makefile build-${DIST} - - make -f build/container/Makefile push-${DIST} image-centos7: extends: diff --git a/.nvidia-ci.yml b/.nvidia-ci.yml index bf926571..478526e9 100644 --- a/.nvidia-ci.yml +++ b/.nvidia-ci.yml @@ -56,13 +56,13 @@ variables: - job_execution_timeout - stuck_or_timeout_failure before_script: + - !reference [.regctl-setup, before_script] + - apk add --no-cache make bash - > - docker pull ${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION}-${DIST} > /dev/null && echo "${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION}-${DIST}" || ( echo "${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION}-${DIST} does not exist" && sleep infinity ) + regctl manifest get ${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION}-${DIST} --list > /dev/null && echo "${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION}-${DIST}" || ( echo "${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION}-${DIST} does not exist" && sleep infinity ) script: - - docker pull ${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION}-${DIST} - - docker tag ${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION}-${DIST} ${OUT_IMAGE_NAME}:${CI_COMMIT_SHORT_SHA}-${DIST} - - docker login -u "${OUT_REGISTRY_USER}" -p "${OUT_REGISTRY_TOKEN}" "${OUT_REGISTRY}" - - docker push ${OUT_IMAGE_NAME}:${CI_COMMIT_SHORT_SHA}-${DIST} + - regctl registry login "${OUT_REGISTRY}" -u "${OUT_REGISTRY_USER}" -p "${OUT_REGISTRY_TOKEN}" + - make -f build/container/Makefile IMAGE=${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION}-${DIST} OUT_IMAGE=${OUT_IMAGE_NAME}:${CI_COMMIT_SHORT_SHA}-${DIST} push-${DIST} image-centos7: extends: