-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
30 lines (21 loc) · 777 Bytes
/
Dockerfile
File metadata and controls
30 lines (21 loc) · 777 Bytes
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
# -------- Build stage --------
FROM golang:1.22-alpine AS builder
# Optional build-time value; can be overridden with --build-arg
ARG BUILD_VALUE="build_time_value_not_set"
WORKDIR /app
# Copy go modules files first to leverage Docker cache
COPY go.mod .
RUN go mod download
# Copy the rest of the source code
COPY . .
# Build with injected value
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-s -w -X main.BuildValue=${BUILD_VALUE}" -o /app/test-image
# -------- Runtime stage --------
FROM alpine:3.19
# Set non-root user (optional)
# RUN adduser -D appuser
# USER appuser
# Copy binary from builder stage
COPY --from=builder /app/test-image /usr/local/bin/test-image
# Default command prints the build value then sleeps forever
CMD ["/usr/local/bin/test-image"]