Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using headless Chrome Puppeteer with meteor and mup (Error) #981

Open
Twisterking opened this issue Jul 18, 2018 · 18 comments
Open

Using headless Chrome Puppeteer with meteor and mup (Error) #981

Twisterking opened this issue Jul 18, 2018 · 18 comments
Labels

Comments

@Twisterking
Copy link
Contributor

Mup version (mup --version): 1.4.5

So I am running into an error with my deployed Meteor app:

/built_app/programs/server/npm/node_modules/puppeteer/.local-chromium/linux-571375/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory

I am 90% sure, that this is just due to some missing libs inside the abernix/meteord:node-8-base docker container? Any ideas on this?

Do I have to make my own docker container with some more libs installed? (see here: puppeteer/puppeteer#404 - apt-get install libpangocairo-1.0-0 libx11-xcb1 libxcomposite1 libxcursor1 libxdamage1 libxi6 libxtst6 libnss3 libcups2 libxss1 libxrandr2 libgconf2-4 libasound2 libatk1.0-0 libgtk-3-0).

Or is there some way around this?

@zodern
Copy link
Owner

zodern commented Jul 20, 2018

Mup is able to customize the docker container: http://meteor-up.com/docs#customize-docker-image. You could use that to install the apt-get packages.

@adamjgriffith
Copy link

Im trying to figure this out as well.

I have successfully used buildInstructions to apt-get install the required dependencies. However a runaway amount of Chrome processes are created. The solution recommended by Puppeteer is to add these instructions to your docker file.

https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#running-puppeteer-in-docker

But I cant figure out if these commands are possible with meteor-up especially the last 4.

Could you provide any assistance?

@Twisterking
Copy link
Contributor Author

Not sure if this is of any help to you but I ended up using pm2-meteor for my worker as I don't need docker there - using my PR.

@IDCOLL
Copy link

IDCOLL commented Feb 19, 2019

Im trying to figure this out as well.

I have successfully used buildInstructions to apt-get install the required dependencies. However a runaway amount of Chrome processes are created. The solution recommended by Puppeteer is to add these instructions to your docker file.

https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#running-puppeteer-in-docker

But I cant figure out if these commands are possible with meteor-up especially the last 4.

Could you provide any assistance?

Has anybody been able to successfully get Puppeteer working with mup?

@nabiltntn
Copy link

Hi @IDCOLL ,
I have build 2 custom docker images based on meteord with 8.11.2 node version
https://hub.docker.com/r/nabiltntn/meteord-node-with-chromium/tags

8.11.2_dumb-init starts the application with dumb-init to avoid having plenty of zombies process after browser execution.

@IDCOLL
Copy link

IDCOLL commented Feb 19, 2019

Hi @IDCOLL ,
I have build 2 custom docker images based on meteord with 8.11.2 node version
https://hub.docker.com/r/nabiltntn/meteord-node-with-chromium/tags

8.11.2_dumb-init starts the application with dumb-init to avoid having plenty of zombies process after browser execution.

Thank you for the quick reply.
Do I just reference that docker image in my MUP file i.e. or do I need to do add some instructions to the build Instructions also?

Also is the image compatible with Meteor 1.6+

docker: {
image: '8.11.2_dumb-init',
buildInstructions: [
'RUN apt-get update && apt-get install -y imagemagick'
]
}

@nabiltntn
Copy link

You need to change the image. No addtional build instructions.

Meteor 1.6 is compatible with Node 8, so it should work fine.

@IDCOLL
Copy link

IDCOLL commented Feb 19, 2019

Thanks @nabiltntn it worked.

I had to make a small adjustment in my puppeteer code:
await puppeteer.launch({headless: true, args:['--no-sandbox']})
The --no-sandbox argument is critical otherwise PUPPETEER will give the following error:

Exception while invoking method 'createXreport' Error: Failed to launch chrome!
[82.196.3.225][0219/140956.079200:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

@nabiltntn
Copy link

Yes i usally use :

const browser = await puppeteer.launch({
      args: [
        '--no-sandbox',
        '--disable-setuid-sandbox',
        '--disable-webgl',
        '--disable-accelerated-2d-canvas',
        '--disable-gpu'
      ]
    });

@wildhart
Copy link

wildhart commented Nov 1, 2019

Hi @nabiltntn, thank you very much for your docker images with Chromium!

I've used them to automate production of pre-rendered landing pages with in-line critical css. See my post in the Meteor forums: https://forums.meteor.com/t/pre-rendered-landing-pages-with-critical-css/50626

Using Meteor 1.8.1

@nabiltntn
Copy link

@wildhart thanks for the reference

@johannel00
Copy link

Hi @nabiltntn, thank you for your the previous docker images that you've provided. I recently upgraded my Meteor project to 1.9. Can you help or explain/direct to me how I can create a custom docker image based on meteord with 12.14.0 node version.

@nabiltntn
Copy link

Unfortunately, I don't have anymore the docker file I have used to build the image but I tried to recreate it again for node 12 using image layers from Dockerhub

Could you try to build the following Dockerfile

FROM meteord:node-12.14.0-base

RUN apt-get update \
    && apt-get install -y \
    libpangocairo-1.0-0 \
    libx11-xcb1 \
    libxcomposite1 \
    libxcursor1 \
    libxdamage1 \
    libxi6 \
    libxtst6 \
    libnss3 \
    libcups2 \
    libxss1 \
    libxrandr2 \
    libgconf2-4 \
    libasound2 \
    libatk1.0-0 \
    libgtk-3-0 \
    wget \
    --no-install-recommends \
    && rm -rf /var/lib/apt/lists/* \
    && rm -rf /src/*.deb

RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.2/dumb-init_1.2.2_amd64

RUN chmod +x /usr/local/bin/dumb-init

ENTRYPOINT ["/bin/bash" "-c" "/usr/local/bin/dumb-init -- $METEORD_DIR/run_app.sh"]

Hope this help !

@johannel00
Copy link

Thanks @nabiltntn for the feedback. I was able to get it working by cloning the https://github.com/abernix/meteord repo and made changes to the 'base' Dockerfile and built it. I can confirm that it works with my Meteor 1.9 project.

I modified the Dockerfile to this:

FROM debian:stretch
MAINTAINER Jesse Rosenberger

ENV METEORD_DIR /opt/meteord
COPY scripts $METEORD_DIR

ARG NODE_VERSION
ENV NODE_VERSION ${NODE_VERSION:-12.14.0}
ONBUILD ENV NODE_VERSION ${NODE_VERSION:-12.14.0}

RUN bash $METEORD_DIR/lib/install_base.sh
RUN bash $METEORD_DIR/lib/install_node.sh
RUN bash $METEORD_DIR/lib/install_phantomjs.sh
RUN bash $METEORD_DIR/lib/cleanup.sh

EXPOSE 80/tcp
RUN chmod +x $METEORD_DIR/run_app.sh
ENTRYPOINT exec $METEORD_DIR/run_app.sh

ENV NODE_VERSION=12.14.0

RUN apt-get update \
    && apt-get install -y \
    libpangocairo-1.0-0 \
    libx11-xcb1 \
    libxcomposite1 \
    libxcursor1 \
    libxdamage1 \
    libxi6 \
    libxtst6 \
    libnss3 \
    libcups2 \
    libxss1 \
    libxrandr2 \
    libgconf2-4 \
    libasound2 \
    libatk1.0-0 \
    libgtk-3-0 \
    wget \
    --no-install-recommends \
    && rm -rf /var/lib/apt/lists/* \
    && rm -rf /src/*.deb
    
RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.2/dumb-init_1.2.2_amd64

RUN chmod +x /usr/local/bin/dumb-init

ENTRYPOINT /usr/local/bin/dumb-init -- $METEORD_DIR/run_app.sh

@wildhart
Copy link

Awesome work @johannel00. Can you make this available on DockerHub?

@johannel00
Copy link

johannel00 commented Jan 16, 2020

Awesome work @johannel00. Can you make this available on DockerHub?

It's available here. Let me know if it works for you.
https://hub.docker.com/repository/docker/fedescoinc/meteord-node-with-chromium_dumb-init/tags

@wildhart
Copy link

wildhart commented Feb 2, 2020

It's available here. Let me know if it works for you.

Works perfectly, thanks!

@wildhart
Copy link

FYI, After upgrading to Meteor 2.3.2 with node 14 I got this working with just:

   ...
    docker: {
      image: 'zodern/meteor:root',
      prepareBundle: true, // https://github.com/zodern/meteor-up/issues/942

      // (optional, default is true) If true, the app is stopped during
      // Prepare Bundle to help prevent running out of memory when building
      // the docker image. Set to false to reduce downtime if your server has
      // enough memory or swap.
      // needs swap: https://stackoverflow.com/questions/17173972/how-do-you-add-swap-to-an-ec2-instance?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
      stopAppDuringPrepareBundle: false,

      // Using headless Chrome Puppeteer with meteor and mup (Error) #981
      // https://github.com/zodern/meteor-up/issues/981#issuecomment-406588533
      buildInstructions: [
        'RUN apt-get update && apt-get install -y libpangocairo-1.0-0 libx11-xcb1 libxcomposite1 libxcursor1 libxdamage1 libxi6 libxtst6 libnss3 libcups2 libxss1 libxrandr2 libgconf2-4 libasound2 libatk1.0-0 libgtk-3-0 wget'
      ]
    },
 ...
  hooks: {
    'pre.setup': {
      // create swap file so can safely use stopAppDuringPrepareBundle: false
      remoteCommand: "[ -f /var/swap.1 ] && echo 'Swap file already exists' || (echo 'Creating swap file...' && /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024 && chmod 600 /var/swap.1 && /sbin/mkswap /var/swap.1 && /sbin/swapon /var/swap.1 && echo '  done!')"
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants