-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
86 lines (69 loc) · 2.66 KB
/
Dockerfile
File metadata and controls
86 lines (69 loc) · 2.66 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
76
77
78
79
80
81
82
83
84
85
86
# syntax=docker/dockerfile:1
# =============================================================================
# Builder Stage
# =============================================================================
# Pin Go version and Alpine variant explicitly for reproducible builds
# To fully pin, add digest: golang:1.24-alpine3.21@sha256:<digest>
FROM golang:1.25-alpine3.23 AS builder
# Install build dependencies for CGO (required by go-sqlite3)
# Note: go-sqlite3 bundles SQLite source, no need for sqlite-dev
RUN apk add --no-cache \
gcc \
musl-dev
WORKDIR /src
# Cache dependencies - copy go.mod/sum first for better layer caching
COPY go.mod go.sum ./
RUN go mod download && go mod verify
# Copy source code
COPY . .
# Build the binary with CGO enabled (required for go-sqlite3)
# Flags:
# -tags sqlite_omit_load_extension: security hardening, disable extension loading
# -ldflags="-s -w": strip debug info and symbol table
# -extldflags '-static': fully static binary (no runtime deps)
# -trimpath: remove file system paths for reproducibility
RUN CGO_ENABLED=1 GOOS=linux \
go build \
-tags sqlite_omit_load_extension \
-ldflags="-s -w -extldflags '-static'" \
-trimpath \
-o /bin/lightd \
./cmd/lightd
# =============================================================================
# Runtime Stage
# =============================================================================
# Using Alpine for tzdata and ca-certificates
# Binary is fully static, no runtime libs needed
FROM alpine:3.23
# Installations
# - ca-certificates: HTTPS connections
# - tzdata: timezone support for scheduler
# - curl: healthcheck
RUN apk add --no-cache \
ca-certificates \
tzdata \
curl
# Create non-root user for security
RUN addgroup -g 1000 lightd && \
adduser -u 1000 -G lightd -s /bin/sh -D lightd
WORKDIR /app
# Copy binary from builder
COPY --from=builder /bin/lightd /usr/local/bin/lightd
# Create directory structure:
# /app/data - SQLite database (mount as volume for persistence)
# /app/config - config.yaml and lua scripts (mount to customize)
RUN mkdir -p /app/data /app/config && chown -R lightd:lightd /app
# Copy default config (env-variable driven)
COPY --chown=lightd:lightd config.docker.yaml /app/config/config.yaml
# Switch to non-root user
USER lightd
# Expose ports
# 8080 - Webhook events
# 9090 - Health check
EXPOSE 8080 9090
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -sf http://localhost:9090/health || exit 1
# Run the application with default config path
# Override with: docker run lightd -c /path/to/config.yaml
ENTRYPOINT ["lightd", "-c", "/app/config/config.yaml"]