-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
42 lines (30 loc) · 1.11 KB
/
Dockerfile
File metadata and controls
42 lines (30 loc) · 1.11 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
# Build stage
FROM golang:1.26-alpine AS builder
# Install build dependencies for CGO (though we plan to disable it)
RUN apk add --no-cache git gcc musl-dev
WORKDIR /app
# Copy go.mod and go.sum first for better caching
COPY go.mod go.sum ./
RUN go mod download
# Copy the rest of the source code
COPY . .
# Build a statically linked binary
# CGO_ENABLED=0 ensures we don't depend on glibc
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o clouddns cmd/clouddns/main.go
# Final stage
FROM alpine:3.20
# Add security updates and root CA certificates
RUN apk add --no-cache ca-certificates tzdata
WORKDIR /app
# Create a non-root user for security
RUN adduser -D -u 1000 clouddns
USER clouddns
# Copy the binary from the builder
COPY --from=builder /app/clouddns .
# Copy schema for database initialization if needed (used by entrypoint scripts)
COPY --from=builder /app/internal/adapters/repository/schema.sql ./schema.sql
# DNS defaults to 1053 for unprivileged execution (Standard ports 53/853/443 require root)
# Management API on 8080
EXPOSE 1053/udp 1053/tcp 8080/tcp 853/tcp
# Run the server
ENTRYPOINT ["./clouddns"]