File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ # syntax=docker/dockerfile:1
2
+
3
+ # ###########################################
4
+ # Build stage
5
+ # ###########################################
6
+ FROM golang:1.24-alpine AS builder
7
+
8
+ # Install build dependencies for CGO & SQLite
9
+ RUN apk add --no-cache git gcc musl-dev sqlite-dev
10
+
11
+ WORKDIR /app
12
+
13
+ # Copy go modules manifests first and download deps (leverages Docker layer caching)
14
+ COPY go.mod go.sum ./
15
+ RUN go mod download
16
+
17
+ # Copy the rest of the application source
18
+ COPY . .
19
+
20
+ # Build the binary (CGO enabled so that github.com/mattn/go-sqlite3 works)
21
+ RUN CGO_ENABLED=1 go build -v -o todo-app .
22
+
23
+ # ###########################################
24
+ # Runtime stage
25
+ # ###########################################
26
+ FROM alpine:latest AS runner
27
+
28
+ # Install runtime dependencies for the compiled binary (libsqlite3 & CA certs)
29
+ RUN apk add --no-cache ca-certificates sqlite-libs
30
+
31
+ WORKDIR /app
32
+
33
+ # Copy compiled binary and application assets
34
+ COPY --from=builder /app/todo-app ./
35
+
36
+ # Create data directory
37
+ RUN mkdir /data
38
+
39
+ # Ensure non-root user can write the database file
40
+ RUN chown -R nobody:nobody /data
41
+
42
+ # Expose the port used by the Go server
43
+ EXPOSE 8081
44
+ ENV PORT=8081
45
+
46
+ # Run as non-root for security where possible
47
+ USER nobody
48
+
49
+ ENTRYPOINT ["./todo-app" ]
You can’t perform that action at this time.
0 commit comments