FROM node:24

RUN apt update -y && apt upgrade -y

RUN useradd -ms /bin/bash ctf

RUN apt install -y wget gnupg ca-certificates fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils

# Install necessary dependencies for Puppeteer and Chromium
RUN apt install -y --no-install-recommends libdrm2 libu2f-udev libxshmfence1 libglu1-mesa chromium && apt-get clean && rm -rf /var/lib/apt/lists/*

# Puppeteer setup: Skip Chromium download and use the installed Chromium
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
ENV PUPPETEER_EXECUTABLE_PATH="/usr/bin/chromium"

# Install your app here...
WORKDIR /app/

COPY source .

RUN mkdir database

RUN npm i

RUN chown -R root:root /app && chmod -R 555 /app
RUN chown -R ctf:ctf /app/database && chmod -R 700 /app/database

USER ctf

CMD npm run prod
