Over the last one year Loklak has been turning into quite a huge project. The main Loklak site (http://loklak.org) hosts 125 million messages for 14 million users! How cool is that?

Loklak is a P2P based service; the more peers, the better the service. Till very recently, the only way to have your own Loklak instance was to spin up a VM on a cloud provider, and then follow the instructions to install, build and start the Loklak server. This also meant that you had to download and install all required dependencies like JDK, ant, etc. Also, if the server unexpectedly shut down, you had to manually restart it. A major leap came when Loklak was dockerized. Yes! Loklak can now be easily installed with Docker. Here are the instructions to deploy Loklak with Docker.

A key piece missing was deployment to PaaS providers like Heroku. Heroku makes it super easy for developers and organizations to deploy the code without needing to worry about maintenance and deployment issues. You just need to upload your code and Heroku takes care of the rest. Since its underlying stack is Debian based Ubuntu, most applications will have no trouble running on it. However, Heroku does not give you direct access to the VM per se. There is no terminal access. All deployment and build commands are in a special file named Procfile, stored in the root directory of your project. This can handle most use cases and programming languages but not stuff like custom builds and deployment. To overcome this, Heroku has given us the option to create custom buildpacks. To enable the deployment of Loklak on Heroku, a new buildpack was needed. The buildpack needed to:

  1. Download JDK and ant.

  2. Build the project using the ant command.

  3. Start the server using the custom shell script in the bin directory of the project.

Luckily, I found an excellent buildpack for building ant projects to Heroku. I promptly forked it and began writing my own modifications so that it could be used with Loklak server. I finally ended up with Heroku buildpack for Loklak: Java (with Apache Ant). I also had to make a special start-up script in the Loklak server project so that the server runs in the foreground and logs are properly forwarded to Heroku's logging utility.

How to run the Loklak server on Heroku

  1. Create a Heroku account https://www.heroku.com/

  2. Download the Heroku toolbelt https://toolbelt.heroku.com/

  3. Login with heroku: heroku login

  4. Clone the Loklak server (if not already) : git clone https://github.com/loklak/loklak_server.git

  5. Create a heroku app: heroku create

  6. Set the buildpack: heroku buildpacks:set https://github.com/aneeshd16/heroku-buildpack-ant-loklak.git

  7. Push your app to heroku: git push heroku master

  8. Confirm the loklak server is running: heroku logs --tail

  9. Sometimes the server may take a while to start. The logs would show State changed from starting to up when the server is ready.

  10. Open the URL of your server in your browser: heroku open.

And that's it! Seems like the easiest way to deploy Loklak to the cloud. Keep in mind that a free dyno on heroku sleeps after some period of inactivity, and it may take a while for it to start up from the sleep phase. You can always upgrade to a paid tier if you wish. (Wish Heroku paid me for this post)