
I'm going to use Go's built-in module support for this article. I'll also show a fairly new feature of Go: built-in package management.

In this post, I'm going to show you how easy it is to develop a simple web application in Go, package it as a lightweight Docker image, and deploy it to Heroku. Go feels like it was created with specific goals in mind, leading to a deceptively simple language design that's straightforward to learn, without compromising on capabilities. Add to that the robust and easily comprehensible approach to concurrency, to take maximum advantage of today's multi-core or multi-CPU execution environments, and it's clear why the Go community has grown so rapidly.


Ruby runner heroku code#
This comes down to the great tooling that you get out of the box with a compiler, runner, test suite, and code formatter provided by default. Go provides you with all the speed and performance of a compiled language, but feels like coding in an interpreted language. Many of the most popular tools such as Docker, Kubernetes, and Terraform are written in Go, but it can also be a great choice for building web applications and APIs. Hope this helps.The Go programming language, often referred to as "Golang," has gained a lot of well-deserved traction in the DevOps community. much like this awesome site: Īs mentioned earlier, keep an eye on memory and CPU usage though, we all know how much Chrome loves both ) I've noticed it using about 60-70Mb per chrome instance, and as long as you close browsers and the process in your scripts, it's been very stable. For example, I'm experimenting with the page.evaluate functions in Puppeteer, which allows you to execture javascript in the context of pages to get interesting font and color info out of them.
Ruby runner heroku pdf#
Push to Heroku and follow the build logs!! You should see everything installing, and finally your Ruby app starts per normal.įrom this point on, you can call any puppeteer script in the same way, so you are not limited to PDF generation. Git commit -m 'Adding node modules support and puppeteer'ġ9. Heroku buildpacks:add -index 1 heroku/nodejs Now add the node buildpack to position 1, so the final order is node, puppeteer and then ruby: The -index 1 puts it in the 1st position: heroku buildpacks:add -index 1 ġ7. First you need to add the puppeteer buildpack, to run before your Ruby buildpack (Ruby should always be last, as that is what will actually be handling the web requests etc.). In terminal, run the following command to see which buildpacks you are running on. Send_data(pdf_data, filename: pdf_filename, type: 'application/pdf', disposition: 'inline')ġ5. Your package.json should look something like this: ") So now in your app root, you have a "node_modules" folder, "package.json" and "package-lock.json" files, and an" pdf.js" file. I added the node version I want to use, directly into the package.json This ensures the same node version is used when you deploy to Heroku later.ħ.
Ruby runner heroku install#
The -save and -save-exact makes sure it also pulls in it's dependencies: npm install -save -save-exact puppeteerĦ. Create a new intializer, which will take care of pulling in the node modules on new dev or test machines: config/initializers/npm.rb system 'npm install' if ? || ?ĥ. It will ask you some questions, I went with the default for everything, except that I named my entry point file for "pdf.js" instead of "index.js" npm initĤ. Ignore the folder that will contain puppeteer and any other node module: echo '/node_modules' >. I changed a few commands and skipped a couple, so here's what I did:ġ. cd into the folder containing your Rails project.Ģ. To get node running alongside Rails, this great article helped me on the right track: just that it can be done and had no negative impact on my experimental project Adding node modules to your Rails appįirstly, make sure you have npm and node installed and with a recent version (I'm using 8.6.x): and it's maintained by Google themselves. Resulting PDF's from my experiments so far look perfect!ĭISCLAIMER: I'm not saying the below is a good idea, or even that I know what I am doing. This means it handles HTML5, CSS3 and Google fonts, which the other alternatives have always had troubles with. This is the same idea behind wkhtmltopdf and PhantomJs but puppeteer is powered by a modern and maintained browser. Headless is great because it means we can use much of the same functionality of a normal Chrome browser, but can be run entirely on a remote server.

However, running a node.js library from within a Rails app was not something I'd done before and I couldn't find a lot of info or complete instructions, so I decided to document it here for my own future reference.
