Preview your website with Gitlab CI and Surge
Julien Bianchi
132

As you may have seen, Riad Benguella suggested an alternative service if you have to host a webapp with its backend.

This service is called Now and is also very simple to hook to Gitlab CI builds. Here is how:

Get started with Now

npm install --save-dev now
node_modules/.bin/now --login

You will be prompted to enter your email address and follow a confirmation link. Once done, you are ready to go!

Configure GitLab CI

Open up your “.gitlab-ci.yml” file and add these lines:

preview:
stage:
deploy
script:
- echo ${NOW_AUTH} > ~/.now.json
- npm run build
- node_modules/.bin/now
except:
- master

Again, we add a “preview” job to the “deploy” stage.

Configure your GitLab project

As for Surge.sh, you will have to add a secured variable to your project. This one will hold a full JSON payload to make things simple:

cat ~/.now.json | pbcopy

Then create a “NOW_AUTH” variable and paste the content you got from the file.

Enjoy!

We are done! deploying a web application with its backend has never been so simple.

But…

There are some differences with Surge.sh:

  • Now free plan only allows 20 deployments per month,
  • It only supports Node.js projects
  • You can’t create custom domains as we did with Surge.sh
  • You can’t tear down previews

But but…

Now has some interesting features enabled by default on the free plan:

  • HTTP/2 support
  • Source browser (here is an example)
  • Storage, scaling, …