Skip to content

Commit

Permalink
chore: toy with xvfb-run (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladfrangu authored May 23, 2024
1 parent 0059192 commit ee3852a
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 12 deletions.
7 changes: 4 additions & 3 deletions node-playwright-chrome/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN \
# Disable chrome auto updates, based on https://support.google.com/chrome/a/answer/9052345
mkdir -p /etc/default && echo 'repo_add_once=false' > /etc/default/google-chrome \
&& apt-get update \
&& apt-get install -y wget gnupg unzip ca-certificates xvfb --no-install-recommends \
&& apt-get install -y wget gnupg unzip ca-certificates xvfb xauth --no-install-recommends \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& sh -c 'echo "deb http://ftp.us.debian.org/debian bookworm main non-free" >> /etc/apt/sources.list.d/fonts.list' \
Expand Down Expand Up @@ -59,7 +59,7 @@ WORKDIR /home/myuser
ENV PLAYWRIGHT_BROWSERS_PATH=/home/myuser/pw-browsers

# Copy source code and xvfb script
COPY --chown=myuser:myuser package.json main.js chrome_test.js start_xvfb_and_run_cmd.sh /home/myuser/
COPY --chown=myuser:myuser package.json main.js chrome_test.js start_xvfb_and_run_cmd.sh new_xvfb_run_cmd.sh /home/myuser/

# Sets path to Chrome executable, this is used by Apify.launchPuppeteer()
ENV APIFY_CHROME_EXECUTABLE_PATH=/usr/bin/google-chrome
Expand Down Expand Up @@ -110,4 +110,5 @@ ENV XVFB_WHD=1920x1080x24+32
# NOTEs:
# - This needs to be compatible with CLI.
# - Using CMD instead of ENTRYPOINT, to allow manual overriding
CMD ./start_xvfb_and_run_cmd.sh && npm start --silent
# CMD ./start_xvfb_and_run_cmd.sh && npm start --silent
CMD ./new_xvfb_run_cmd.sh npm start --silent
6 changes: 6 additions & 0 deletions node-playwright-chrome/new_xvfb_run_cmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# xvfb-run -a -s "-ac -screen 0 $XVFB_WHD -nolisten tcp" npm start --silent

echo "Will run command: xvfb-run -a -s \"-ac -screen 0 $XVFB_WHD -nolisten tcp\" $@"
xvfb-run -a -s "-ac -screen 0 $XVFB_WHD -nolisten tcp" "$@"
6 changes: 4 additions & 2 deletions node-playwright-firefox/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ RUN sh -c 'echo "deb http://ftp.us.debian.org/debian bookworm main non-free" >>
jq \
wget \
p11-kit \
xauth \
\
# Register cerificates
&& chmod +x ./register_intermediate_certs.sh \
Expand Down Expand Up @@ -52,7 +53,7 @@ ENV PLAYWRIGHT_BROWSERS_PATH=/home/myuser/pw-browsers
ENV CRAWLEE_SKIP_BROWSER_INSTALL=1

# Copy source code and xvfb script
COPY --chown=myuser:myuser package.json main.js firefox_test.js start_xvfb_and_run_cmd.sh /home/myuser/
COPY --chown=myuser:myuser package.json main.js firefox_test.js start_xvfb_and_run_cmd.sh new_xvfb_run_cmd.sh /home/myuser/

# Tell Node.js this is a production environemnt
ENV NODE_ENV=production
Expand Down Expand Up @@ -97,4 +98,5 @@ ENV XVFB_WHD=1920x1080x24+32
# NOTEs:
# - This needs to be compatible with CLI.
# - Using CMD instead of ENTRYPOINT, to allow manual overriding
CMD ./start_xvfb_and_run_cmd.sh && npm start --silent
# CMD ./start_xvfb_and_run_cmd.sh && npm start --silent
CMD ./new_xvfb_run_cmd.sh npm start --silent
6 changes: 6 additions & 0 deletions node-playwright-firefox/new_xvfb_run_cmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# xvfb-run -a -s "-ac -screen 0 $XVFB_WHD -nolisten tcp" npm start --silent

echo "Will run command: xvfb-run -a -s \"-ac -screen 0 $XVFB_WHD -nolisten tcp\" $@"
xvfb-run -a -s "-ac -screen 0 $XVFB_WHD -nolisten tcp" "$@"
6 changes: 4 additions & 2 deletions node-playwright-webkit/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RUN apt-get update \
git \
procps \
xvfb \
xauth \
# Install node
&& apt-get update && apt-get install -y curl \
&& curl -sL https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash - \
Expand Down Expand Up @@ -48,7 +49,7 @@ ENV PLAYWRIGHT_BROWSERS_PATH=/home/myuser/pw-browsers
ENV CRAWLEE_SKIP_BROWSER_INSTALL=1

# Copy source code and xvfb script
COPY --chown=myuser:myuser package.json main.js webkit_test.js start_xvfb_and_run_cmd.sh /home/myuser/
COPY --chown=myuser:myuser package.json main.js webkit_test.js start_xvfb_and_run_cmd.sh new_xvfb_run_cmd.sh /home/myuser/

# Tell Node.js this is a production environemnt
ENV NODE_ENV=production
Expand Down Expand Up @@ -87,4 +88,5 @@ ENV XVFB_WHD=1920x1080x24+32
# NOTEs:
# - This needs to be compatible with CLI.
# - Using CMD instead of ENTRYPOINT, to allow manual overriding
CMD ./start_xvfb_and_run_cmd.sh && npm start --silent
# CMD ./start_xvfb_and_run_cmd.sh && npm start --silent
CMD ./new_xvfb_run_cmd.sh npm start --silent
6 changes: 6 additions & 0 deletions node-playwright-webkit/new_xvfb_run_cmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# xvfb-run -a -s "-ac -screen 0 $XVFB_WHD -nolisten tcp" npm start --silent

echo "Will run command: xvfb-run -a -s \"-ac -screen 0 $XVFB_WHD -nolisten tcp\" $@"
xvfb-run -a -s "-ac -screen 0 $XVFB_WHD -nolisten tcp" "$@"
7 changes: 4 additions & 3 deletions node-playwright/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ COPY ./register_intermediate_certs.sh ./register_intermediate_certs.sh

# Install libs
RUN apt-get update \
&& apt-get install --fix-missing -yq --no-install-recommends procps xvfb wget \
&& apt-get install --fix-missing -yq --no-install-recommends procps xvfb xauth wget \
&& mkdir -p /tmp/.X11-unix && chmod 1777 /tmp/.X11-unix \
# Uninstall system NodeJs
&& apt-get purge -yq nodejs \
Expand Down Expand Up @@ -65,7 +65,7 @@ ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
ENV CRAWLEE_SKIP_BROWSER_INSTALL=1

# Copy source code and xvfb script
COPY --chown=myuser:myuser package.json main.js chrome_test.js start_xvfb_and_run_cmd.sh /home/myuser/
COPY --chown=myuser:myuser package.json main.js chrome_test.js start_xvfb_and_run_cmd.sh new_xvfb_run_cmd.sh /home/myuser/

# Sets path to Chrome executable, this is used by Apify.launchPuppeteer()
ENV APIFY_CHROME_EXECUTABLE_PATH=/usr/bin/google-chrome
Expand Down Expand Up @@ -105,4 +105,5 @@ ENV XVFB_WHD=1920x1080x24+32
# NOTEs:
# - This needs to be compatible with CLI.
# - Using CMD instead of ENTRYPOINT, to allow manual overriding
CMD ./start_xvfb_and_run_cmd.sh && npm start --silent
# CMD ./start_xvfb_and_run_cmd.sh && npm start --silent
CMD ./new_xvfb_run_cmd.sh npm start --silent
6 changes: 6 additions & 0 deletions node-playwright/new_xvfb_run_cmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# xvfb-run -a -s "-ac -screen 0 $XVFB_WHD -nolisten tcp" npm start --silent

echo "Will run command: xvfb-run -a -s \"-ac -screen 0 $XVFB_WHD -nolisten tcp\" $@"
xvfb-run -a -s "-ac -screen 0 $XVFB_WHD -nolisten tcp" "$@"
6 changes: 4 additions & 2 deletions node-puppeteer-chrome/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ RUN apt-get update \
procps \
xdg-utils \
xvfb \
xauth \
--no-install-recommends \
# Disable chrome auto updates, based on https://support.google.com/chrome/a/answer/9052345
&& mkdir -p /etc/default && echo 'repo_add_once=false' > /etc/default/google-chrome \
Expand Down Expand Up @@ -61,7 +62,7 @@ USER myuser
WORKDIR /home/myuser

# Copy source code and xvfb script
COPY --chown=myuser:myuser package.json main.js puppeteer_*.js start_xvfb_and_run_cmd.sh /home/myuser/
COPY --chown=myuser:myuser package.json main.js puppeteer_*.js start_xvfb_and_run_cmd.sh new_xvfb_run_cmd.sh /home/myuser/

# Uncomment to skip the chromium download when installing puppeteer. If you do,
# you'll need to launch puppeteer with:
Expand Down Expand Up @@ -102,4 +103,5 @@ ENV XVFB_WHD=1920x1080x24+32
# NOTEs:
# - This needs to be compatible with CLI.
# - Using CMD instead of ENTRYPOINT, to allow manual overriding
CMD ./start_xvfb_and_run_cmd.sh && npm start --silent
# CMD ./start_xvfb_and_run_cmd.sh && npm start --silent
CMD ./new_xvfb_run_cmd.sh npm start --silent
6 changes: 6 additions & 0 deletions node-puppeteer-chrome/new_xvfb_run_cmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# xvfb-run -a -s "-ac -screen 0 $XVFB_WHD -nolisten tcp" npm start --silent

echo "Will run command: xvfb-run -a -s \"-ac -screen 0 $XVFB_WHD -nolisten tcp\" $@"
xvfb-run -a -s "-ac -screen 0 $XVFB_WHD -nolisten tcp" "$@"

0 comments on commit ee3852a

Please sign in to comment.