Skip to content

Commit

Permalink
Specify platform as linux/${ARCH} when cross-building docker images (
Browse files Browse the repository at this point in the history
…#2503)

When using arch specific dockerfiles it's also necessary to specify `--platform`
flag. Otherwise dockerx can build arm image with x86_64 binaries, which may not
work properly in deployment.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
hairyhum and mergify[bot] authored Dec 6, 2023
1 parent 7a0873a commit 2756ffb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion build/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ build_licenses_info_image() {
elif grep docker /proc/1/cgroup -qa; then
mount_cmd="--volumes-from $(grep docker -m 1 /proc/self/cgroup|cut -d/ -f3)"
fi
if [ -z "${ARCH:-""}" ]; then
echo "ARCH must be set"
exit 1
fi
docker run --rm ${mount_cmd} \
--platform linux/${ARCH}\
"ghcr.io/kanisterio/license-extractor:4e0a91a" \
--mode merge \
--source ${src_dir} \
Expand Down Expand Up @@ -66,5 +71,5 @@ sed \
-e "s|ARG_ARCH|${ARCH}|g" \
-e "s|ARG_SOURCE_BIN|${SOURCE_BIN}|g" \
Dockerfile.in > .dockerfile-${ARCH}
docker buildx build --push --pull --sbom=true ${baseimagearg:-} --build-arg kanister_version=${VERSION} -t ${IMAGE}:${VERSION} -f .dockerfile-${ARCH} .
docker buildx build --push --pull --sbom=true ${baseimagearg:-} --build-arg kanister_version=${VERSION} -t ${IMAGE}:${VERSION} --platform linux/${ARCH} -f .dockerfile-${ARCH} .
docker images -q ${IMAGE}:${VERSION}

0 comments on commit 2756ffb

Please sign in to comment.