# ------------------------------------------------------ # 1. Build Stage # ------------------------------------------------------ FROM golang:1.25-alpine AS builder # Install necessary build tools for SQLite (CGO) RUN apk add --no-cache gcc musl-dev sqlite-dev WORKDIR /app # Cache dependencies COPY go.mod go.sum ./ RUN go mod download # Copy source files COPY . . # Build with CGO enabled for SQLite RUN CGO_ENABLED=1 GOOS=linux go build -o server main.go # ------------------------------------------------------ # 2. Runtime Stage # ------------------------------------------------------ FROM alpine:3.20 # Install SQLite (if your app interacts directly with .db file) RUN apk add --no-cache sqlite WORKDIR /app # Copy binary and required files COPY --from=builder /app/server . COPY --from=builder /app/css ./css COPY --from=builder /app/views ./views COPY --from=builder /app/my_website.db ./ COPY --from=builder /app/data ./data EXPOSE 8080 CMD ["./server"]