fix(scraper): replace glibc binary with npm single-file-cli on node:22-alpine

The pre-compiled single-file binary requires glibc symbols (__res_init)
that Alpine's gcompat shim does not provide, causing exit status 127.
Switch runtime base to node:22-alpine and install single-file-cli via npm.
Also add .dockerignore to exclude bin/ and static/ from build context.
This commit is contained in:
Admin
2026-03-04 12:54:51 +05:00
parent 555973c053
commit 5a7751e6d1
2 changed files with 16 additions and 18 deletions

4
scraper/.dockerignore Normal file
View File

@@ -0,0 +1,4 @@
bin/
static/
*.md
.git

View File

@@ -12,30 +12,24 @@ COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
go build -ldflags="-s -w" -o /scraper ./cmd/scraper
# ── single-file binary stage ───────────────────────────────────────────────────
# Download the official pre-compiled single-file-cli binary (Deno-compiled,
# statically linked for Linux x86_64 glibc). We pin to a specific version so
# image builds are reproducible; bump this ARG to upgrade.
FROM alpine:3.20 AS singlefile-downloader
ARG SINGLEFILE_VERSION=2.0.83
RUN apk add --no-cache wget ca-certificates && \
wget -q -O /single-file \
"https://github.com/gildas-lormeau/single-file-cli/releases/download/v${SINGLEFILE_VERSION}/single-file-x86_64-linux" && \
chmod +x /single-file
# ── Runtime stage ──────────────────────────────────────────────────────────────
FROM alpine:3.20
# 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
# gcompat: glibc compatibility shim so the glibc-linked single-file binary
# runs on musl/Alpine without needing a full glibc image.
# libstdc++: required by the Deno runtime embedded in single-file
RUN apk add --no-cache ca-certificates tzdata gcompat libstdc++
# 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
COPY --from=singlefile-downloader /single-file /usr/local/bin/single-file
# Create the default static output directory.
RUN mkdir -p /app/static/books
@@ -51,7 +45,7 @@ ENV BROWSERLESS_STRATEGY=content
ENV SCRAPER_WORKERS=0
ENV SCRAPER_STATIC_ROOT=/app/static/books
ENV SCRAPER_HTTP_ADDR=:8080
ENV SINGLEFILE_PATH=/usr/local/bin/single-file
ENV SINGLEFILE_PATH=single-file
EXPOSE 8080