From e59cc6934e8ed81e97e70477ee991a01a5438e2a Mon Sep 17 00:00:00 2001 From: Alf-Rune Siqveland Date: Wed, 5 Jun 2024 10:42:55 +0200 Subject: [PATCH] ci: Update `build:docker` and publish image to Docker Hub Signed-off-by: Alf-Rune Siqveland --- .gitlab-ci.yml | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6a1902aa..e69d2a8c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -28,24 +28,28 @@ variables: S3_BUCKET_NAME: "mender" S3_BUCKET_PATH: "mender-artifact" DOCKER_BUILDKIT: 1 + DOCKER_PLATFORMS: + value: "linux/amd64,linux/arm64" + description: "Platforms for building and distributing container images" test:check-license-source: variables: LICENSE_HEADERS_IGNORE_FILES_REGEXP: './artifact/keyfactor/\(signer\|signer_test\)\.go' build:docker: - image: docker + image: docker:26-cli needs: [] services: - - docker:dind + - docker:26-dind stage: build + before_script: + - docker login --username "$CI_REGISTRY_USER" --password "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY" + - docker buildx create --platform "$DOCKER_PLATFORMS" --name builder --bootstrap --use script: - - docker build -t $DOCKER_REPOSITORY:pr . - - docker save $DOCKER_REPOSITORY:pr > image.tar - artifacts: - expire_in: 2w - paths: - - image.tar + - docker buildx build --push \ + --platform "$DOCKER_PLATFORMS" \ + --tag "$CI_REGISTRY_IMAGE:$CI_PIPELINE_IID" \ + . tags: - gitlab-org-docker @@ -266,6 +270,30 @@ publish:s3: only: - /^(master|[0-9]+\.[0-9]+\.x)$/ +publish:docker: + stage: publish + rules: + - if: '$CI_COMMIT_TAG' + - if: '$CI_COMMIT_BRANCH == "master"' + - when: manual # Fallback; allow manual trigger + allow_failure: true + image: + name: "quay.io/skopeo/stable:v1.15" + # https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#override-the-entrypoint-of-an-image + entrypoint: [""] + before_script: + - skopeo login --username "$CI_REGISTRY_USER" --password "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY" + - | + skopeo login \ + --username "$DOCKER_HUB_USERNAME" \ + --password "$DOCKER_HUB_PASSWORD" \ + docker.io + script: + - | + skopeo copy --multi-arch all \ + "docker://${CI_REGISTRY_IMAGE}:${CI_PIPELINE_IID}" \ + "docker://docker.io/mendersoftware/mender-artifact:${CI_COMMIT_REF_NAME}" + generate-qa-trigger: image: python:alpine stage: trigger_prep