-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
56 lines (40 loc) · 1.3 KB
/
Dockerfile
File metadata and controls
56 lines (40 loc) · 1.3 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
# --- SECTION: Metadata ---
FROM golang:1.25-alpine AS builder
LABEL maintainer="Clovis Mugaruka <clovis.mugaruka@gmail.com>"
# Define build-time arguments (Stage 1)
ARG PORT=4000
ARG TZ=Africa/Nairobi
# --- SECTION: Build Dependencies ---
RUN apk add --no-cache git ca-certificates
WORKDIR /app
# Leverage Docker layer caching for Go modules
COPY go.mod go.sum ./
RUN go mod download
# --- SECTION: Compilation ---
COPY . .
# Build a statically linked binary
# -ldflags="-w -s" strips debug info for a smaller footprint
RUN CGO_ENABLED=0 GOOS=linux go build \
-buildvcs=true \
-ldflags="-w -s" \
-o alice ./cmd/server
# --- SECTION: Final Runtime (Distroless) ---
FROM gcr.io/distroless/static-debian12:latest
# Re-declare ARGs to make them available in this stage
ARG PORT=4000
ARG TZ=Africa/Nairobi
# Set Environment Variables for the application
ENV TZ=${TZ}
ENV PORT=${PORT}
WORKDIR /
# --- SECTION: Asset Transfer ---
# Copy the compiled binary from the builder stage
COPY --from=builder /app/alice .
# Copy configuration and certificates
COPY --from=builder /app/.env ./.env
COPY --from=builder /app/public.cer ./public.cer
# --- SECTION: Execution ---
# Expose the port (now correctly resolving the ARG)
EXPOSE ${PORT}
# Run the binary directly (Distroless has no shell)
ENTRYPOINT ["/alice"]