# https://blog.callr.tech/building-docker-images-with-gitlab-ci-best-practices/ # comments dropped, updated for podman builds # # Add this variable to your .gitlab-ci.yml to enable aarch64 builds. # Also needs an aarch64 builder (tagged 'aarch64') to work. # #variables: # BUILD_AARCH64: "yes" image: registry.gitlab.com/kraxel/podman-docker-builder:latest stages: - build - manifest .tag-name: &tag-name - > if test "$CI_COMMIT_BRANCH" != ""; then TAGNAME=${CI_COMMIT_BRANCH/master/latest}; else TAGNAME=${CI_COMMIT_SHA}; fi - echo "tagname is -> ${TAGNAME} <-" .build-default: &build-default - podman login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - podman pull $CI_REGISTRY_IMAGE:${TAGNAME}-${ARCH} || true - > podman build --pull --build-arg VCS_REF=$CI_COMMIT_SHA --build-arg VCS_URL=$CI_PROJECT_URL --cache-from $CI_REGISTRY_IMAGE:${TAGNAME}-${ARCH} --tag $CI_REGISTRY_IMAGE:${TAGNAME}-${ARCH} . - podman push $CI_REGISTRY_IMAGE:${TAGNAME}-${ARCH} .build-nocache: &build-nocache - podman login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - > podman build --build-arg VCS_REF=$CI_COMMIT_SHA --build-arg VCS_URL=$CI_PROJECT_URL --tag $CI_REGISTRY_IMAGE:${TAGNAME}-${ARCH} . - podman push $CI_REGISTRY_IMAGE:${TAGNAME}-${ARCH} build-x86_64: stage: build variables: ARCH: x86_64 script: - *tag-name - *build-nocache build-aarch64: stage: build tags: - aarch64 variables: ARCH: aarch64 rules: - if: '$BUILD_AARCH64 == "yes"' script: - *tag-name - *build-nocache manifest: stage: manifest script: - *tag-name - TAGLIST=$(skopeo inspect docker://$CI_REGISTRY_IMAGE:${TAGNAME}-x86_64 | jq '.RepoTags[]' | tr -d '"' | grep ${TAGNAME}-) - buildah login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - buildah manifest create localhost/multiarch:${TAGNAME} - > for item in $TAGLIST; do echo "# -> $item <-"; buildah manifest add localhost/multiarch:${TAGNAME} docker://$CI_REGISTRY_IMAGE:${item}; done - buildah manifest inspect localhost/multiarch:${TAGNAME} - buildah manifest push -f v2s2 localhost/multiarch:${TAGNAME} docker://$CI_REGISTRY_IMAGE:${TAGNAME}