From d8c9e20beaf6f948f11b5311acc8683a41a1c368 Mon Sep 17 00:00:00 2001 From: vickunwu <31735039+vickunwu@users.noreply.github.com> Date: Thu, 16 Jan 2025 19:13:36 +0800 Subject: [PATCH] Fix target platform --- .github/workflows/ci.yml | 4 ++++ Dockerfile.build | 40 ++++++++++++++++++++++++++++++++++++---- docker-bake.hcl | 7 +++++-- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f27bd79e9..d9e35d69c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -138,7 +138,10 @@ jobs: ARTIFACT_REPO: ghcr.io/${{github.repository}} BUILD_ENV: ${{matrix.build_env}} ZIG_VERSION: ${{ steps.zig-version.outputs.zig_version }} + DOCKER_PLATFORM: ${{ startsWith(matrix.target, 'x86') && 'amd64' || 'arm64' }} with: + set: | + *.platform=linux/${{ env.DOCKER_PLATFORM }} source: . files: | docker-bake.hcl @@ -309,4 +312,5 @@ jobs: append_body: true body: |
+ ## Check binary attestation at [here](${{ steps.attest.outputs.attestation-url }}) diff --git a/Dockerfile.build b/Dockerfile.build index cc30abcf6..0eda84d72 100644 --- a/Dockerfile.build +++ b/Dockerfile.build @@ -110,9 +110,9 @@ FROM scratch AS binaries COPY --from=builder /app/artifact / # ***************** -# Runtime image for GNU artifact +# Runtime image for GNU-amd64 artifact # ***************** -FROM --platform=$TARGETPLATFORM docker.io/debian:bookworm-slim AS gnu +FROM --platform=linux/amd64 docker.io/debian:bookworm-slim AS gnu-amd64 WORKDIR /opt/stalwart-mail RUN export DEBIAN_FRONTEND=noninteractive && \ apt-get update && \ @@ -127,9 +127,41 @@ EXPOSE 443 25 110 587 465 143 993 995 4190 8080 ENTRYPOINT ["/bin/sh", "/usr/local/bin/entrypoint.sh"] # ***************** -# Runtime image for musl artifact +# Runtime image for musl-arm64 artifact # ***************** -FROM --platform=$TARGETPLATFORM alpine AS musl +FROM --platform=linux/arm64 alpine AS musl-arm64 +WORKDIR /opt/stalwart-mail +RUN apk add --update --no-cache ca-certificates tzdata && rm -rf /var/cache/apk/* +COPY --from=binaries /stalwart-mail /usr/local/bin +COPY --from=binaries /stalwart-cli /usr/local/bin +COPY ./resources/docker/entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod -R 755 /usr/local/bin +CMD ["/usr/local/bin/stalwart-mail"] +VOLUME [ "/opt/stalwart-mail" ] +EXPOSE 443 25 110 587 465 143 993 995 4190 8080 +ENTRYPOINT ["/bin/sh", "/usr/local/bin/entrypoint.sh"] + +# ***************** +# Runtime image for GNU-arm64 artifact +# ***************** +FROM --platform=linux/arm64 docker.io/debian:bookworm-slim AS gnu-arm64 +WORKDIR /opt/stalwart-mail +RUN export DEBIAN_FRONTEND=noninteractive && \ + apt-get update && \ + apt-get install -yq ca-certificates tzdata +COPY --from=binaries /stalwart-mail /usr/local/bin +COPY --from=binaries /stalwart-cli /usr/local/bin +COPY ./resources/docker/entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod -R 755 /usr/local/bin +CMD ["/usr/local/bin/stalwart-mail"] +VOLUME [ "/opt/stalwart-mail" ] +EXPOSE 443 25 110 587 465 143 993 995 4190 8080 +ENTRYPOINT ["/bin/sh", "/usr/local/bin/entrypoint.sh"] + +# ***************** +# Runtime image for musl-amd64 artifact +# ***************** +FROM --platform=linux/amd64 alpine AS musl-amd64 WORKDIR /opt/stalwart-mail RUN apk add --update --no-cache ca-certificates tzdata && rm -rf /var/cache/apk/* COPY --from=binaries /stalwart-mail /usr/local/bin diff --git a/docker-bake.hcl b/docker-bake.hcl index b75a48867..bf3840c4a 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -13,6 +13,9 @@ variable "BUILD_ENV" { variable "ZIG_VERSION" { default = "$ZIG_VERSION" } +variable "DOCKER_PLATFORM" { + default = "$DOCKER_PLATFORM" +} target "docker-metadata-action" {} target "build" { secret = [ @@ -41,9 +44,9 @@ target "image" { cache-from = [ "type=registry,ref=${ARTIFACT_REPO}:buildcache-${TARGET}" ] - target = regexall("(?P[^-]+)-unknown-linux-(?P.+)", TARGET)[0].tgt + target = "${regexall("(?P[^-]+)-unknown-linux-(?P.+)", TARGET)[0].tgt}-${DOCKER_PLATFORM}" platforms = [ - regexall("(?P[^-]+)-unknown-linux-(?P.+)", TARGET)[0].arch == "aarch64" ? "linux/arm64" : "linux/amd64" + "linux/amd64","linux/arm64" ] output = ["type=image,push=true,compression=zstd,compression-level=9,force-compression=true,oci-mediatypes=true"] }