diff --git a/HerokuDockerfile b/HerokuDockerfile new file mode 100644 index 0000000..268cc06 --- /dev/null +++ b/HerokuDockerfile @@ -0,0 +1,17 @@ +FROM ubuntu:20.04 +ARG DEBIAN_FRONTEND=noninteractive +ENV RUSTUP_HOME=/usr/local/rustup \ + CARGO_HOME=/usr/local/cargo \ + PATH=/usr/local/cargo/bin:$PATH +RUN apt-get update \ + && apt-get install -y tzdata \ + && apt-get -y upgrade && apt-get install -y build-essential curl wget git vim libboost-all-dev +RUN curl -sL https://deb.nodesource.com/setup_14.x | bash \ + && apt-get install -y nodejs \ + && npm install -y -g ssvmup --unsafe-perm \ + && npm install -y ssvm \ + && npm install express express-fileupload +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +ADD . ./ +RUN ssvmup build +CMD node node/app.js diff --git a/README.md b/README.md index 247d9dc..6162cdd 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,22 @@ $ curl http://localhost:3000/?name=SSVM hello SSVM ``` +## Use Heroku to Deploy +Use this button [![Heroku Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/nizam0906/ssvm-nodejs-starter) + +![SSVM](https://github.com/nizam0906/ssvm-nodejs-starter/blob/master/docs/img/heroku.gif?raw=true) + +Or create a Heroku app manually: + +``` +$ heroku create +$ heroku stack:set container +$ git push heroku master +... +remote: Verifying deploy... done. +To https://git.heroku.com/ssvm-nodejs-starter.git + * [new branch] master -> master +``` ## Use VSCode Codespace diff --git a/app.json b/app.json new file mode 100644 index 0000000..e6d8779 --- /dev/null +++ b/app.json @@ -0,0 +1,10 @@ +{ + "name": "ssvm-nodejs-starter", + "description": "A template project to run Rust functions in Node.js through the Second State WebAssembly engine.", + "stack": "container", + "env":{ + "HEROKU_APP_NAME": { + "required": true + } + } +} diff --git a/docs/img/heroku.gif b/docs/img/heroku.gif new file mode 100644 index 0000000..210c4ed Binary files /dev/null and b/docs/img/heroku.gif differ diff --git a/heroku.yml b/heroku.yml new file mode 100644 index 0000000..d0b6a9d --- /dev/null +++ b/heroku.yml @@ -0,0 +1,3 @@ +build: + docker: + web: HerokuDockerfile diff --git a/node/app.js b/node/app.js index 8d1c331..b2ea5c2 100644 --- a/node/app.js +++ b/node/app.js @@ -2,13 +2,14 @@ const { say } = require('../pkg/ssvm_nodejs_starter_lib.js'); const http = require('http'); const url = require('url'); -const hostname = '0.0.0.0'; -const port = 3000; +const hostname = '0.0.0.0'; +const port = process.env.PORT || 3000; +const appname = (process.env.HEROKU_APP_NAME) ? process.env.HEROKU_APP_NAME + '.herokuapp.com' : hostname + ':' + port; const server = http.createServer((req, res) => { const queryObject = url.parse(req.url,true).query; if (!queryObject['name']) { - res.end(`Please use command curl http://${hostname}:${port}/?name=MyName \n`); + res.end(`Please use command curl http://${appname}/?name=MyName \n`); } else { res.end(say(queryObject['name']) + '\n'); }