fix(docker): ensure qemu binfmt is loaded
the docker run command ensures that the binfmt is loaded. see https://gitlab.com/gitlab-org/gitlab-runner/-/merge_requests/1861 for further details !24 gitlab-org/gitlab-runner!1861
This commit is contained in:
@ -38,6 +38,10 @@ variables:
|
|||||||
- pip3 install setuptools wheel
|
- pip3 install setuptools wheel
|
||||||
- pip install -r $ROOT_DIR/conventional_commits/requirements.txt
|
- pip install -r $ROOT_DIR/conventional_commits/requirements.txt
|
||||||
- pip3 install gitlab-ci/gitlab_release/python-module/cz_nfc/.
|
- pip3 install gitlab-ci/gitlab_release/python-module/cz_nfc/.
|
||||||
|
# see: https://gitlab.com/gitlab-org/gitlab-runner/-/merge_requests/1861
|
||||||
|
# on why this `docker run` is required. without it multiarch support doesnt work.
|
||||||
|
- docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
|
||||||
|
- update-binfmts --display
|
||||||
- update-binfmts --enable # Important: Ensures execution of other binary formats is enabled in the kernel
|
- update-binfmts --enable # Important: Ensures execution of other binary formats is enabled in the kernel
|
||||||
- docker buildx create --driver=docker-container --driver-opt image=moby/buildkit:v0.11.6 --use
|
- docker buildx create --driver=docker-container --driver-opt image=moby/buildkit:v0.11.6 --use
|
||||||
- docker buildx inspect --bootstrap
|
- docker buildx inspect --bootstrap
|
||||||
@ -45,50 +49,52 @@ variables:
|
|||||||
|
|
||||||
# --label org.opencontainers.image.url="$CI_PROJECT_URL/-/releases/$(cz -n cz_nfc version --project)" \
|
# --label org.opencontainers.image.url="$CI_PROJECT_URL/-/releases/$(cz -n cz_nfc version --project)" \
|
||||||
# --label org.opencontainers.image.version="$(cz -n cz_nfc version --project)" \
|
# --label org.opencontainers.image.version="$(cz -n cz_nfc version --project)" \
|
||||||
script: |
|
script:
|
||||||
|
- update-binfmts --display
|
||||||
|
- |
|
||||||
|
|
||||||
if [ "0$DOCKER_IMAGE_BUILD_TARGET_PLATFORMS" != "0" ]; then
|
if [ "0$DOCKER_IMAGE_BUILD_TARGET_PLATFORMS" != "0" ]; then
|
||||||
|
|
||||||
echo "[DEBUG] building multiarch/specified arch image";
|
echo "[DEBUG] building multiarch/specified arch image";
|
||||||
|
|
||||||
docker buildx build --platform=$DOCKER_IMAGE_BUILD_TARGET_PLATFORMS . \
|
docker buildx build --platform=$DOCKER_IMAGE_BUILD_TARGET_PLATFORMS . \
|
||||||
--label org.opencontainers.image.created="$(date '+%Y-%m-%d %H:%M:%S%:z')" \
|
--label org.opencontainers.image.created="$(date '+%Y-%m-%d %H:%M:%S%:z')" \
|
||||||
--label org.opencontainers.image.documentation="$CI_PROJECT_URL" \
|
--label org.opencontainers.image.documentation="$CI_PROJECT_URL" \
|
||||||
--label org.opencontainers.image.source="$CI_PROJECT_URL" \
|
--label org.opencontainers.image.source="$CI_PROJECT_URL" \
|
||||||
--label org.opencontainers.image.revision="$CI_COMMIT_SHA" \
|
--label org.opencontainers.image.revision="$CI_COMMIT_SHA" \
|
||||||
--no-cache \
|
--push \
|
||||||
--push \
|
--build-arg CI_JOB_TOKEN=$CI_JOB_TOKEN --build-arg CI_PROJECT_ID=$CI_PROJECT_ID --build-arg CI_API_V4_URL=$CI_API_V4_URL \
|
||||||
--file $DOCKER_DOCKERFILE \
|
--file $DOCKER_DOCKERFILE \
|
||||||
--tag $DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG;
|
--tag $DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG;
|
||||||
|
|
||||||
docker buildx imagetools inspect $DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG;
|
docker buildx imagetools inspect $DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG;
|
||||||
|
|
||||||
# during docker multi platform build there are >=3 additional unknown images added to gitlab container registry. cleanup
|
# during docker multi platform build there are >=3 additional unknown images added to gitlab container registry. cleanup
|
||||||
|
|
||||||
DOCKER_MULTI_ARCH_IMAGES=$(docker buildx imagetools inspect "$DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG" --format "{{ range .Manifest.Manifests }}{{ if ne (print .Platform) \"&{unknown unknown [] }\" }}$DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG@{{ println .Digest }}{{end}} {{end}}");
|
DOCKER_MULTI_ARCH_IMAGES=$(docker buildx imagetools inspect "$DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG" --format "{{ range .Manifest.Manifests }}{{ if ne (print .Platform) \"&{unknown unknown [] }\" }}$DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG@{{ println .Digest }}{{end}} {{end}}");
|
||||||
|
|
||||||
docker buildx imagetools create $DOCKER_MULTI_ARCH_IMAGES --tag $DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG;
|
docker buildx imagetools create $DOCKER_MULTI_ARCH_IMAGES --tag $DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG;
|
||||||
|
|
||||||
docker buildx imagetools inspect $DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG;
|
docker buildx imagetools inspect $DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG;
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
echo "[DEBUG] building image";
|
echo "[DEBUG] building image";
|
||||||
|
|
||||||
docker build . \
|
docker build . \
|
||||||
--label org.opencontainers.image.created="$(date '+%Y-%m-%d %H:%M:%S%:z')" \
|
--label org.opencontainers.image.created="$(date '+%Y-%m-%d %H:%M:%S%:z')" \
|
||||||
--label org.opencontainers.image.documentation="$CI_PROJECT_URL" \
|
--label org.opencontainers.image.documentation="$CI_PROJECT_URL" \
|
||||||
--label org.opencontainers.image.source="$CI_PROJECT_URL" \
|
--label org.opencontainers.image.source="$CI_PROJECT_URL" \
|
||||||
--label org.opencontainers.image.url="$CI_PROJECT_URL/-/releases/$(cz -n cz_nfc version --project)" \
|
--label org.opencontainers.image.url="$CI_PROJECT_URL/-/releases/$(cz -n cz_nfc version --project)" \
|
||||||
--label org.opencontainers.image.version="$(cz -n cz_nfc version --project)" \
|
--label org.opencontainers.image.version="$(cz -n cz_nfc version --project)" \
|
||||||
--label org.opencontainers.image.revision="$CI_COMMIT_SHA" \
|
--label org.opencontainers.image.revision="$CI_COMMIT_SHA" \
|
||||||
--no-cache \
|
--build-arg CI_JOB_TOKEN=$CI_JOB_TOKEN --build-arg CI_PROJECT_ID=$CI_PROJECT_ID --build-arg CI_API_V4_URL=$CI_API_V4_URL \
|
||||||
--file $DOCKER_DOCKERFILE \
|
--file $DOCKER_DOCKERFILE \
|
||||||
--tag $DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG;
|
--tag $DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG;
|
||||||
|
|
||||||
docker push $DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG;
|
docker push $DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG;
|
||||||
|
|
||||||
fi
|
fi
|
||||||
rules:
|
rules:
|
||||||
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
||||||
when: never
|
when: never
|
||||||
|
|||||||
Reference in New Issue
Block a user