-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
75 lines (57 loc) · 2.21 KB
/
Dockerfile
File metadata and controls
75 lines (57 loc) · 2.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# syntax=docker/dockerfile:1.6
###############################################################################
# Build stage
###############################################################################
FROM golang:1.25.5-alpine AS builder
ARG TARGETARCH
ARG COMMIT_SHA=dev
RUN apk add --no-cache build-base git curl
WORKDIR /src
# Cache modules
COPY go.mod go.sum ./
RUN go mod download
# Download Tailwind CLI (pinned to v3.4.17)
RUN TAILWIND_VERSION="v3.4.17" && \
case "${TARGETARCH}" in \
amd64) TAILWIND_ASSET="tailwindcss-linux-x64" ;; \
arm64) TAILWIND_ASSET="tailwindcss-linux-arm64" ;; \
*) echo "Unsupported arch: ${TARGETARCH}"; exit 1 ;; \
esac && \
curl -sL "https://github.com/tailwindlabs/tailwindcss/releases/download/${TAILWIND_VERSION}/${TAILWIND_ASSET}" -o /usr/local/bin/tailwindcss && \
chmod +x /usr/local/bin/tailwindcss
# Copy Tailwind config and source CSS
COPY tailwind.config.js ./
COPY web ./web
# Build Tailwind CSS
RUN tailwindcss -i web/static/app.css -o web/static/app.built.css --minify
# Copy remaining application source
COPY cmd ./cmd
COPY internal ./internal
COPY pkg ./pkg
# Build binary with commit SHA for cache busting
RUN CGO_ENABLED=1 GOOS=linux go build \
-trimpath \
-ldflags="-X formlander/internal/server.buildCommit=${COMMIT_SHA}" \
-o /src/formlander \
./cmd/formlander
# Runtime stage
###############################################################################
FROM alpine:3.20
WORKDIR /app
# Install minimal runtime dependencies
RUN apk add --no-cache ca-certificates tzdata curl && \
mkdir -p /app/storage /app/storage/logs
COPY --from=builder /src/formlander /usr/local/bin/formlander
ENV FORMLANDER_ENV=production \
FORMLANDER_PORT=8080 \
FORMLANDER_DATA_DIR=/app/storage \
FORMLANDER_LOGS_DIR=/app/storage/logs \
FORMLANDER_SESSION_TIMEOUT_SECONDS=1800
EXPOSE 8080
# Health check using curl with proper error handling
# -f flag makes curl fail on HTTP errors (4xx, 5xx)
# Using shell form to ensure environment variable expansion
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD /bin/sh -c "curl -f http://localhost:${FORMLANDER_PORT}/_health || exit 1"
VOLUME ["/app/storage"]
ENTRYPOINT ["/usr/local/bin/formlander"]