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:
- Download JDK and ant.
- Build the project using the
ant
command. - 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
- Create a Heroku account https://www.heroku.com/
- Download the Heroku toolbelt https://toolbelt.heroku.com/
- Login with heroku:
heroku login
- Clone the Loklak server (if not already) :
git clone https://github.com/loklak/loklak_server.git
- Create a heroku app:
heroku create
- Set the buildpack:
heroku buildpacks:set https://github.com/aneeshd16/heroku-buildpack-ant-loklak.git
- Push your app to heroku:
git push heroku master
- Confirm the loklak server is running:
heroku logs --tail
- Sometimes the server may take a while to start. The logs would show
State changed from starting to up
when the server is ready. - 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)