-
-
Notifications
You must be signed in to change notification settings - Fork 315
Expand file tree
/
Copy pathDockerfile
More file actions
50 lines (37 loc) · 1.21 KB
/
Copy pathDockerfile
File metadata and controls
50 lines (37 loc) · 1.21 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
# Build stage
FROM golang:1.25-alpine AS builder
WORKDIR /build
# Install build dependencies
RUN apk add --no-cache git gcc musl-dev sqlite-dev
# Copy go mod files first for better caching
COPY go.mod go.sum ./
RUN go mod download
# Copy only necessary source files
COPY cmd/ cmd/
COPY internal/ internal/
# Build the server binary with optimizations and cache
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo \
-tags sqlite_fts5 \
-ldflags "-extldflags '-static' -s -w" \
-trimpath \
-o server ./cmd/server
# Runtime stage
FROM alpine:latest
RUN apk add --no-cache ca-certificates curl gzip
WORKDIR /app
# Copy binary, config, and startup script
COPY --link --from=builder --chmod=755 /build/server .
COPY --link --chmod=644 config.yaml .
COPY --link --chmod=755 scripts/startup.sh .
# Environment variables
ENV PORT=1279 \
GIN_MODE=release \
RATE_LIMIT_ENABLED=true \
RATE_LIMIT_RPS=10 \
RATE_LIMIT_BURST=20
EXPOSE 1279
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:${PORT}/api/v1/health || exit 1
CMD ["./startup.sh"]