From 4221780ce53ff7484f6f1958173373dc963e7967 Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Sat, 22 Feb 2025 14:06:20 -0500 Subject: functional scratch dockerfile --- resources/Dockerfile | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'resources/Dockerfile') diff --git a/resources/Dockerfile b/resources/Dockerfile index 89c1ac3..4a460c3 100644 --- a/resources/Dockerfile +++ b/resources/Dockerfile @@ -1,23 +1,21 @@ -FROM golang:latest AS setup -WORKDIR /app - -COPY go.* ./ -COPY cmd cmd -COPY internal internal +FROM golang:latest AS compile +WORKDIR /build +COPY . . RUN go mod download && go mod verify -RUN CGO_ENABLED=0 GOOS=linux go build -o /application cmd/songlinkr/main.go +# Enable static linking for scratch +RUN CGO_ENABLED=0 GOOS=linux go build -o /application -ldflags="-s -w" main.go FROM alpine:latest AS compressor - RUN apk add --no-cache upx - -COPY --from=setup +COPY --from=compile /application /application +RUN upx --best /application FROM scratch AS package -COPY --from=setup /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY --from=setup /application /application +# Copy CA certificates +COPY --from=alpine:latest /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=compressor /application /application -CMD ["/application"] +ENTRYPOINT ["/application"] -- cgit v1.2.3