-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
39 lines (29 loc) · 925 Bytes
/
Copy pathDockerfile
File metadata and controls
39 lines (29 loc) · 925 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
31
32
33
34
35
36
37
38
39
# Build stage
FROM golang:1.24-alpine AS builder
# Install build dependencies
RUN apk add --no-cache git ca-certificates build-base postgresql-dev
WORKDIR /app
# Copy module files first
COPY go.mod go.sum ./
# Download dependencies with proper retry
RUN for i in $(seq 1 3); do \
go mod download && break || sleep 5; \
done
# Copy source code
COPY . .
# Build
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o /app/main .
# Final stage
FROM alpine:3.18
RUN apk add --no-cache ca-certificates postgresql-client && \
adduser -D -u 1000 -g '' appuser && \
mkdir -p /app/config && \
chown -R appuser:appuser /app
WORKDIR /app
COPY --from=builder --chown=appuser:appuser /app/main .
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --chown=appuser:appuser .env.example .
COPY --chown=appuser:appuser config/*.yaml ./config/
USER appuser
EXPOSE 8080
CMD ["./main"]