########### # BUILDER # ########### FROM golang:1.24.2 AS builder ARG VERSION ARG BUILT ARG GIT_COMMIT ARG SSH_PRV_KEY # private go packages ENV GOPRIVATE=code.30cm.net ENV FLAG="-s -w -X main.Version=${VERSION} -X main.Built=${BUILT} -X main.GitCommit=${GIT_COMMIT}" WORKDIR /app COPY . . RUN apt-get update && \ apt-get install git # Make the root foler for our ssh RUN mkdir -p /root/.ssh && \ chmod 0700 /root/.ssh && \ ssh-keyscan git.30cm.net > /root/.ssh/known_hosts && \ 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 wallet ########## ## upx ## ######### # 壓縮執行黨,讓他變小 FROM gruebel/upx:latest as upx WORKDIR /app COPY --from=builder /app/wallet /app/wallet # Compress the binary and copy it to final image RUN upx --best --lzma /app/wallet ########## ## FINAL # ########## # FROM gcr.io/distroless/static-debian11 WORKDIR /app COPY --from=upx /app/product /app/wallet COPY --from=builder /app/etc/wallet.yaml /app/etc/wallet.yaml EXPOSE 8080 CMD ["/app/wallet"]