-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
76 lines (57 loc) · 1.91 KB
/
Dockerfile
File metadata and controls
76 lines (57 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# ============================================
# Development stage with hot reload
# ============================================
FROM golang:1.26.2-alpine AS development
WORKDIR /app
# hadolint ignore=DL3018
RUN apk add --no-cache ca-certificates tzdata git
COPY go.mod go.sum* ./
RUN go mod download
EXPOSE 80 443
CMD ["go", "tool", "air", "-c", ".air.toml"]
# ============================================
# Build stage
# ============================================
FROM golang:1.26.2-alpine AS builder
WORKDIR /app
# Security: Get latest CA certificates
# hadolint ignore=DL3018
RUN apk add --no-cache ca-certificates tzdata
# Download dependencies first (cache efficiency)
COPY go.mod go.sum* ./
RUN go mod download && go mod verify
# Copy source code
COPY . .
# Build
ARG VERSION=dev
ARG COMMIT=unknown
ARG DATE=unknown
ARG BUILT_BY=docker
RUN CGO_ENABLED=0 GOOS=linux go build \
-ldflags="-s -w \
-X github.com/kan/roji/cmd/roji/cmd.Version=${VERSION} \
-X github.com/kan/roji/cmd/roji/cmd.Commit=${COMMIT} \
-X github.com/kan/roji/cmd/roji/cmd.Date=${DATE} \
-X github.com/kan/roji/cmd/roji/cmd.BuiltBy=${BUILT_BY}" \
-trimpath \
-o /roji \
./cmd/roji
# ============================================
# Production stage (distroless)
# ============================================
FROM gcr.io/distroless/static:nonroot AS production
# Metadata
LABEL org.opencontainers.image.source="https://github.com/kan/roji"
LABEL org.opencontainers.image.description="Reverse proxy for local development"
LABEL org.opencontainers.image.licenses="MIT"
# Copy CA certificates and timezone info
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
# Copy binary
COPY --from=builder /roji /roji
# Certificate directory
VOLUME /certs
EXPOSE 80 443
# Run as nonroot user (UID 65532)
USER nonroot:nonroot
ENTRYPOINT ["/roji"]