How to deploy SailsJs app via Amazon’s OpsWorks

Week ago CTO of company where I am working at the moment, asked me do I know what is OpsWorks and what it does. I was like, nope, never heard of that, sounds like something that has to do with DevOps and work, in some sense 🙂 We started chatting and talking about it. Hours later I did checked it out briefly and it seemed to be just what i was looking for. Easy atomic deployment with full power of load-balancing and creation of EC2 instances. Perfect!! As many of us who worked for at least 2 different companies, small or big, doesn’t matter, know that deployment is ONE thing that varies greatly from company to company.

I think there is more deploying tools for any kind of code than frameworks itself, which also means that people have different mindset for deploying. Some like Capistrano, some like Mina others like other deployment tools that are written in a language they know and/or they are comfortable with. These deployment tools wary greatly in performance and in language they are written in.

As we are talking about deployment, my personal opinion is that deployment process should be as simple as possible, somewhat centralised and well defined. Most of us are using version control software like Git or Subversion/Mercurial. So question is why use other software that will do it’s magic with your code when you have it already online and accessible? As this is not a post about Deployment Management, i will stop here and get to the point.

Let’s start!!

First of all there will be minor tweaks to SailsJs app before we can deploy it properly.

Step 1, preparing SailsJs app:

  • Rename your app.js to server.js
  • open your package.json file and change all occurrences of app.js to server.js, that will not mess up sails lift and everything should work as it was before
  • open  config/env/production.js and enable port: 80,
  • save

Step 2, preparing OpsWorks environment:

  • Check out Getting started With OpsWorks, that should cover quite a lot of what you should do. One note on repositories, use PRIVATE key, not public, it will not work. I have mine hosted on bitbucket as private repo, so i created deployment key-pair just for opsworks deployment. If you are stuck somewhere in the middle of the process, or it doesn’t work, please let me know via comments and i will try to answer or even write more detailed post about it.
  • Make sure to set Env variable NODE_ENV = production for the env settings; that tells sails to run production.js config

When you see that your deployment is done, go to instances and select one that is tied to your app, there should be public IP address, click on it and enjoy your deployed sails app.

I’ve created github repo of clean SailsJs app SailsJs deployable template, feel free to use it and/or modify it.

Useful links

OpsWorks doc on nodejs apps

Programming with Cloud IDEs

After reading many posts about cloud IDEs, how cool they are and how developers can be more productive and develop faster and faster until they reach speed of light, i decided to test for myself. Some of the facts that are said about cloud IDEs hold the ground, but to which extent, and how much actually they are useful for building real apps? They say that cloud IDEs are future of coding, because they unify environment,  system OS independent, but as always there is a drawbacks, like constant, internet connection, fast(er) internet speed ( i tried to work with one of them via tethered wifi hotspot from my phone where i have 0.5 MB up and down, and I tell you, it’s soooo slow ), any browser will start sucking ram, constant DOM manipulation and caching. Chrome wen to 2 GB for single process when i used one of the cloud IDEs.

But enough of that, let’s start to list them and tell what’s the setup and how this will go.

  1. First all cloud IDEs will be tested with same github repo
  2. Bower, Grunt, NPM, nodejs 0.10.20+ installed
  3. Mysql (if not supported MongoDB then)
  4. Redis

I will record every single installation/cloning of repo on each cloud IDE.

These are the cloud IDEs that i will cover with this blog series. Each of them will be  a blog post, so if you would like for me to test some other your favourite cloud IDE with same routine, drop a comment below, or send a tweet.

Stay tuned for upcoming “Part 1, coding with Codeanywhere”.