puphpeteer icon indicating copy to clipboard operation
puphpeteer copied to clipboard

Create a Docker image to run PuPHPeteer

Open nesk opened this issue 4 years ago • 7 comments

Sometimes we have weird issues due to the different environments of our users: #114 #84 #65

Debugging those environments is a real pain. What we could do is provide an official Docker image for PuPHPeteer (in a new repository). There are already some unofficial images but by providing our own image we would ensure to have better control on the final environments.

The image should extend the official PHP image to allow users to easily setup their environments. See the official Puppeteer Dockerfile to get all the requirements to run Chromium inside the container.

nesk avatar Oct 31 '20 16:10 nesk

That's a great idea to keep things managable. Reconstructing issues is often a pain I noticed.

spekulatius avatar Oct 31 '20 16:10 spekulatius

Let me explain what I was thinking about.

Creating an image suited to PuPHPeteer is not really a complex work, all we have to do is write a Dockerfile using the PHP image as a base. Next, we need to install Node and apply the requirements described in Puppeteer's documentation.

The whole "install Node and apply the requirements" part can be done in a simple shell script, which we can be run in any Dockerfile inheriting the official PHP image (we might support more, but it will be another future step).

Using a simple shell script to do the setup has two benefits:

  • We can create a Github Action which will generate and publish multiple tags of the PHP image, with all the requirements to run PuPHPeteer. For example, we could support the tags php:<version>, php:<version>-cli, php:<version>-apache, php:<version>-fpm, for all the maintained versions of PHP. Those images will be easy to use for our users, they just have to pull them and everything is ready!
  • If a user has more specific needs, he can write its own Dockerfile and run the script in it to make the image compliant with PuPHPeteer.

nesk avatar Nov 08 '20 16:11 nesk

I can add that while creating unofficial image for PuPHPeter I noticed that there are some important options which are required to pass, otherwise it does not work inside docker. Hope it can help someone to save some time. The options are the following:

$browser   = $puppeteer->launch(
	[
		'args' =>
			[
				// this is required for dockerized puppeteer
				'--no-sandbox',
				'--disable-setuid-sandbox',
				'--disable-dev-shm-usage',
			],
	]
);

ivastly avatar Nov 08 '20 17:11 ivastly

It seems like this is handled by the user they add in their Dockerfile:

# Install puppeteer so it's available in the container.
RUN npm i puppeteer \
    # Add user so we don't need --no-sandbox.
    # same layer as npm install to keep re-chowned files from using up several hundred MBs more space
    && groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
    && mkdir -p /home/pptruser/Downloads \
    && chown -R pptruser:pptruser /home/pptruser \
    && chown -R pptruser:pptruser /node_modules

nesk avatar Nov 08 '20 17:11 nesk

Hello @nesk I can pick this up if no-one is working on it atm.

I have just seen this repo https://github.com/spekulatius/puphpeteer-docker

I assume @spekulatius started working on it :smiley:

tugrulcan avatar Dec 03 '20 08:12 tugrulcan

Thank you, that's kind from you 🙂

@spekulatius is already working on it, but we might need some people to test everything and tell us what they think about the available images. For the moment, its very WIP, let me tell you once we have something more stable. 😉

nesk avatar Dec 03 '20 09:12 nesk

Hey @tugrulcan,

Yeah, as you discovered I've made a start on this :) @nesk and myself are still working out the details atm. Keen to hear your feedback on the approach once it's a bit more developed.

Peter

spekulatius avatar Dec 03 '20 09:12 spekulatius