GithubHelp home page GithubHelp logo

entrptaher / playground-puppeteer-xvfb Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 10 KB

Example of how you can run puppeteer on server with xvfb, docker and so on

Dockerfile 27.33% JavaScript 54.93% Shell 17.74%
puppeteer docker nodejs xvfb hacktoberfest

playground-puppeteer-xvfb's Introduction

PS: Check https://github.com/entrptaher/puppeteer-xvfb/tree/direct-script For running script directly instead of PM2 and/or Docker.

Overview

Assuming we are going to use digitalocean for hosting, we will install a one click app, it should be either Docker or NodeJS. That way we don't have to worry about installing them manually.

Make sure you have docker installed and running, after that, we have a docker file Dockerfile which we can use to deploy our app anywhere. The docker file is commented out with proper code, you can read it to know what is happenening behind the scene.

This is a very big topic to cover, so I'll link to related resources instead to discuss everything here, If you don't know what is docker or nodejs,

Here are some crash courses that will make you up and running,

Here are some videos about deploying an app on digitalocean,

If you want to know how to install docker or nodejs manually, here are some guides for that,

Preparation

So the instructions right now are pretty straightforward,

  • Clone the repo, or upload it to server.
    • Run Dockerfile which will do the rest of the work.
    • OR, Run everything manually with nodejs and pm2

PM2 Process Manager

  • Install nodejs from above guide,

  • Check the dockerfile and install the dependencies with apt-get commands.

  • Install pm2 which will take care of concurrency and fallback problems. It will run Xvfb for you, with a fake display, so headless:false can be run perfectly. There are some dependencies needed, check the dockerfile for those.

  • You can install it using npm i -g pm2,

  • Install all node dependencies npm install,

  • and then run with pm2 start process.json on this folder.

Running the docker

You need to build the docker image/container every time you want to run the script, Make sure to remove the container before building another one. I cannot go over all commands, but here are some basic commands to get you going.

# Stop all running containers
docker stop $(docker ps -aq)

# Remove all containers
docker rm $(docker ps -aq)

# build the docker and give it a name
docker build -t myapp . 

Now that we built it, we can run it various ways, make sure to run only one of the following commands,

# start the container, expose to network and restart on fail, 
# if you exit terminal, it will run on background
docker run --network=host --restart always -it myapp

# start the container, expose to network and remove on successful run, 
# also if you exit terminal, it will stop and remove container
docker run --network=host --rm -it myapp

# starts the container, expose to network
# runs on background as daemon, won't show anything on terminal
docker run --network=host --restart always -d myapp

playground-puppeteer-xvfb's People

Contributors

entrptaher avatar

Stargazers

 avatar  avatar

Watchers

 avatar

playground-puppeteer-xvfb's Issues

**Cards**

Cards can be added to your board to track the progress of issues and pull requests. You can also add note cards, like this one!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.