diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4aab1a2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.git* +Dockerfile* +Containerfile* +.dockerignore +.pre-commit* +docker-compose.yml +venv* diff --git a/Containerfile b/Containerfile index 61c96d0..8988e3c 100644 --- a/Containerfile +++ b/Containerfile @@ -1,10 +1,22 @@ -FROM buildkite/puppeteer +FROM node:bookworm-slim -WORKDIR . +# We don't need the standalone Chromium +ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true +ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y awscli curl +# Install Google Chrome Stable and fonts +# Note: this installs the necessary libs to make the browser work with Puppeteer. +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked apt-get update \ + && apt-get install -y gnupg wget awscli curl \ + && wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg \ + && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \ + && apt-get update && apt-get install google-chrome-stable -y --no-install-recommends \ + && rm -rf /var/lib/apt/lists/* -COPY grafana_pdf.js grafana_pdf_exporter.sh sendgridSendEmail.sh ./ +USER node +WORKDIR /app + +COPY --chown=node:node . . # just run the container doing nothing ENTRYPOINT ["sh", "-c", "sleep infinity"] diff --git a/grafana_pdf.js b/grafana_pdf.js index 15b15d8..320016b 100644 --- a/grafana_pdf.js +++ b/grafana_pdf.js @@ -24,7 +24,15 @@ const width_px = 1200; const auth_header = 'Basic ' + new Buffer.from(auth_string).toString('base64'); (async() => { - const browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']}) + const browser = await puppeteer.launch({ + args: [ + '--no-sandbox', + '--disable-setuid-sandbox', + '--disable-dev-shm-usage', + '--disable-gpu', + ], + executablePath: '/usr/bin/google-chrome', + }); const page = await browser.newPage(); // Set basic auth headers