-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
47 lines (36 loc) · 1.29 KB
/
Dockerfile
File metadata and controls
47 lines (36 loc) · 1.29 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: compile Go binary with static SQLite
# ---------------------------------------------
FROM golang:1.24-alpine AS builder
ENV CGO_ENABLED=1
RUN apk add --no-cache \
gcc \
musl-dev \
sqlite
WORKDIR /workspace
COPY go.mod go.sum ./
RUN go mod download
COPY cmd ./cmd
COPY internal ./internal
COPY assets ./assets
COPY pkg ./pkg
# Build a static, stripped binary
RUN go build \
-ldflags "-s -w -extldflags '-static'" \
-o forum ./cmd/web
# initialize a fresh DB on the builder
COPY data/init.sql /workspace/init.sql
RUN sqlite3 data.db < ./init.sql && \
sqlite3 data.db ".tables"
# ---------------------------------------------
# Runtime Stage: minimal scratch image
# ---------------------------------------------
FROM scratch
COPY --from=builder /workspace/forum /usr/local/bin/forum
COPY --from=builder /workspace/data.db /app/data/db.sqlite
WORKDIR /app
# Tell Docker this is where the DB lives
VOLUME ["/app/data"]
ENV DATABASE_PATH="/app/data/db.sqlite"
EXPOSE 4001
ENTRYPOINT ["/usr/local/bin/forum"]