Per plan §11.1, the index builder reads PostgreSQL and generates all JSON index files for Cloudflare Pages deployment: - main.go: Build cycle orchestration with configurable timeout, self-restart - config.go: Environment-based configuration with sensible defaults - db.go: PostgreSQL data fetching for bots, matches, series, seasons, predictions - generator.go: JSON index generation (leaderboard, bots, matches, playlists) - deploy.go: Cloudflare Pages deployment via wrangler, R2 warm cache pruning - Dockerfile: Multi-stage build with Go + Node.js + wrangler CLI - main_test.go: Tests for config, index generation, playlists Index builder runs on 15-minute cycles, deploys to Pages every ~90 minutes, and prunes R2 warm cache weekly to stay within 10GB free tier. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
48 lines
1 KiB
Docker
48 lines
1 KiB
Docker
# Build stage
|
|
FROM golang:1.23-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Install build dependencies
|
|
RUN apk add --no-cache git ca-certificates tzdata
|
|
|
|
# Copy go mod files
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build the binary
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /acb-index-builder ./cmd/acb-index-builder
|
|
|
|
# Runtime stage
|
|
FROM node:22-alpine
|
|
|
|
# Install wrangler CLI for Cloudflare Pages deployment
|
|
RUN npm install -g wrangler@3
|
|
|
|
# Install ca-certificates for HTTPS calls
|
|
RUN apk add --no-cache ca-certificates tzdata
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy binary from builder
|
|
COPY --from=builder /acb-index-builder /usr/local/bin/acb-index-builder
|
|
|
|
# Create data directory
|
|
RUN mkdir -p /data
|
|
|
|
# Set environment defaults
|
|
ENV ACB_OUTPUT_DIR=/data
|
|
ENV ACB_BUILD_INTERVAL=15m
|
|
ENV ACB_DEPLOY_INTERVAL=6
|
|
ENV ACB_MAX_LIFETIME=4h
|
|
ENV ACB_BUILD_TIMEOUT=10m
|
|
|
|
# Run as non-root user
|
|
RUN addgroup -g 1000 acb && adduser -u 1000 -G acb -s /bin/sh -D acb
|
|
RUN chown -R acb:acb /data
|
|
USER acb
|
|
|
|
ENTRYPOINT ["/usr/local/bin/acb-index-builder"]
|