Skip to content

Commit

Permalink
ci: 🎡 opmimize image building
Browse files Browse the repository at this point in the history
  • Loading branch information
monlor committed Feb 13, 2025
1 parent 76a2a7c commit cf6d01e
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
FROM golang:1.23-alpine AS builder
# Build stage
FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS builder

ARG TARGETARCH

WORKDIR /app
COPY . .

# Copy go mod files first for better layer caching
COPY go.mod go.sum ./
RUN go mod download
RUN CGO_ENABLED=0 GOOS=linux go build -o k8s-image-updater

FROM alpine:3.19
# Copy source code
COPY . .

ENV GIN_MODE=release
# Build with optimizations
RUN GOARCH=${TARGETARCH} CGO_ENABLED=0 GOOS=linux go build \
-ldflags="-s -w" \
-o k8s-image-updater

WORKDIR /app
COPY --from=builder /app/k8s-image-updater .
# Final stage
FROM scratch

# Copy SSL certificates from builder
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /app/k8s-image-updater /

ENV GIN_MODE=release

EXPOSE 8080
CMD ["./k8s-image-updater"]
ENTRYPOINT ["/k8s-image-updater"]

0 comments on commit cf6d01e

Please sign in to comment.