FROM mcr.microsoft.com/playwright:v1.60.0

WORKDIR /app

# Install Node 22+ if not present (Playwright image may have an older Node)
RUN apt-get update && apt-get install -y curl && \
    curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
    apt-get install -y nodejs && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

COPY package.json package-lock.json ./
RUN npm ci

COPY . .
RUN npx playwright install chromium

# Default to headless; override with --env HEADFUL=1 and mount X11 socket or use VNC
ENV NODE_ENV=production
ENV ARCHIVE_PATH=/archives

VOLUME ["/archives"]

ENTRYPOINT ["node", "src/cli.mjs"]
