-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
47 lines (34 loc) · 1.17 KB
/
Dockerfile
File metadata and controls
47 lines (34 loc) · 1.17 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
# Build stage - using Go 1.24 for compatibility with go.mod (pgx requires updated toolchain)
FROM golang:1.24-bookworm AS builder
WORKDIR /app
# Install build dependencies for PostgreSQL
RUN apt-get update && apt-get install -y gcc libc6-dev
# Copy go mod files
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY . .
# Build the application (CGO disabled for PostgreSQL-only)
RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags='-s -w' -o main ./cmd/api
# Runtime stage - minimal image
FROM debian:bookworm-slim
WORKDIR /app
# Install runtime dependencies (PostgreSQL client libs)
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
tzdata \
&& rm -rf /var/lib/apt/lists/*
# Copy binary from builder
COPY --from=builder /app/main .
COPY --from=builder /app/internal/database/migrations ./internal/database/migrations
# Set environment variables
ENV APP_ENV=production
ENV APP_PORT=8080
# Expose port
EXPOSE 8080
# Health check
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
# Run the application
CMD ["./main"]