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.
- Open a Heroku account
- Download the Heroku CLI
git init
the directory that contains your bash scriptheroku login
heroku create <name of your app/website>
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.- 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. - 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 typehttps://<your website name>.herokuapp.com
in her browser. git add .
followed bygit commit
- Then push to Heroku for deployment:
git push -u heroku master
- If deployment is successful, the push will be accepted.
- View logs anytime with :
heroku logs -t -a <your app or website name>
- See the amount of free dyno hours consumed by your app:
heroku ps -a <your app or website name>
heroku --help
heroku <command> --help