Photo by @chuttersnap — https://unsplash.com/photos/pgfWIStWIfs

CircleCI and Zeit’s now.sh

This will be a very short post. I just wanted to share the config that I came up with. I had difficulties to find the answer to my questions when I was working on it.

The problem

I needed to add Continuous Integration and Continuous Deployment to the platform that I was working on. I use now.sh for all of my side project and recently started to use it at work as well.

Simply I wanted CircleCI to run the tests for me and deploy the pages to two environments dev for QA and production. I also wanted to alias the deployed pages.

One of the problems that I was facing was that we use a few private modules from npm, and I needed a way of giving now access to them. Currently now supports installing from GitHub private repos, but not npm. AFAIK better support for private npm modules is coming very soon to now. But there’s a way of dealing with it currently, by setting forwardNpm flag (thanks to Guillermo Rauch for pointing it out to me).

My solution

So here is how I set it up:

First of all I tell CircleCI to use yarn instead of npm (as this is my preference). I also install now globally and set deployments for two of my branches on GitHub. I also generated the now token from now.sh and set it in the CircleCI dashboard as NOW_TOKEN environment variable.

If you want to use just now alias <YOUR_ALIAS> instead of 
now alias set <DEPLOYMENT_ID> <YOUR_ALIAS>
you need to specify an alias property in now.json file. I also set forwardNpm flag to true as I want now to use .npmrc file to get the access to my npm private modules.

So when I merge my PR to the master branch, it gets deployed and aliased to foo-dev.now.sh, if I do the same for the production branch it will be deployed and aliased to foo.now.sh.

That’s it! Hope it is helpful!

Feel free to comment if you have any questions or ways of improving this setup. This setup satisfies my needs, feel free to amend it to your needs.