-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
56 lines (37 loc) · 1.32 KB
/
Copy pathDockerfile
File metadata and controls
56 lines (37 loc) · 1.32 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
# Build stage
FROM golang:1.24-alpine AS builder
WORKDIR /app
# Install build dependencies
RUN apk add --no-cache git nodejs npm
# Copy go mod files first for better caching
COPY go.mod go.sum* ./
RUN go mod download
# Copy package.json and install npm dependencies for Tailwind
COPY package.json tailwind.config.js ./
RUN npm install
# Copy source code
COPY . .
# Build Tailwind CSS
RUN npx tailwindcss -i ./static/css/input.css -o ./static/css/output.css --minify
# Build the binary
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o caddyshack ./cmd/caddyshack
# Runtime stage
FROM alpine:3.19
WORKDIR /app
# Install ca-certificates for HTTPS requests
RUN apk add --no-cache ca-certificates tzdata
# Create non-root user
RUN adduser -D -g '' caddyshack
# Create data directory for database and other persistent data
RUN mkdir -p /data && chown caddyshack:caddyshack /data
# Copy binary from builder (templates and static files are embedded)
COPY --from=builder /app/caddyshack .
# Set ownership
RUN chown -R caddyshack:caddyshack /app
# Set default database path to /data
ENV CADDYSHACK_DB=/data/caddyshack.db
USER caddyshack
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
ENTRYPOINT ["./caddyshack"]