Skip to content
This repository was archived by the owner on Feb 2, 2026. It is now read-only.

Commit 878e5dd

Browse files
authored
feat(deployment): encrypt heroku auth token in node (#188)
* feat(deployment): encrypt heroku auth token in node * bug(deployment): Included missing file and added error cleanup to heroku-token script
1 parent 1904980 commit 878e5dd

7 files changed

Lines changed: 1398 additions & 1152 deletions

File tree

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ node_js:
44
services:
55
- postgresql # starts up postgres
66
addons:
7-
postgresql: '9.6' # highest available postgres version on Travis
8-
dist: trusty # uses trusty environment
9-
sudo: false # when on trusty, uses Docker containers for speed
7+
postgresql: '10' # recent postgres version on Travis
8+
dist: xenial # uses xenial environment
109
notifications:
1110
email:
1211
on_success: change # default: change (only when going from broken to fixed)

README.md

Lines changed: 156 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@
22

33
_Good things come in pairs_
44

5-
Looking to mix up a backend with express/sequelize and a frontend with react/redux? That's `boilermaker`!
5+
Looking to mix up a backend with `express`/`sequelize` and a frontend with
6+
`react`/`redux`? That's `boilermaker`!
67

7-
Follow along with the workshop to make your own! This canonical version can serve as a reference, or a starting point all on its own.
8+
Follow along with the boilerplate workshop to make your own! This canonical
9+
version can serve as a reference, or a starting point. For an in depth
10+
discussion into the code that makes up this repository, see the
11+
[Boilermaker Guided Tour][boilermaker-yt]
12+
13+
[boilermaker-yt]: https://www.youtube.com/playlist?list=PLx0iOsdUOUmn7D5XL4mRUftn8hvAJGs8H
814

915
## Setup
1016

11-
To use this boilerplate, you'll need to take the following steps:
17+
To use this as boilerplate, you'll need to take the following steps:
1218

13-
* Don't fork or clone this repo! Instead, create a new, empty directory on your machine and `git init` (or create an empty repo on Github and clone it to your local machine)
19+
* Don't fork or clone this repo! Instead, create a new, empty
20+
directory on your machine and `git init` (or create an empty repo on
21+
Github and clone it to your local machine)
1422
* Run the following commands:
1523

1624
```
@@ -19,7 +27,9 @@ git fetch boilermaker
1927
git merge boilermaker/master
2028
```
2129

22-
Why did we do that? Because every once in a while, `boilermaker` may be updated with additional features or bug fixes, and you can easily get those changes from now on by entering:
30+
Why did we do that? Because every once in a while, `boilermaker` may
31+
be updated with additional features or bug fixes, and you can easily
32+
get those changes from now on by entering:
2333

2434
```
2535
git fetch boilermaker
@@ -30,104 +40,186 @@ git merge boilermaker/master
3040

3141
Now that you've got the code, follow these steps to get acclimated:
3242

33-
* Update project name and description in `package.json` and `.travis.yml` files
34-
* `npm install`, or `yarn install` - whatever you're into
35-
* Create two postgres databases: `boilermaker` and `boilermaker-test` (you can substitute these with the name of your own application - just be sure to go through and change the `package.json` and `.travis.yml` to refer to the new name)
36-
* By default, running `npm test` will use `boilermaker-test`, while regular development uses `boilermaker`
37-
* Create a file called `secrets.js` in the project root
43+
* Update project name and description in `package.json` and
44+
`.travis.yml` files
45+
* `npm install`
46+
* Create two postgres databases (`MY_APP_NAME` should match the `name`
47+
parameter in `package.json`):
48+
49+
```
50+
export MY_APP_NAME=boilermaker
51+
createdb $MY_APP_NAME
52+
createdb $MY_APP_NAME-test
53+
```
3854

39-
* This file is `.gitignore`'d, and will _only_ be required in your _development_ environment
40-
* Its purpose is to attach the secret env variables that you'll use while developing
41-
* However, it's **very** important that you **not** push it to Github! Otherwise, _prying eyes_ will find your secret API keys!
55+
* By default, running `npm test` will use `boilermaker-test`, while
56+
regular development uses `boilermaker`
57+
* Create a file called `secrets.js` in the project root
58+
* This file is listed in `.gitignore`, and will _only_ be required
59+
in your _development_ environment
60+
* Its purpose is to attach the secret environment variables that you
61+
will use while developing
62+
* However, it's **very** important that you **not** push it to
63+
Github! Otherwise, _prying eyes_ will find your secret API keys!
4264
* It might look like this:
4365

44-
```
45-
process.env.GOOGLE_CLIENT_ID = 'hush hush'
46-
process.env.GOOGLE_CLIENT_SECRET = 'pretty secret'
47-
process.env.GOOGLE_CALLBACK = '/auth/google/callback'
48-
```
66+
```
67+
process.env.GOOGLE_CLIENT_ID = 'hush hush'
68+
process.env.GOOGLE_CLIENT_SECRET = 'pretty secret'
69+
process.env.GOOGLE_CALLBACK = '/auth/google/callback'
70+
```
71+
72+
### OAuth
4973

50-
* To use OAuth with Google, complete the step above with a real client ID and client secret from Google
51-
* You can get them here: https://console.developers.google.com/apis/credentials
52-
* Finally, complete the section below to set up your linter
74+
* To use OAuth with Google, complete the steps above with a real client
75+
ID and client secret supplied from Google
76+
* You can get them from the [Google APIs dashboard][google-apis].
77+
78+
[google-apis]: https://console.developers.google.com/apis/credentials
5379

5480
## Linting
5581

56-
Linters are fundamental to any project - they ensure that your code has a consistent style, which is critical to writing readable code.
82+
Linters are fundamental to any project. They ensure that your code
83+
has a consistent style, which is critical to writing readable code.
5784

58-
Boilermaker comes with a working linter (ESLint, with `eslint-config-fullstack`) "out of the box." However, everyone has their own style, so we recommend that you and your team work out yours and stick to it. Any linter rule that you object to can be "turned off" in `.eslintrc.json`. You may also choose an entirely different config if you don't like ours:
85+
Boilermaker comes with a working linter (ESLint, with
86+
`eslint-config-fullstack`) "out of the box." However, everyone has
87+
their own style, so we recommend that you and your team work out yours
88+
and stick to it. Any linter rule that you object to can be "turned
89+
off" in `.eslintrc.json`. You may also choose an entirely different
90+
config if you don't like ours:
5991

6092
* [Standard style guide](https://standardjs.com/)
6193
* [Airbnb style guide](https://github.com/airbnb/javascript)
6294
* [Google style guide](https://google.github.io/styleguide/jsguide.html)
6395

6496
## Start
6597

66-
`npm run start-dev` will make great things happen!
98+
Running `npm run start-dev` will make great things happen!
6799

68-
If you want to run the server and/or webpack separately, you can also `npm run start-server` and `npm run build-client`.
100+
If you want to run the server and/or `webpack` separately, you can also
101+
`npm run start-server` and `npm run build-client`.
69102

70103
From there, just follow your bliss.
71104

72105
## Deployment
73106

74-
Ready to go world wide? Here's a guide to deployment! There are two (compatible) ways to deploy:
107+
Ready to go world wide? Here's a guide to deployment! There are two
108+
supported ways to deploy in Boilermaker:
75109

76-
* automatically, via continuous integration
77-
* manually, from your local machine
110+
* automatically, via continuous deployment with Travis.
111+
* "manually", from your local machine via the `deploy` script.
78112

79-
Either way, you'll need to set up your deployment server to start:
113+
Either way, you'll need to set up your deployment server to start.
114+
The steps below are also covered in the CI/CD workshop.
80115

81-
### Prep
116+
### Heroku
82117

83-
1. Set up the [Heroku command line tools](https://devcenter.heroku.com/articles/heroku-cli)
118+
1. Set up the [Heroku command line tools][heroku-cli]
84119
2. `heroku login`
85120
3. Add a git remote for heroku:
86121

87-
* **If you're creating a new app...**
88-
89-
1. `heroku create` or `heroku create your-app-name` if you have a name in mind.
90-
2. `heroku addons:create heroku-postgresql:hobby-dev` to add ("provision") a postgres database to your heroku dyno
122+
[heroku-cli]: https://devcenter.heroku.com/articles/heroku-cli
91123

92-
* **If you already have a Heroku app...**
124+
* **If you are creating a new app...**
93125

94-
1. `heroku git:remote your-app-name` You'll need to be a collaborator on the app.
126+
1. `heroku create` or `heroku create your-app-name` if you have a
127+
name in mind.
128+
2. `heroku addons:create heroku-postgresql:hobby-dev` to add
129+
("provision") a postgres database to your heroku dyno
95130

96-
### When you're ready to deploy
97-
98-
#### Option A: Automatic Deployment via Continuous Integration
131+
* **If you already have a Heroku app...**
99132

100-
(_**NOTE**: This step assumes that you already have Travis-CI testing your code._)
133+
1. `heroku git:remote your-app-name` You'll need to be a
134+
collaborator on the app.
101135

102-
CI is not about testing per se – it's about _continuously integrating_ your changes into the live application, instead of periodically _releasing_ new versions. CI tools can not only test your code, but then automatically deploy your app. Boilermaker comes with a `.travis.yml` configuration almost ready for deployment; follow these steps to complete the job.
136+
### Travis
103137

104-
1. Run `git checkout master && git pull && git checkout -b f/travis-deploy` (or use some other new branch name).
105-
2. Un-comment the bottom part of `.travis.yml` (the `before_deploy` and `deploy` sections)
106-
3. Add your Heroku app name to `deploy.app`, where it says "YOUR HEROKU APP NAME HERE". For example, if your domain is `cool-salty-conifer.herokuapp.com`, your app name is `cool-salty-conifer`.
107-
4. Install the Travis CLI tools by following [the instructions here](https://github.com/travis-ci/travis.rb#installation).
108-
5. Run `travis encrypt $(heroku auth:token) --org` to encrypt your Heroku API key. _**Warning:** do not run the `--add` command suggested by Travis, that will rewrite part of our existing config!_
109-
6. Copy-paste your encrypted API key into the `.travis.yml` file under `deploy.api_key.secure`, where it says "YOUR ENCRYPTED API KEY HERE".
110-
7. `git add -A && git commit -m 'travis: activate deployment' && git push -u origin f/travis-deploy`
111-
8. Make a PR for the new branch, get it approved, and merge it into master.
138+
_**NOTE**_ that this step assumes that Travis-CI is already testing your code.
139+
Continuous Integration is not about testing per se – it's about _continuously
140+
integrating_ your changes into the live application, instead of periodically
141+
_releasing_ new versions. CI tools can not only test your code, but then
142+
automatically deploy your app. This is known as Continuous Deployment.
143+
Boilermaker comes with a `.travis.yml` configuration almost ready for
144+
continuous deployment; follow these steps to the job.
112145

113-
That's it! From now on, whenever `master` is updated on GitHub, Travis will automatically push the app to Heroku for you.
146+
1. Run the following commands to create a new branch:
114147

115-
#### Option B: Manual Deployment from your Local Machine
148+
```
149+
git checkout master
150+
git pull
151+
git checkout -b f/travis-deploy
152+
```
116153

117-
Some developers may prefer to control deployment rather than rely on automation. Your local copy of the application can be pushed up to Heroku at will, using Boilermaker's handy deployment script:
154+
2. Run the following script to finish configuring `travis.yml` :
155+
`npm run heroku-token`
156+
This will use your `heroku` CLI (that you configured previously, if
157+
not then see [above](#Heroku)) to generate an authentication token. It
158+
will then use `openssl` to encrypt this token using a public key that
159+
Travis has generated for you. It will then update your `.travis.yml`
160+
file with the encrypted value to be sent with the `secure` key under
161+
the `api_key`.
162+
3. Run the following commands to commit these changes
118163

119-
1. Make sure that all your work is fully committed and pushed to your master branch on Github.
120-
2. If you currently have an existing branch called "deploy", delete it now (`git branch -d deploy`). We're going to use a dummy branch with the name "deploy" (see below), so if you have one lying around, the script below will error
121-
3. `npm run deploy` - this will cause the following commands to happen in order:
164+
```
165+
git add .travis.yml
166+
git commit -m 'travis: activate deployment'
167+
git push -u origin f/travis-deploy
168+
```
122169

123-
* `git checkout -b deploy`: checks out a new branch called "deploy". Note that the name "deploy" here isn't magical, but it needs to match the name of the branch we specify when we push to our heroku remote.
124-
* `webpack -p`: webpack will run in "production mode"
125-
* `git add -f public/bundle.js public/bundle.js.map`: "force" add the otherwise gitignored build files
126-
* `git commit --allow-empty -m 'Deploying'`: create a commit, even if nothing changed
127-
* `git push --force heroku deploy:master`: push your local "deploy" branch to the "master" branch on heroku
128-
* `git checkout master`: return to your master branch
129-
* `git branch -D deploy`: remove the deploy branch
170+
4. Make a Pull Request for the new branch, get it approved, and merge it into
171+
the master branch.
172+
173+
_**NOTE**_ that this script depends on your local `origin` Git remote matching
174+
your GitHub URL, and your local `heroku` remote matching the name of your
175+
Heroku app. This is only an issue if you rename your GitHub organization,
176+
repository name or Heroku app name. You can update these values using
177+
`git remote` and its related commands.
178+
179+
#### Travis CLI
180+
181+
There is a procedure to complete the above steps by installing the official
182+
[Travis CLI tools][travis-cli]. This requires a recent Ruby, but this step
183+
should not be, strictly speaking, necessary. Only explore this option when the
184+
above has failed.
185+
186+
[travis-cli]: https://github.com/travis-ci/travis.rb#installation
187+
188+
That's it! From now on, whenever `master` is updated on GitHub, Travis
189+
will automatically push the app to Heroku for you.
190+
191+
### Cody's own deploy script
192+
193+
Your local copy of the application can be pushed up to Heroku at will,
194+
using Boilermaker's handy deployment script:
195+
196+
1. Make sure that all your work is fully committed and merged into your
197+
master branch on Github.
198+
2. If you currently have an existing branch called "deploy", delete
199+
it now (`git branch -d deploy`). We will use a dummy branch
200+
with the name `deploy` (see below), so and the script below will error if a
201+
branch with that name already exists.
202+
3. `npm run deploy`
203+
_ this will cause the following commands to happen in order:
204+
_ `git checkout -b deploy`: checks out a new branch called
205+
`deploy`. Note that the name `deploy` here is not magical, but it needs
206+
to match the name of the branch we specify when we push to our `heroku`
207+
remote.
208+
_ `webpack -p`: webpack will run in "production mode"
209+
_ `git add -f public/bundle.js public/bundle.js.map`: "force" add
210+
these files which are listed in `.gitignore`.
211+
_ `git commit --allow-empty -m 'Deploying'`: create a commit, even
212+
if nothing changed
213+
_ `git push --force heroku deploy:master`: push your local
214+
`deploy` branch to the `master` branch on `heroku`
215+
_ `git checkout master`: return to your master branch
216+
_ `git branch -D deploy`: remove the deploy branch
130217

131218
Now, you should be deployed!
132219

133-
Why do all of these steps? The big reason is because we don't want our production server to be cluttered up with dev dependencies like webpack, but at the same time we don't want our development git-tracking to be cluttered with production build files like bundle.js! By doing these steps, we make sure our development and production environments both stay nice and clean!
220+
Why do all of these steps? The big reason is because we don't want our
221+
production server to be cluttered up with dev dependencies like
222+
`webpack`, but at the same time we don't want our development
223+
git-tracking to be cluttered with production build files like
224+
`bundle.js`! By doing these steps, we make sure our development and
225+
production environments both stay nice and clean!

0 commit comments

Comments
 (0)