diff --git a/Dockerfile.alpine b/Dockerfile.alpine new file mode 100644 index 0000000..35650fd --- /dev/null +++ b/Dockerfile.alpine @@ -0,0 +1,70 @@ +FROM node:16-alpine + +# Configure Xvfb via environment variables: +ENV SCREEN_WIDTH 1440 +ENV SCREEN_HEIGHT 900 +ENV SCREEN_DEPTH 24 +ENV DISPLAY :60 + +# Configure VNC via environment variables: +ENV VNC_ENABLED true +ENV VNC_PASSWORD secret +ENV VNC_PORT 5900 +ENV NOVNC_PORT 6080 +EXPOSE 5900 +EXPOSE 6080 + +ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true +ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD true +ENV PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium-browser + +# Installs latest Chromium package. +RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories \ + && echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \ + && echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \ + && echo "http://dl-cdn.alpinelinux.org/alpine/v3.12/main" >> /etc/apk/repositories \ + && apk upgrade -U -a \ + && apk add --no-cache \ + libstdc++ \ + chromium \ + harfbuzz \ + nss \ + freetype \ + ttf-freefont \ + font-noto-emoji \ + wqy-zenhei +RUN apk add --no-cache \ + tini \ + xvfb \ + x11vnc \ + novnc + +COPY ./docker/local.conf /etc/fonts/local.conf + +# Shell scripts +ENV NOVNC_HOME /usr/share/novnc +COPY ./docker/entrypoint.sh /usr/local/bin/entrypoint +COPY ./docker/vnc-start.sh /usr/local/bin/vnc-start +RUN chmod +x /usr/local/bin/entrypoint \ + && chmod +x /usr/local/bin/vnc-start \ + && ln -s "$NOVNC_HOME/vnc.html" "$NOVNC_HOME/index.html" + +# Add Chrome as a user +RUN mkdir -p /fgc \ + && adduser -D chrome \ + && chown -R chrome:chrome /fgc +# Run app as non-privileged +USER chrome +WORKDIR /fgc + +# Install Playwright +COPY --chown=chrome package.json package-lock.json ./ +RUN npm install +RUN npx playwright install chromium +COPY --chown=chrome . ./ + +ENV CHROME_BIN=/usr/bin/chromium-browser \ + CHROME_PATH=/usr/lib/chromium/ + +ENTRYPOINT [ "entrypoint" ] +CMD ["node", "epic-games.js"] \ No newline at end of file diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index aebe085..54b164b 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -9,6 +9,9 @@ Xvfb "$DISPLAY" -ac -screen 0 "${SCREEN_WIDTH}x${SCREEN_HEIGHT}x${SCREEN_DEPTH}" >/dev/null 2>&1 & if [ "$VNC_ENABLED" = true ]; then + echo "Starting VNC server..." + # wait for Xvfb to start up + sleep 3 vnc-start >/dev/null 2>&1 & fi diff --git a/docker/local.conf b/docker/local.conf new file mode 100644 index 0000000..ed6c08b --- /dev/null +++ b/docker/local.conf @@ -0,0 +1,31 @@ + + + + + + sans-serif + + Main sans-serif font name goes here + Noto Color Emoji + Noto Emoji + + + + + serif + + Main serif font name goes here + Noto Color Emoji + Noto Emoji + + + + + monospace + + Main monospace font name goes here + Noto Color Emoji + Noto Emoji + + + \ No newline at end of file diff --git a/docker/vnc-start.sh b/docker/vnc-start.sh index 92423ea..e33ce78 100755 --- a/docker/vnc-start.sh +++ b/docker/vnc-start.sh @@ -1,10 +1,10 @@ #!/bin/sh - +set -e # Start VNC in a background process: x11vnc -display "$DISPLAY" -forever -shared -rfbport "${VNC_PORT:-5900}" \ -passwd "${VNC_PASSWORD:-secret}" -bg NOVNC_HOME=/usr/share/novnc -ln -s $NOVNC_HOME/vnc_auto.html $NOVNC_HOME/index.html +# ln -s $NOVNC_HOME/vnc_auto.html $NOVNC_HOME/index.html websockify -D --web "$NOVNC_HOME" "$NOVNC_PORT" "localhost:$VNC_PORT" & # Execute the given command: diff --git a/epic-games.js b/epic-games.js index 1c9e975..198c251 100644 --- a/epic-games.js +++ b/epic-games.js @@ -6,7 +6,7 @@ const debug = process.env.PWDEBUG == '1'; // runs non-headless and opens https:/ const URL_CLAIM = 'https://store.epicgames.com/en-US/free-games'; const URL_LOGIN = 'https://www.epicgames.com/id/login?lang=en-US&noHostRedirect=true&redirectUrl=' + URL_CLAIM; const TIMEOUT = 20 * 1000; // 20s, default is 30s -const SCREEN_WIDTH = Number(process.env.SCREEN_WIDTH) - 80 || 1280; +const SCREEN_WIDTH = Number(process.env.SCREEN_WIDTH) - 50 || 1280; const SCREEN_HEIGHT = Number(process.env.SCREEN_HEIGHT) || 1280; // https://playwright.dev/docs/auth#multi-factor-authentication @@ -17,6 +17,7 @@ const context = await chromium.launchPersistentContext(path.resolve(__dirname, ' viewport: { width: SCREEN_WIDTH, height: SCREEN_HEIGHT }, userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.83 Safari/537.36', // see replace of Headless in util.newStealthContext. TODO update if browser is updated! locale: "en-US", // ignore OS locale to be sure to have english text for locators + executablePath: "/usr/bin/chromium-browser", args: [ // don't want to see bubble 'Restore pages? Chrome didn't shut down correctly.', but flags below don't work. '--disable-session-crashed-bubble', '--restore-last-session',