app-cloudep-product-service/build/Dockerfile

54 lines
1.1 KiB
Docker
Raw Permalink Normal View History

2025-03-12 14:05:38 +00:00
###########
# BUILDER #
###########
2025-04-10 07:54:58 +00:00
FROM golang:1.24.2 AS builder
2025-03-12 14:05:38 +00:00
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 product
2025-04-10 07:54:58 +00:00
##########
## 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
2025-03-12 14:05:38 +00:00
##########
## FINAL #
##########
#
FROM gcr.io/distroless/static-debian11
WORKDIR /app
2025-04-10 07:54:58 +00:00
COPY --from=upx /app/product /app/product
2025-03-12 14:05:38 +00:00
COPY --from=builder /app/etc/product.yaml /app/etc/product.yaml
EXPOSE 8080
CMD ["/app/product"]