-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
74 lines (54 loc) · 2.36 KB
/
Dockerfile
File metadata and controls
74 lines (54 loc) · 2.36 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
# Multi-stage Dockerfile for Ditto
# Builds tiny production binary
# ─────────────────────────────────────────────────────────────
# Stage 1: Build
# ─────────────────────────────────────────────────────────────
FROM golang:1.21-alpine AS builder
# Install build dependencies
RUN apk add --no-cache git ca-certificates
# Set working directory
WORKDIR /build
# Copy go mod files
COPY go.mod go.sum ./
RUN go mod download && go mod verify
# Copy source code
COPY . .
# Build arguments
ARG VERSION=dev
ARG COMMIT=unknown
ARG DATE=unknown
# Build optimized binary
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-trimpath \
-ldflags "-s -w \
-X main.version=${VERSION} \
-X main.commit=${COMMIT} \
-X main.date=${DATE}" \
-o /build/Ditto \
./cmd/ditto
# ─────────────────────────────────────────────────────────────
# Stage 2: Runtime (minimal image)
# ─────────────────────────────────────────────────────────────
FROM scratch AS runtime
# Copy CA certificates for HTTPS
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Copy binary from builder
COPY --from=builder /build/Ditto /Ditto
# Set working directory
WORKDIR /data
# Default command
ENTRYPOINT ["/Ditto"]
CMD ["help"]
# ─────────────────────────────────────────────────────────────
# Stage 3: Development (with examples)
# ─────────────────────────────────────────────────────────────
FROM golang:1.21-alpine AS development
RUN apk add --no-cache git ca-certificates
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# Build with debug symbols
RUN go build -race -o /app/Ditto ./cmd/ditto
WORKDIR /workspace
ENTRYPOINT ["/app/Ditto"]