From 48663155860e2b862b975a90f3fff3fffcd3e17d Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Fri, 31 May 2024 00:23:53 +0200 Subject: [PATCH] feat: add dockerfile build arguments --- README.md | 13 +++++++++++++ entrypoint.sh | 11 ++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b140b47..79e347b 100644 --- a/README.md +++ b/README.md @@ -218,3 +218,16 @@ Example: `thetadev256/test-actions-helloworld2:main` Full reference to the built image with registry and tag. Example: `thetadev256/test-actions-helloworld2:main` + +## Dockerfile build arguments + +Action-Kaniko automatically sets build arguments to allow for different dockerfile actions +depending on the OS and architecture the image is build for. + +The supported arguments are: + +- `TARGETPLATFORM` (example: linux/amd64) +- `TARGETOS` (example: linux) +- `TARGETARCH` (example: amd64) +- `TARGETARCH_ALT` (alternative architecture name, x86_64 for amd64, otherwise the same as TARGETARCH) +- `TARGETVARIANT` (third docker platform parameter like ARM version) diff --git a/entrypoint.sh b/entrypoint.sh index 8e59589..7ddb396 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -96,7 +96,16 @@ if [ -n "$INPUT_PLATFORMS" ]; then DESTINATION="--no-push --tarPath /kaniko/build/${platformFn}.tar --destination $IMAGE" DIGEST="--image-name-tag-with-digest-file=/kaniko/build/${platformFn}_image-tag-digest" - runKaniko "${ARGS} --custom-platform=${platform} $DESTINATION $DIGEST" + targetos=$(echo "$platform" | cut -d/ -f1) + targetarch=$(echo "$platform" | cut -d/ -f2) + targetvariant=$(echo "$platform" | cut -d/ -f3) + + case "$targetarch" in + 'amd64') targetarchAlt="x86_64" ;; + *) targetarchAlt="$targetarch" ;; + esac + + runKaniko "${ARGS} --custom-platform=${platform} --build-arg TARGETPLATFORM='${platform}' --build-arg TARGETOS='${targetos}' --build-arg TARGETARCH='${targetarch}' --build-arg TARGETARCH_ALT='${targetarchAlt}' --build-arg TARGETVARIANT='${targetvariant}' $DESTINATION $DIGEST" echo "✅ $platform image built: $(head -n 1 "/kaniko/build/${platformFn}_image-tag-digest")" done