# ── Build stage ──────────────────────────────────────────────────────────────── FROM golang:1.25-alpine AS builder WORKDIR /build # Cache dependency downloads separately from source compilation. COPY go.mod go.sum ./ RUN go mod download COPY . . RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ go build -ldflags="-s -w" -o /scraper ./cmd/scraper # ── Runtime stage ────────────────────────────────────────────────────────────── # Use node:22-alpine so single-file-cli (npm package) runs natively without # any glibc shims. The pre-compiled binary release requires glibc symbols # (e.g. __res_init) that Alpine's gcompat shim does not provide. FROM node:22-alpine # ca-certificates: HTTPS to novelfire.net # tzdata: timezone data RUN apk add --no-cache ca-certificates tzdata # Install single-file-cli as a global npm package. # It runs via Node.js (no Deno/glibc needed) and connects to an external # Chromium via the CDP --browser-server flag. RUN npm install -g single-file-cli WORKDIR /app COPY --from=builder /scraper /app/scraper # Create the default static output directory. RUN mkdir -p /app/static/books # Non-root user. RUN addgroup -S scraper && adduser -S scraper -G scraper RUN chown -R scraper:scraper /app USER scraper # ── Configuration ───────────────────────────────────────────────────────────── ENV BROWSERLESS_URL=http://browserless:3030 ENV BROWSERLESS_STRATEGY=content ENV SCRAPER_WORKERS=0 ENV SCRAPER_STATIC_ROOT=/app/static/books ENV SCRAPER_HTTP_ADDR=:8080 ENV SINGLEFILE_PATH=single-file EXPOSE 8080 # Default: run as an HTTP server. Override CMD to use "run" for one-shot. ENTRYPOINT ["/app/scraper"] CMD ["serve"]