diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2020-12-10 15:23:02 +0100 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2020-12-16 14:04:20 +0100 |
commit | 63ad786e2ee71f15a7d365c98d159dfa963d1ea4 (patch) | |
tree | 19c373b549c12a2ec08accab936c5b0b1ecaa553 | |
parent | 1c6d7071c4d0055247b092143fcf643a579d5d3b (diff) | |
download | podman-docker-builder-63ad786e2ee71f15a7d365c98d159dfa963d1ea4.tar.gz |
add multiarch template
-rw-r--r-- | gitlab-ci-template-multiarch.yml | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/gitlab-ci-template-multiarch.yml b/gitlab-ci-template-multiarch.yml new file mode 100644 index 0000000..491d76c --- /dev/null +++ b/gitlab-ci-template-multiarch.yml @@ -0,0 +1,106 @@ +# 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:devel + +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-default-x86_64: + stage: build + variables: + ARCH: x86_64 + rules: + - if: '$CI_PIPELINE_SOURCE != "schedule"' + script: + - *tag-name + - *build-default + +build-nocache-x86_64: + stage: build + variables: + ARCH: x86_64 + rules: + - if: '$CI_PIPELINE_SOURCE == "schedule"' + script: + - *tag-name + - *build-nocache + +build-default-aarch64: + stage: build + tags: + - aarch64 + variables: + ARCH: aarch64 + rules: + - if: '$CI_PIPELINE_SOURCE != "schedule" && $BUILD_AARCH64 == "yes"' + script: + - *tag-name + - *build-default + +build-nocache-aarch64: + stage: build + tags: + - aarch64 + variables: + ARCH: aarch64 + rules: + - if: '$CI_PIPELINE_SOURCE == "schedule" && $BUILD_AARCH64 == "yes"' + script: + - *tag-name + - *build-nocache + +manifest: + stage: manifest + script: + - *tag-name + - TAGLIST=$(skopeo inspect docker://$CI_REGISTRY_IMAGE | jq '.RepoTags[]' | tr -d '"' | grep ${TAGNAME}-) + - buildah login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY + - buildah manifest create ${TAGNAME} + - > + for item in $TAGLIST; + do echo "# -> $item <-"; + buildah manifest add ${TAGNAME} docker://$CI_REGISTRY_IMAGE:${item}; + done + - buildah manifest push ${TAGNAME} docker://$CI_REGISTRY_IMAGE:${TAGNAME} |