fix cross-compiled docker images

binaries for linux/amd64 were build for each target platform. apparently the
--platform in the first-stage overrides the $TARGET* variables of the build.
docker behaviour always manages to surprise me...
This commit is contained in:
Mechiel Lukkien
2023-02-27 13:46:29 +01:00
parent 92e018e463
commit f3f2c6f8ea
2 changed files with 18 additions and 9 deletions

View File

@ -32,18 +32,23 @@ alpineversion=alpine$(podman run alpine:latest cat /etc/alpine-release)
# We assume the alpines for all platforms have the same version...
echo Building with $goversion and $alpineversion
# We build the images individually so we can pass goos and goarch ourselves,
# needed because the platform in "FROM --platform <image>" in the first stage
# seems to override the TARGET* variables.
test -d empty || mkdir empty
podman build --platform $platforms -f Dockerfile.release -v $HOME/go/pkg/sumdb:/go/pkg/sumbd:ro --build-arg moxversion=$moxversion --manifest docker.io/moxmail/mox:$moxversion-$goversion-$alpineversion empty
(podman manifest rm moxmail/mox:$moxversion-$goversion-$alpineversion || exit 0)
for platform in $(echo $platforms | sed 's/,/ /g'); do
goos=$(echo $platform | sed 's,/.*$,,')
goarch=$(echo $platform | sed 's,^.*/,,')
podman build --platform $platform -f Dockerfile.release -v $HOME/go/pkg/sumdb:/go/pkg/sumbd:ro --build-arg goos=$goos --build-arg goarch=$goarch --build-arg moxversion=$moxversion --manifest moxmail/mox:$moxversion-$goversion-$alpineversion empty
done
cat <<EOF
# Suggested commands to push images:
podman manifest push --all docker.io/moxmail/mox:$moxversion-$goversion-$alpineversion
podman manifest push --all moxmail/mox:$moxversion-$goversion-$alpineversion docker.io/moxmail/mox:$moxversion-$goversion-$alpineversion
podman tag docker.io/moxmail/mox:$moxversion-$goversion-$alpineversion docker.io/moxmail/mox:$moxversion
podman manifest push --all docker.io/moxmail/mox:$moxversion
podman tag docker.io/moxmail/mox:$moxversion docker.io/moxmail/mox:latest
podman manifest push --all docker.io/moxmail/mox:latest
podman manifest push --all moxmail/mox:$moxversion-$goversion-$alpineversion docker.io/moxmail/mox:$moxversion
podman manifest push --all moxmail/mox:$moxversion-$goversion-$alpineversion docker.io/moxmail/mox:latest
EOF