diff --git a/Dockerfile.release b/Dockerfile.release index 35b8f7b..9e698ae 100644 --- a/Dockerfile.release +++ b/Dockerfile.release @@ -1,8 +1,12 @@ FROM --platform=linux/amd64 docker.io/golang:1-alpine AS build +# note: cannot use $TARGETOS or $TARGETARCH because apparently the --platform in +# the FROM above overrides the actual target os/arch from the command-line. +ARG goos +ARG goarch WORKDIR / ARG moxversion -RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go install -mod mod -trimpath github.com/mjl-/mox@$moxversion -RUN test -f /go/bin/mox && cp /go/bin/mox /bin/mox || cp /go/bin/${TARGETOS}_${TARGETARCH}/mox /bin/mox +RUN CGO_ENABLED=0 GOOS=$goos GOARCH=$goarch go install -mod mod -trimpath github.com/mjl-/mox@$moxversion +RUN test -f /go/bin/mox && cp /go/bin/mox /bin/mox || cp /go/bin/${goos}_${goarch}/mox /bin/mox # Using latest may break at some point, but will hopefully be convenient most of the time. FROM --platform=$TARGETPLATFORM docker.io/alpine:latest diff --git a/docker-release.sh b/docker-release.sh index 1f0e42c..8476d5a 100755 --- a/docker-release.sh +++ b/docker-release.sh @@ -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 " 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 <