Skip to content

Commit

Permalink
Fix target platform
Browse files Browse the repository at this point in the history
  • Loading branch information
vickunwu committed Jan 16, 2025
1 parent 5162745 commit d8c9e20
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -309,4 +312,5 @@ jobs:
append_body: true
body: |
<hr />
## Check binary attestation at [here](${{ steps.attest.outputs.attestation-url }})
40 changes: 36 additions & 4 deletions Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -41,9 +44,9 @@ target "image" {
cache-from = [
"type=registry,ref=${ARTIFACT_REPO}:buildcache-${TARGET}"
]
target = regexall("(?P<arch>[^-]+)-unknown-linux-(?P<tgt>.+)", TARGET)[0].tgt
target = "${regexall("(?P<arch>[^-]+)-unknown-linux-(?P<tgt>.+)", TARGET)[0].tgt}-${DOCKER_PLATFORM}"
platforms = [
regexall("(?P<arch>[^-]+)-unknown-linux-(?P<tgt>.+)", 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"]
}

0 comments on commit d8c9e20

Please sign in to comment.