Puppeteer on Heroku: Failed to launch the browser process - heroku

I'm using Puppeteer on Heroku and I receive the following error:
Failed to launch the browser process! /usr/src/app/node_modules/puppeteer/.local-chromium/linux-756035/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md

Declare browser as:
const browser = await puppeteer.launch({
headless: true,
args: ['--no-sandbox','--disable-setuid-sandbox']
})
Install heroku buildpack puppeteer heroku buildpack
Must clear heroku cache
git add .
git commit -m "some text"
git push heroku master

May be this could help (copied from Puppeteer official website)
Running Puppeteer on Heroku (https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-puppeteer-on-heroku)
Running Puppeteer on Heroku requires some additional dependencies that aren't included on the Linux box that Heroku spins up for you. To add the dependencies on deploy, add the Puppeteer Heroku buildpack to the list of buildpacks for your app under Settings > Buildpacks.
The url for the buildpack is https://github.com/jontewks/puppeteer-heroku-buildpack
Ensure that you're using '--no-sandbox' mode when launching Puppeteer. This can be done by passing it as an argument to your .launch() call: puppeteer.launch({ args: ['--no-sandbox'] });.
When you click add buildpack, simply paste that url into the input, and click save. On the next deploy, your app will also install the dependencies that Puppeteer needs to run.
If you need to render Chinese, Japanese, or Korean characters you may need to use a buildpack with additional font files like https://github.com/CoffeeAndCode/puppeteer-heroku-buildpack
There's also another simple guide from #timleland that includes a sample project: https://timleland.com/headless-chrome-on-heroku/.

Adding this github repo to my heroku buildpack worked for me
https://github.com/jontewks/puppeteer-heroku-buildpack

You cant run Puppeteer on Heroku with headless: false because it doesn't have GUI to show.
You need to use headless: true that's because it's running on a Linux without GUI
If you have another errors, you may want to read the official Puppeteer troubleshooting guide: Running Puppeteer on Heroku.

Related

how can I install with tag "legacy-peer-deps" on heroku

I am trying to deploy my app onto heroku, yet I receive a build erorr where it fails to install the dependencies using npm install. Is there anyway I can install with "legacy-peer-deps"?
Thank you so much...
I tried editing my procifile file with the following contents in it
web: npm install --legacy-peer-deps
web: npm start
Ideally, you should resolve the underlying dependency issue so your application works without this option. But you should be able to configure it by setting environment variable ("config var" in Heroku-speak).
I believe the legacy-peer-deps setting will do the trick:
heroku config:set NPM_CONFIG_LEGACY_PEER_DEPS=true
Then you'll need to redeploy.
Alternatively, you could add an .npmrc file to your project:
legacy-peer-deps = true
Commit it, then redeploy.
It is recommended to fix your dependency issues, but in case there's still the need to deploy it as is, the easiest way to do so would be the following:
Go to your app account on Heroku.
Go to settings.
Click on 'Reveal Config Vars'.
Add as key:
NPM_CONFIG_LEGACY_PEER_DEPS
Add as value:
true
Deploy
Good luck!

No images to push error when container:push web in docker laravel heroku

I just learned about this problem so there is a bug that has not been fixed yet. For example "No images to push" when running the "heroku container:push web" command. Please help me, thanks you so much!!!
my err:
heroku.yml:
web.dockerfile:
Heroku provides two different methods for deploying with Docker that you're mixing up:
The container registry uses the heroku container:push command, but not heroku.yml.
If you wish to use this option, you need to rename your web.dockerfile to Dockerfile.web (or simply Dockerfile if it is your only image). You should also delete heroku.yml since it doesn't do anything.
Once your Dockerfile has been renamed, heroku container:push should be able to build and push your container.
Building with heroku.yml doesn't use heroku container:push.
If you wish to use this version, you'll need to follow a different set of instructions:
Make sure your heroku.yml file is committed
Tell Heroku to use the container stack:
heroku stack:set container
Deploy your code, e.g. by running git push heroku main
With this flow, Heroku will build your image from your heroku.yml file server-side.

heroku CLI auth by token

Every time after building and pushing docker image from Gitlab registry to Heroku registry I need to execute heroku container:release web to Heroku run image (release), but I wanna automate this
I added heroku CLI tool installation into gitlab-ci-yml, but I can't auth heroku CLI by token
When I try to set HEROKU_API_KEY=token and run heroku login I get an error Error: Cannot log in with HEROKU_API_KEY set
Also tried to do this with HEROKU_DEBUG on, but debugger info couldn't help me
I can't use ~/.netrc
Any way to auth heroku CLI or automate releasing docker images in heroku?
current gitlab-ci.yml:
before_script:
- apt install snapd
- snap install --classic heroku
- HEROKU_API_KEY=$HEROKU_API_TOKEN heroku login
- docker login -u $REGISTRY_UNAME -p $REGISTRY_PWD registry.gitlab.com
- docker login --username=_ --password=$HEROKU_PWD registry.heroku.com
script:
# a lot of tag & push lines
- heroku container:release web
If you have set the HEROKU_API_KEY environment variable, you don't have to log in again. The API key will be used for the Heroku CLI commands if present.
Make sure to use heroku authorizations:create to create never-expiring tokens. Check this out for a detailed explanation.
Ref: https://github.com/heroku/cli/issues/502#issuecomment-309099883
Note that the git commands like git push heroku master won't use the API key. See this for more info.
problem solved by changing account password that causes tokens changing and re-creating new token
And then run again HEROKU_API_KEY=token heroku container:release web with success

