diff --git a/build/Dockerfile b/build/Dockerfile index 6741dc6..df04dee 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,7 +1,7 @@ ########### # BUILDER # ########### -FROM golang:1.24.0 as builder +FROM golang:1.24.2 AS builder ARG VERSION ARG BUILT @@ -25,14 +25,22 @@ RUN mkdir -p /root/.ssh && \ echo "$SSH_PRV_KEY" > /root/.ssh/id_rsa && \ chmod 600 /root/.ssh/id_rsa - - RUN --mount=type=ssh go mod download RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ -ldflags "$FLAG" \ -o product +########## +## upx ## +######### +# 壓縮執行黨,讓他變小 +FROM gruebel/upx:latest as upx +WORKDIR /app + +COPY --from=builder /app/product /app/product +# Compress the binary and copy it to final image +RUN upx --best --lzma /app/product ########## ## FINAL # ########## @@ -40,7 +48,7 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ FROM gcr.io/distroless/static-debian11 WORKDIR /app -COPY --from=builder /app/product /app/product +COPY --from=upx /app/product /app/product COPY --from=builder /app/etc/product.yaml /app/etc/product.yaml EXPOSE 8080 CMD ["/app/product"] \ No newline at end of file diff --git a/go.mod b/go.mod index 13d5c2c..33a6728 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,11 @@ module code.30cm.net/digimon/app-cloudep-product-service -go 1.24.0 +go 1.24.2 require ( code.30cm.net/digimon/library-go/errs v1.2.14 code.30cm.net/digimon/library-go/mongo v0.0.9 + code.30cm.net/digimon/library-go/mongo v0.0.9 github.com/alicebob/miniredis/v2 v2.34.0 github.com/golang/snappy v0.0.4 github.com/shopspring/decimal v1.4.0