/stage-ci

Automatic deploy previews for your PRs using zeit.co/now.

Primary LanguageJavaScriptMIT LicenseMIT

stage-ci

Realtime staging environments.

Prerequisites

Node 6.6.0 and greater (security requirement for crypto.timingSafeEqual)

Development

Install project dependencies:

$ yarn

Generate a GitHub token with the repo scope. Set this token in an environment variable:

$ export GITHUB_TOKEN=123

Generate a Zeit API token and set it in an environment variable:

$ export ZEIT_API_TOKEN=123

To enable Papertrail logging, set the respective environment variables:

$ export PAPERTRAIL_HOST=logs.papertrail.com && PAPERTRAIL_PORT=1234

To inject environment variables into the staging deployment, set the ENVS environment variable to a valid JSON object:

$ export ENVS='{"REDIS_HOST": "my.cache.aws.com", "REDIS_PORT": 1234}'

Now start the server:

$ npm start

Testing GitHub integration

Install ngrok or some other localhost tunnel. Fire it up and point it to port 3000:

$ ngrok http 3000

Setup a test repo on GitHub and configure a webhook using the ngrok url. Give it access to the "Pull request" event. You also must set a secret. Use this value as your GITHUB_WEBHOOK_SECRET. It should be long and you should not share it with anyone.

Now use the same value to set your secret environment variable:

$ export GITHUB_WEBHOOK_SECRET=REPLACEME_REPLACEME_REPLACEME_REPLACEME_REPLACEME_REPLACEME_REPLACEME

Open a PR on your repo to trigger the webhook. It will also fire on commits pushed to the PR's branch.

Dev away! :)

License

stage-ci is licensed under the MIT License.