Ionic PWA deploy

I'm trying to deploy a Progressive Web App version of my Ionic 2 project to Heroku but it doesn't seem to work. What I'm trying is to use "Ionic build browser --prod" and then deploy the www folder, but I'm not getting any response from Heroku (Seems that nothing has being deployed)
The steps you are supposed to take:
Ionic build browser --prod - creates the main.js file to be deployed
Go to .gitignore file and remove the mentions of www/ so git picks it up and add these two lines so platforms browsers folder is picked up
platforms/*
!platforms/browser/
!platforms/browser/www
!platforms/browser/www/plugins
Add these 2 libraries to your package.json (don't forget to run npm install)
"connect": "^3.5.0",
"serve-static": "^1.11.1"
Add a start to your npm scripts in package.json
"start": "node server.js"
Add server.js to your project folder with the following code:
var connect = require('connect'),
serveStatic = require('serve-static');
var app = connect();
app.use(serveStatic("platforms/browser/www"))
app.listen(process.env.PORT || 5000);
Please note this code is only for ionic apps and not normal angular apps.
At this point you can write npm start or node server.js in your cmd and you can test to see how it will run.
Commit your code to heroku git using git push heroku master. Please note to have the heroku git on your remote list. You may do git remote -v to check if thats the case. If not get the url from the website and add it.
Optional - Put the www/ folder back in .gitignore and git rm --cached -r ./www to delete them from your git. This is so your co workers wont have merge conflicts on your main.js everytime you commit. The same for platforms/browser.
You are supposed to see heroku installing and deployed a node application in your enviornment after pushing to their git
NOTE If you are using Heroku you could probably do this with Heroku builds rather than playing with your git. https://github.com/heroku/heroku-builds
An update, as i ran the same task today:
It may be preferable to avoid
Adding and maintaining "server" code along with your app.
Pushing the built app (www/) in your version control system.
You can rely just on the heroku buildpacks. To do that you would need two buildpacks:
https://github.com/heroku/heroku-buildpack-nodejs.git
https://github.com/heroku/heroku-buildpack-static.git
Your app will be detected first as node app and will build, and later as a static site and served.
First, build the app up on heroku, don't add www to your version control system:
The first buildpack will detect your app as node app, and run the build after the postbuild script.
you need to add this line to you package.json scripts:
"heroku-postbuild": "ionic build --prod"
and add the ionic cli to your dev-dependencies so it can be available for heroku on the build process
npm install ionic --save-dev
Second, serve the static files generated:
The second buildpack will serve the static files generated in www. For that you need to tell the buildpack how to serve the files with a static.json file: (this one is somewhat equivalent to the config for firebase in the ionic docs)
/static.json:
{
"routes": {
"/**": "index.html"
},
"headers": {
"ngsw-worker.js": {
"Cache-Control": "no-cache"
},
"/build/app/**": {
"Cache-Control": "public, max-age=31536000"
}
},
"root": "www/"
}
Looks like the new Ionic doesn't generate the 'www/build/app/...' directory anymore, just added to be consistent with the above mentioned docs.
Just those two changes, along with the buildpacks are enough to run the PWA on heroku / dokku

How can I deploy a shiny app to Heroku

I have a shiny app and want to deploy it to Heroku. I tried to follow the steps as mentioned in:
https://github.com/btubbs/heroku-buildpack-shiny
I created a git Git repository and put the R files into it. Then, I created an app in heroku and tell Heroku to use a custom buildpack for my app. But, I was not be able to enable Heroku websockets support.
Error is:
Couldn't find that feature.
I can't figure out how to deal with this problem. Is there any other way to deploy the shiny app to Heroku?
Have you seen https://github.com/virtualstaticvoid/heroku-docker-r?
Check out the example shiny app too. To specify additional dependencies, you can still use init.R.
To deploy using Docker, you might have to move your current Heroku app to a container stack. This can be done with the heroku stack:set CLI command:
$ heroku stack:set container
Here's a minimal example. Basically:
Create run.R file with the following
library(shiny)
port <- Sys.getenv('PORT')
shiny::runApp(
appDir = getwd(),
host = '0.0.0.0',
port = as.numeric(port)
)
Commit to git
Create a new heroku app with
heroku create --buildpack https://github.com/virtualstaticvoid/heroku-buildpack-r.git
git push heroku master
That's all there is to it.
Another way would be to deploy using Docker. I am not an expert, but it took me a couple of days to deploy an app using this soluation. Many tutorials exist and could bring you to achieving this.

Resources