-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
57 lines (41 loc) · 1.38 KB
/
Dockerfile
File metadata and controls
57 lines (41 loc) · 1.38 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
# Build stage
FROM golang:1.24-alpine AS builder
# Install build dependencies
RUN apk add --no-cache git make
WORKDIR /app
# Copy go mod and sum files
COPY go.mod go.sum ./
RUN go mod download
# Copy the source code
COPY . .
# Build argument for target binary (default to server)
ARG TARGET=server
# Build arguments for version information
ARG VERSION=dev
ARG COMMIT=unknown
ARG BUILD_TIME=unknown
# Build the binary
RUN CGO_ENABLED=0 GOOS=linux go build \
-ldflags "-X github.com/cmelgarejo/go-modulith-template/internal/version.Version=${VERSION} \
-X github.com/cmelgarejo/go-modulith-template/internal/version.Commit=${COMMIT} \
-X github.com/cmelgarejo/go-modulith-template/internal/version.BuildTime=${BUILD_TIME}" \
-o /app/bin/service ./cmd/${TARGET}/main.go
# Run stage
FROM alpine:3.20
# Install runtime dependencies (ca-certificates for HTTPS/gRPC TLS)
RUN apk add --no-cache ca-certificates tzdata
WORKDIR /app
# Copy the binary from builder
COPY --from=builder /app/bin/service ./service
# Copy configurations
COPY configs/ ./configs/
# Create non-root user for security
RUN addgroup -g 1001 appgroup && \
adduser -u 1001 -G appgroup -s /bin/sh -D appuser && \
chown -R appuser:appgroup /app
# Switch to non-root user
USER appuser
# Expose ports (standard defaults, can be overridden)
EXPOSE 8080 9050
# Run the service
CMD ["./service"]