Skip to content

feat(sully): prepare scully for running inside Docker container#109

Merged
SanderElias merged 1 commit intoscullyio:masterfrom
beeman:beeman/scully-in-docker
Jan 1, 2020
Merged

feat(sully): prepare scully for running inside Docker container#109
SanderElias merged 1 commit intoscullyio:masterfrom
beeman:beeman/scully-in-docker

Conversation

@beeman
Copy link
Copy Markdown
Contributor

@beeman beeman commented Dec 28, 2019

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Other... Please describe:

What is the current behavior?

Currently when running scully in a Docker container it fails with an error message similar to this:

Error: Failed to launch chrome! spawn /workspace/node_modules/puppeteer/.local-chromium/linux-706915/chrome-linux/chrome ENOENT

What is the new behavior?

This PR adds the option to instruct Scully to use an existing chromium as executable, allowing it to run inside a Docker container.

It introduces support for the SCULLY_PUPPETEER_EXECUTABLE_PATH env var, if this is found it uses it's value as the executablePath for Puppeteer.

This allows for running Scully with a prepared Docker image, like beeman/scully-docker.

After this patch, scully uses the browser that's pre-installed in the images and runs perfectly fine!

$ scully
Launching puppeteer with executablePath /usr/bin/chromium-browser
The option outFolder isn't configured, using default folder "/workspace/dist/static/".
Cleaned up /workspace/dist/static/ folder.
 ☺   new Angular build imported
started servers in background
servers available
Finding all routes in application.
Pull in data to create additional routes.
Finding files in folder "/workspace/blog"
Route list created in files:
      src/assets/scully-routes.json
      /workspace/dist/static/assets/scully-routes.json
Route "" rendered into file: "/workspace/dist/static/index.html"
Route "/blog/12-24-2019-blog" rendered into file: "/workspace/dist/static/blog/12-24-2019-blog/index.html"
Route "/about" rendered into file: "/workspace/dist/static/about/index.html"
Route list created in files:
      src/assets/scully-routes.json
      /workspace/dist/static/assets/scully-routes.json

Generating took 10.23 seconds for 3 pages:
  That is 0.3 pages per second,
  or 3412 milliseconds for each page.

Done in 21.09s.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Most of the information to build this feature comes from here.

@claassistantio
Copy link
Copy Markdown

claassistantio commented Dec 28, 2019

CLA assistant check
All committers have signed the CLA.

@beeman beeman marked this pull request as ready for review December 29, 2019 18:12
@aaronfrost
Copy link
Copy Markdown
Contributor

@beeman Can you please describe what the puppeteer options you added do to make this better prepared for Docker? I believe you but I want to learn what is going on in this PR.

@beeman
Copy link
Copy Markdown
Contributor Author

beeman commented Dec 30, 2019

@aaronfrost on our dev machines when installing puppeteer from npm it will download a recent version of Chromium. While this works great on most workstations, there are a situations (like CI or Docker) where Puppeteer can not download the right version.

Take for instance a Docker images that's based on Alpine. In that case the solution is to prepare the Docker image and install chromium using that OS' package manager, and instruct Puppeteer to not download it (by setting the env var PUPPETEER_SKIP_CHROMIUM_DOWNLOAD to true) and point it to the locally installed chromium binary using the executablePath parameter when launching Puppeteer.

With this PR we can instruct Puppeteer that we want to change the executablePath and additionally when that's the case we add the argument --disable-dev-shm-usage as explained here.

In this case I prepared a Docker image to include Chromium like this, and instruct it not to download Puppeteer when installed from npm:

FROM node:12-alpine

RUN apk add --no-cache \
      chromium \
      nss \
      freetype \
      freetype-dev \
      harfbuzz \
      ca-certificates \
      ttf-freefont

ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true

In order to use this I create my projects' Docker file like this:

FROM beeman/scully-docker:latest
ENV SCULLY_PUPPETEER_EXECUTABLE_PATH '/usr/bin/chromium-browser'
... more docker stuff here
... and eventually run Scully:
RUN yarn scully

Happy to elaborate more if needed!

@aaronfrost
Copy link
Copy Markdown
Contributor

@beeman we need to update the commit when we get this merged. The commit says "feat(sully)" when it should have a C and say "feat(s__c__ully)".

Copy link
Copy Markdown
Contributor

@SanderElias SanderElias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM,

I will merge when the conflicts are resolved.

@beeman beeman force-pushed the beeman/scully-in-docker branch from 023a114 to 1e25d52 Compare December 31, 2019 20:36
@beeman beeman requested a review from SanderElias December 31, 2019 20:37
@beeman
Copy link
Copy Markdown
Contributor Author

beeman commented Dec 31, 2019

@aaronfrost commit message is renamed
@SanderElias conflicts are resolved

@SanderElias SanderElias merged commit b319db3 into scullyio:master Jan 1, 2020
@beeman beeman deleted the beeman/scully-in-docker branch January 1, 2020 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants