Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SomajitDey/809284d59f3d8cdf5e40b2a11cc19b6c to your computer and use it in GitHub Desktop.
Save SomajitDey/809284d59f3d8cdf5e40b2a11cc19b6c to your computer and use it in GitHub Desktop.
How to host anything on heroku.com in their free-tier 550 hrs/month. Web-apps mostly sleep so very low consumption.

Heroku Bash How-to

Heroku offers PaaS with a generous free-tier of 550 hours/month without requiring any credit-card validation. Official support is for Node.js, Python, Go, Ruby etc. But what if you just need to run a bash script, may be a netcat based server? Or you simply need to serve a webpage over http or https, and all you know is bash? (Of course you can also use the free services of x10hosting.com for the latter.)

Here are some simple steps to deploy a bash-script at Heroku.

  1. Open a Heroku account
  2. Download the Heroku CLI
  3. git init the directory that contains your bash script
  4. heroku login
  5. heroku create <name of your app/website>
  6. heroku buildpacks:add https://github.com/trustatom-oss/heroku-buildpack-shell. The buildpack is nothing but a directory containing three shell-scripts: bin/detect, bin/compile and bin/release. You can also build your own buildpack, upload it at GitHub etc., and add it to your Heroku app by providing its URL as above.
  7. Add a script named compile.sh in your project directory that will do all the compiling. /bin/compile of your buildpack shall call this script. If no compiling is needed, such as when you upload locally-built binaries to Heroku or intend to run bash scripts only, simply have echo compiling... in this script.
  8. Add a file named Procfile in your directory. This file shall contain the command to launch/run/deploy the app by the specified Heroku dyno-type(s). Example content: web: while : ;do echo hi | nc -l $PORT;done. NOTE: Note the use of $PORT in this command. Only processing running on web-dynos can receive inbound http/https traffic by listening to a port provisioned by heroku. The environment variable PORT contains this port number. The visitor to your website however doesn't need to know this port number. She can just type https://<your website name>.herokuapp.com in her browser.
  9. git add . followed by git commit
  10. Then push to Heroku for deployment: git push -u heroku master
  11. If deployment is successful, the push will be accepted.
  12. View logs anytime with : heroku logs -t -a <your app or website name>
  13. See the amount of free dyno hours consumed by your app: heroku ps -a <your app or website name>

Other resources

Docs

Limits to scaling

Dynos

Dyno-Runtime

http-routing

Heroku CLI help

heroku --help

heroku <command> --help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment