From 4a19a5722e30429f2d9cccc91132ddab884b4a91 Mon Sep 17 00:00:00 2001 From: Ben Morgenstren Date: Wed, 5 Feb 2025 13:02:35 -0500 Subject: [PATCH] Update dockerfile for multi-arch builds --- Dockerfile | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3d69a99..09a41f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,21 +12,31 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM golang:1.21 +FROM golang:1.22.0 AS builder + +WORKDIR /app RUN \ - mkdir -p /licenses && \ - curl -s -q https://raw.githubusercontent.com/harshavardhana/s3www/master/CREDITS -o /licenses/CREDITS && \ - curl -s -q https://raw.githubusercontent.com/harshavardhana/s3www/master/LICENSE -o /licenses/LICENSE + mkdir -p /app/licenses && \ + curl -s -q https://raw.githubusercontent.com/harshavardhana/s3www/master/CREDITS -o /app/licenses/CREDITS && \ + curl -s -q https://raw.githubusercontent.com/harshavardhana/s3www/master/LICENSE -o /app/licenses/LICENSE + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o s3www . FROM scratch EXPOSE 8080 # Copy CA certificates to prevent x509: certificate signed by unknown authority errors -COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt -COPY --from=0 /licenses /licenses +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt + +COPY --from=builder /app/licenses /licenses -COPY s3www /s3www +COPY --from=builder /app/s3www /s3www ENTRYPOINT ["/s3www"]