You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+200-5
Original file line number
Diff line number
Diff line change
@@ -67,7 +67,7 @@ These microservices are preconfigured for security, performance, and graceful re
67
67
68
68
* Webapp server → [web.js](template/web.js)
69
69
* API server → [api.js](template/api.js)
70
-
* Job scheduler → [bull.js](template/bull.js)
70
+
* Job scheduler → [bree.js](template/bree.js)
71
71
* Proxy server → [proxy.js](template/proxy.js)
72
72
73
73
### Front-end
@@ -302,6 +302,181 @@ We strongly recommend using [SemaphoreCI][], [PM2][], and [Digital Ocean][do] fo
302
302
303
303
5. If you specify an environment variable value for `AWS_CF_DOMAIN` and `NODE_ENV=production` is set then your assets will need to be published to Amazon S3/Cloudfront. To do so run `npm start publish-assets` (or with yarn as `yarn start publish-assets`). This command automatically sets `NODE_ENV=production` for you as well via `cross-env`.
304
304
305
+
#### Provisioning
306
+
307
+
See the [ansible](ansible/) folder for our [Ansible][] configuration and playbooks, which we use to provision servers with.
308
+
309
+
We recommend you to install [yamllint][] and configure it in your editor while working with [Ansible][] playbooks.
310
+
311
+
Also note that [ansible-lint][] is a helpful linting tool you can use if you plan on making changes to playbooks. Note that our current playbooks have several existing lint errors.
312
+
313
+
First you must provision Ubuntu 18.04 LTS 64-bit server(s) using [Digital Ocean][digital-ocean], [Linode][], [Vultr][], or your host of choice. These newly provisioned server(s) should have your SSH key automatically added.
314
+
315
+
Follow the [Deployment](#deployment) guide below for automatic provisioning and deployment instructions.
316
+
317
+
##### Deployment
318
+
319
+
1. Set up host configuration by copying the `hosts.yml` file template:
2. Edit this configuration and update the file with your newly created server aliases and IP addresses. You can add more than one host to each group if you are setting up load balancing. Refer to the [Naming Convention](#naming-convention) documentation for our recommended approach to server alias naming. Note that this file is automatically ignored by git. If you have a private repository and would like to commit this, then remove `hosts.yml` from the root `.gitignore` file.
326
+
327
+
```sh
328
+
vim hosts.yml
329
+
```
330
+
331
+
3. Set up environment configuration by copying the `env` file template:
4. Edit this configuration and reference the official [Lad][] documentation for a list of all available environment variables (or see [.env.defaults](.env.defaults)). **You will need to open this file in your preferred editor** and set the values for any fields containing `TODO`, whereby you replace `TODO` with the appropriate value. Preserve double quotes where they are already defined.
338
+
339
+
```sh
340
+
vim .env.production
341
+
```
342
+
343
+
5. Generate [pm2][] [ecosystem files][ecosystem-files] using our automatic template generator. We created an [ansible-playbook.js](ansible-playbook.js) which loads the `.env.production` environment variables rendered with [@ladjs/env][] into `process.env`, which then gets used in the playbooks. This is a superior, simple, and the only known dotenv approach we know of in Ansible. Newly created `ecosystem-api.json`, `ecosystem-bree.json`, `ecosystem-web.json` files will now be created for you in the root of the repository. If you ever more add or change IP addresses, you can simply re-run this command.
6. Set up the web and API server(s) (see [patterns and ansible-playbook flags docs](https://docs.ansible.com/ansible/latest/user_guide/intro_patterns.html#patterns-and-ansible-playbook-flags) if you need help). If you completely (or partially) run this playbook (or any others below), then the second time you try to run it may not succeed. This is because we prevent root user access through security hardening. To workaround this, run the same command but without `-e 'ansible_user=root'` appended as it will default to the `devops` user created.
10. Set up GitHub deployment keys for all the servers. Note that the `deployment-keys` directory is ignored from git, so if you have a private repository and wish to commit it, then remove `deployment-keys` from the `.gitignore` file.
11. Go to your repository "Settings" page on GitHub, click on "Deploy keys", and then add a deployment key for each servers' deployment key copied to the `deployment-keys` directory. If you're on macOS, you can use the `pbcopy` command to copy each file's contents to your clipboard. Use tab completion for speed, and replace the server names and paths with yours:
# a new deploy key (make sure to use read-only access)
389
+
#
390
+
```
391
+
392
+
12. Set up PM2 deployment directories on all the servers:
393
+
394
+
```sh
395
+
pm2 deploy ecosystem-web.json production setup
396
+
```
397
+
398
+
```sh
399
+
pm2 deploy ecosystem-api.json production setup
400
+
```
401
+
402
+
```sh
403
+
pm2 deploy ecosystem-bree.json production setup
404
+
```
405
+
406
+
13. Create a SSL certificate at [Namecheap][] (we recommend a 5 year wildcard certificate), set up the certificate, and download and extract the ZIP file with the certificate (emailed to you) to your computer. We do not recommend using tools like [LetsEncrypt][] and `certbot` due to complexity when you have (or scale to) a cluster of servers set up behind load balancers. In other words, we've tried approaches like `lsyncd` in combination with `crontab` for `certbot` renewals and automatic checking. Furthermore, using this exposes the server(s) to downtime as ports `80` and `443` may need to be shut down so that `certbot` can use them for certificate generation. This is not a reliable approach, and simply renewing certificates once a year is vastly simpler and also makes using load balancers trivial. Instead you can use a provider like [Namecheap][] to get a cheap SSL certificate, then run a few commands as we've documented below. This command will prompt you for an absolute file path to the certificates you downloaded. Renewed your certificate after 1 year? Simply follow this step again. Do not set a password on the certificate files. When using the `openssl` command (see Namecheap instructions), you need to use `*.example.com` with an asterisk followed by a period if you are registering a wildcard certificate.
>**Important:** If you renew or change certificates in the future, then after running the previous command, you will subsequently need to reload the processes as such:
413
+
414
+
```sh
415
+
#
416
+
# NOTE: See the "Important" note above BEFORE running this command.
417
+
# This command ONLY APPLIES for certificate renewals/changes.
418
+
#
419
+
pm2 deploy ecosystem-web.json production exec"pm2 reload web"
420
+
pm2 deploy ecosystem-api.json production exec"pm2 reload api"
421
+
```
422
+
423
+
14. (Optional) Create a Google application credentials profile file and store it locally. You only need this if you want to support automatic translation. The following command will prompt you for the absolute file path (e.g. `/path/to/client-profile.json`). See the [mandarin][] docs for more information.
17. Save the process list on the servers so when if the server were to reboot, it will automatically boot back up the processes:
450
+
451
+
```sh
452
+
pm2 deploy ecosystem-web.json production exec"pm2 save"
453
+
```
454
+
455
+
```sh
456
+
pm2 deploy ecosystem-api.json production exec"pm2 save"
457
+
```
458
+
459
+
```sh
460
+
pm2 deploy ecosystem-bree.json production exec"pm2 save"
461
+
```
462
+
463
+
464
+
16. Test by visiting your web and API server in your browser (click "proceed to unsafe" site and bypass certificate warning).
465
+
466
+
17. Configure your DNS records for the web and API server hostnames and respective IP addresses.
467
+
468
+
18. Test by visiting your web and API server in your browser (in an incognito window). There should not be any certificate warnings (similar to the one that occurred in step 15).
469
+
470
+
19. (Optional) Remove the local`.env.production` file forsecurity purposes. If you do this, then make sure you have a backup, or securely back up off the serverin the future before destroying the server.
471
+
472
+
```sh
473
+
rm .env.production
474
+
```
475
+
476
+
20. (Optional) Remove the local certificate files you downloaded locally and specified in step 11. If you do this, then make sure you have a backup, or securely back up off the server in the future before destroying the server.
477
+
478
+
21. Finished. If you need to deploy again, then push your changes to GitHub `master` branch and then follow step 14 again. We recommend you to read the [Ansible getting started guide][ansible-guide], as it provides you with insight into commands like `ansible all -a "echo hello"` which can be run across all or specific servers.
479
+
305
480
#### Tests
306
481
307
482
We use [ava][] and [nyc][] for testing and code coverage.
@@ -706,7 +881,7 @@ template
706
881
│ │ └── uncaught.js
707
882
│ ├── manifest.json
708
883
│ └── robots.txt
709
-
├── bull.js
884
+
├── bree.js
710
885
├── config
711
886
│ ├── env.js
712
887
│ ├── index.js
@@ -833,7 +1008,7 @@ If you are seeking permission to use these trademarks, then please [contact us](
0 commit comments