Skip to content

Commit bc71d48

Browse files
krubenokloreina
authored andcommitted
Feature/deployment (#613)
* Update to a supported node version * Create Procfile * Specify node version in package * Update Procfile * Rename npm scripts * Clean up some kruft * Add deploy to heroku button * Update script names * Add beta frontend to CORS list * Type on CORS env variable
1 parent 54b385c commit bc71d48

12 files changed

+184
-247
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ADDRESS=<Some address such as 127.0.0.1>
66
#front-end server
77
FRONTEND_ADDRESS_DEV=localhost:1337
88
FRONTEND_ADDRESS_DEPLOY=app.mchacks.ca
9+
FRONTEND_ADDRESS_BETA=develop--mchacks-dashboard.netlify.com
910

1011
#The info for the deployment database
1112
DB_ADDRESS_DEPLOY=<Deployment address>
@@ -51,4 +52,4 @@ CLIENT_ID=<client id>
5152
AUTH_URI=<auth uri>
5253
TOKEN_URI=<token uri>
5354
AUTH_PROVIDER_X509_CERT_URL=<auth provider>
54-
CLIENT_X509_CERT_URL=<client cert url>
55+
CLIENT_X509_CERT_URL=<client cert url>

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9.3.0
1+
10.17.0

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: npm run deploy

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ API for registration, live-site
1515
## How to use and contribute
1616

1717
See documentation here: <https://docs.mchacks.ca>
18+
19+
## Deploy
20+
21+
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)

app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ if (!Services.env.isProduction()) {
4646
corsOptions = {
4747
origin: [
4848
`https://${process.env.FRONTEND_ADDRESS_DEPLOY}`,
49+
`https://${process.env.FRONTEND_ADDRESS_BETA}`,
4950
`https://docs.mchacks.ca`
5051
],
5152
credentials: true

app.json

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"name": "HackMcGill HackerAPI",
3+
"description": "API for registration, live-site",
4+
"repository": "https://github.com/hackmcgill/hackerAPI",
5+
"keywords": ["node", "express", "mongo", "react", "hackathon"],
6+
"env": {
7+
"FRONTEND_ADDRESS_DEPLOY": {
8+
"description": "URL for application front end"
9+
},
10+
"DB_ADDRESS_DEPLOY": {
11+
"description": "Connection string for MongoDB"
12+
},
13+
"DB_USER_DEPLOY": {
14+
"description": "DB Username"
15+
},
16+
"DB_PASS_DEPLOY": {
17+
"description": "DB Password"
18+
},
19+
"JWT_INVITE_SECRET": {
20+
"generator": "secret"
21+
},
22+
"JWT_RESET_PWD_SECRET": {
23+
"generator": "secret"
24+
},
25+
"JWT_CONFIRM_ACC_SECRET": {
26+
"generator": "secret"
27+
},
28+
"SENDGRID_API_KEY": {
29+
"description": "Sendgrid API Key"
30+
},
31+
"NO_REPLY_EMAIL": {
32+
"description": "Noreply email address"
33+
},
34+
"NO_REPLY_EMAIL": {
35+
"description": "GCP Storage Bucket Name"
36+
},
37+
"TYPE": {
38+
"description": "GCP Account Type"
39+
},
40+
"PROJECT_ID": {
41+
"description": "GCP Project ID"
42+
},
43+
"PRIVATE_KEY_ID": {
44+
"description": "GCP Private Key ID"
45+
},
46+
"PRIVATE_KEY": {
47+
"description": "GCP Private Key"
48+
},
49+
"CLIENT_EMAIL": {
50+
"description": "GCP Client Email"
51+
},
52+
"AUTH_URI": {
53+
"description": "GCP Auth URI"
54+
},
55+
"TOKEN_URI": {
56+
"description": "GCP TOken URI"
57+
},
58+
"AUTH_PROVIDER_X509_CERT_URL": {
59+
"description": "GCP Provider Cert URL"
60+
},
61+
"CLIENT_X509_CERT_URL": {
62+
"description": "GCP Cert URL"
63+
}
64+
},
65+
"formation": {
66+
"web": {
67+
"quantity": 1,
68+
"size": "free"
69+
}
70+
},
71+
"image": "heroku/nodejs",
72+
"buildpacks": [
73+
{
74+
"url": "https://github.com/heroku/heroku-buildpack-nodejs"
75+
}
76+
]
77+
}

build.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

deployment.yaml

Lines changed: 0 additions & 24 deletions
This file was deleted.

docs/deploy.md

Lines changed: 39 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,42 @@
11
# How to deploy
22

3-
The following document acts as a quickstart guide on how to get your machine set up for deployment to the Google Cloud Container Cluster we have set up for the project.
4-
*** Please note that the very first step before performing any of the steps below is to get permission from** @Kyle Rubenok **to be added to the Google Cloud project.
5-
** The steps below are written with an Ubuntu OS in mind, however a Mac OS should also be able to perform the majority (if not all) of this given the UNIX environment.**
6-
7-
## Installing Google Cloud SDK
8-
9-
We begin by installing the Google Cloud CLI so we can easily deploy the application directly from the command line. Head over to [this link](https://cloud.google.com/sdk/) and click on the "Install for [OS]" button.
10-
11-
## Setting up Google Cloud SDK
12-
13-
Once you have the SDK installed, you can head over to your terminal and type in `gcloud init` to get started with the initial configuration of the SDK. This process is fairly intuitive and it takes you through a few steps to get your Google account linked to the CLI by logging into the web interface, as well as choosing a default project. **Note that it's a good idea to have your Google account already added to the project on Google Cloud by someone who has access before doing this, so that you can just select the hackboard project as your default instead of re-setting it later.**
14-
In any case, we will be covering what commands you need to set our project as your default project. Type in the following lines in your terminal.
15-
16-
```bash
17-
> gcloud config set project hackboard6
18-
> gcloud config set compute/zone us-east1-b
19-
```
20-
21-
## Installing Kubernetes
22-
23-
Kubernetes is essentially Google's answer to efficient cloud clustering and scaling. We'll use both Kubernetes and Docker here. Kubernetes is essentially what we will use to manage our cluster of nodes that will run the application and allow us to scale it efficiently and easily. We get into the Docker details later. We will **not** be installing Kubernetes through the official installer, but rather use `gcloud` CLI to install it such that it automatically integrates with your credentials and save us some time setting it up. Run the following in your terminal.
24-
25-
```bash
26-
> gcloud components install kubectl
27-
```
28-
29-
Hopefully you'll manage to walk through the simple setup quickly and have it up and running. The next step would be creating a cluster and setting it up with your application, but since we have already taken care of that, you'll want to run the below command to have your CLI connected to the cluster we have already created so that you can deploy to it. This command will attempt to retrieve the credentials for the 'hackboard' cluster we have set up and allow you to deploy to it.
30-
31-
```bash
32-
> gcloud container clusters get-credentials hackboard
33-
```
34-
35-
## Intalling Docker CE
36-
37-
We will be using the Community Edition of Docker for our application. Head over to [this link](https://www.docker.com/community-edition#download) and choose and specific installation for your own operating system; the setup is rather intuitive and skipped in this guide. Once you've got Docker installed, try running `docker —version` to make sure it's up and running. Note that docker has a 'daemon' service which should be running for the CLI to communicate with. I suggest following the steps in [this page](https://docs.docker.com/install/linux/linux-postinstall/#configure-docker-to-start-on-boot) to make sure the daemon is configured to start with your machine on start-up. Also, the previously mentioned note is mostly directed towards Linux users; the Windows and MacOS application (I believe) takes care of starting up the daemon for you once you see the green light in your indicators.
38-
39-
**NOTE**: **The following steps are optional and meant for you to understand how the deployment actually works. You will not have to (and it is not recommended) to run all these steps manually everytime, as there will be a bash script setup to take care of all this.**
40-
41-
## Building the Docker Image
42-
43-
Every Docker container requires an image to run, which in turn requires a 'Dockerfile' as a set of instructions for creating it. Images can extend off of other images or be created from scratch. Due to the fact that the Docker community is very well established and has an 'almost' exhaustive list of base images on it already, we will be using an official Node JS image that provides the runtime for our application to run, and add to it as we wish. Below is the basic Dockerfile we have created so far:
44-
45-
```bash
46-
FROM node:carbon
47-
ENV PORT 8080
48-
WORKDIR /usr/src/app
49-
COPY package*.json ./
50-
ADD VERSION .
51-
RUN npm install
52-
COPY . .
53-
EXPOSE 8080
54-
CMD [ "npm", "start" ]
3+
This application can be most easily deployed via Heroku. A "deploy to heroku" button is available in the `README.md` file. Once in Heroku, several environment variables will need to be filled out including:
4+
5+
```plain
6+
##front-end server
7+
FRONTEND_ADDRESS_DEPLOY=
8+
9+
#The info for the deployment database
10+
DB_ADDRESS_DEPLOY=
11+
DB_USER_DEPLOY=
12+
DB_PASS_DEPLOY=
13+
14+
#Secret key for the cookies
15+
COOKIE_SECRET=
16+
17+
#Secret key for the invite tokens
18+
JWT_INVITE_SECRET=
19+
20+
#Reset password secret
21+
JWT_RESET_PWD_SECRET=
22+
23+
#Secret key fo account confirmation token
24+
JWT_CONFIRM_ACC_SECRET=
25+
26+
#mail server information
27+
SENDGRID_API_KEY=
28+
NO_REPLY_EMAIL=
29+
30+
#Google Cloud Storage information
31+
BUCKET_NAME=
32+
TYPE=
33+
PROJECT_ID=-api
34+
PRIVATE_KEY_ID=
35+
PRIVATE_KEY=
36+
CLIENT_EMAIL=
37+
CLIENT_ID=
38+
AUTH_URI=
39+
TOKEN_URI=
40+
AUTH_PROVIDER_X509_CERT_URL=
41+
CLIENT_X509_CERT_URL=
5542
```
56-
57-
*If you have any questions regarding what Docker is and the difference between an image and a container, or anything else, I suggest reading online about it in detail before getting your hands dirty.*
58-
To explain what is happening here, we are extending off of the LTS (carbon) version of the official Node image available on [Docker Hub](https://hub.docker.com/). Next we create an environment variable called PORT for our application. Environment variables can be created like this, or all added in a separate file. Next we declare the path `/usr/src/app` to be working directory (i.e. starting directory) of our image. Any operations from here onwards in the Dockerfile are performed in the set working directory. We will also copy the `package.json` files and the `VERSION` file with each build to make it easier to figure out which build is live via the application itself. Next we run the `npm install` command to install all dependencies, copy everything else left to copy to the image, and mark port `8080` to be exposed. This is an arbitrary value for now and can be replaced with any other port desired. Finally, set `npm start` as the starting command of the application which corresponds to `node ./bin/www` in our `package.json` file; this pretty much fires up the backend server.
59-
60-
To be able to push the docker image into the Google Cloud Container Registry so that our clusters can access the images easily, we first need a defined naming/tagging scheme for the images. Below is the scheme we are using (which is the default and recommended way of naming images on Container Registry). The host name for Google Cloud Container Registry is `[gcr.io](http://gcr.io)` , our project-ID is `hackboard6` , image name is `hackboard` and the tag will correspond to the version of the current build `6.x.x` which we will also have it programatically increment and synchronize with every release on the master branch on GitHub.
61-
62-
[HOSTNAME]/[PROJECT-ID]/[IMAGE][:TAG|@DIGEST] #template
63-
gcr.io/hackboard6/hackboard:latest #example
64-
65-
Every image has a `latest` version as well as all the other versions it was tagged as. The `latest` tag is automatically applied to (obviously) the latest build of the image, while the legacy builds are accessible via their specific version numbers.
66-
67-
First you want to make sure there are no changes pushed to the master branch by anyone else before you deploy your local version. So perform a `git pull origin master`.
68-
69-
We will first increment our `VERSION` file using a 3rd-party Docker image.
70-
71-
*TO BE CONTINUED WHEN I HAVE THE MOOD.*

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 57 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,59 @@
11
{
2-
"name": "hackboard",
3-
"version": "0.0.0",
4-
"private": true,
5-
"scripts": {
6-
"start": "DEBUG=hackboard:* NODE_ENV=development nodemon --ignore gcp_creds.json ./bin/www.js",
7-
"build": "NODE_ENV=deployment node ./bin/www.js",
8-
"debug": "DEBUG=hackboard:* NODE_ENV=deployment nodemon --ignore gcp_creds.json ./bin/www.js",
9-
"test": "DEBUG=hackboard:* NODE_ENV=test mocha --reporter spec tests/**.js --exit",
10-
"seed": "NODE_ENV=development node ./seed/index.js",
11-
"docs": "apidoc -i ./routes -o ./docs/api/",
12-
"format": "prettier --write '**/*.js'",
13-
"lint": "eslint --fix '**/*.js'"
14-
},
15-
"dependencies": {
16-
"@google-cloud/logging-winston": "^0.11.1",
17-
"@google-cloud/storage": "^3.5.0",
18-
"@sendgrid/mail": "^6.4.0",
19-
"bcrypt": "^3.0.7",
20-
"cookie-parser": "~1.4.4",
21-
"cookie-session": "^2.0.0-beta.3",
22-
"cors": "^2.8.5",
23-
"cryptiles": "^4.1.3",
24-
"debug": "~4.1.1",
25-
"dotenv": "^8.2.0",
26-
"express": "~4.17.1",
27-
"express-validator": "^6.3.0",
28-
"express-winston": "^2.6.0",
29-
"handlebars": "^4.5.3",
30-
"jsonwebtoken": "^8.5.1",
31-
"memory-cache": "^0.2.0",
32-
"mongoose": "^5.7.14",
33-
"multer": "^1.4.2",
34-
"passport": "^0.4.0",
35-
"passport-local": "^1.0.0",
36-
"q": "^1.5.1",
37-
"qrcode": "^1.4.4",
38-
"winston": "^2.4.4"
39-
},
40-
"devDependencies": {
41-
"@types/express": "^4.17.2",
42-
"@types/google-cloud__storage": "^1.7.2",
43-
"@types/mongodb": "^3.3.12",
44-
"@types/mongoose": "^5.5.32",
45-
"@types/multer": "^1.3.10",
46-
"apidoc": "^0.17.7",
47-
"chai": "^4.2.0",
48-
"chai-http": "^4.3.0",
49-
"eslint": "6.7.2",
50-
"eslint-config-prettier": "6.7.0",
51-
"eslint-plugin-prettier": "3.1.1",
52-
"mocha": "^6.2.2",
53-
"nodemon": "^1.19.4",
54-
"prettier": "1.19.1"
55-
}
2+
"name": "hackerAPI",
3+
"version": "1.6.2",
4+
"private": true,
5+
"scripts": {
6+
"start": "DEBUG=hackboard:* NODE_ENV=development nodemon --ignore gcp_creds.json ./bin/www.js",
7+
"deploy": "NODE_ENV=deployment node ./bin/www.js",
8+
"debug": "DEBUG=hackboard:* NODE_ENV=deployment nodemon --ignore gcp_creds.json ./bin/www.js",
9+
"test": "DEBUG=hackboard:* NODE_ENV=test mocha --reporter spec tests/**.js --exit",
10+
"seed": "NODE_ENV=development node ./seed/index.js",
11+
"docs": "apidoc -i ./routes -o ./docs/api/",
12+
"format": "prettier --write '**/*.js'",
13+
"lint": "eslint --fix '**/*.js'"
14+
},
15+
"engines": {
16+
"node": "10.17.0"
17+
},
18+
"dependencies": {
19+
"@google-cloud/logging-winston": "^0.11.1",
20+
"@google-cloud/storage": "^3.5.0",
21+
"@sendgrid/mail": "^6.4.0",
22+
"bcrypt": "^3.0.7",
23+
"cookie-parser": "~1.4.4",
24+
"cookie-session": "^2.0.0-beta.3",
25+
"cors": "^2.8.5",
26+
"cryptiles": "^4.1.3",
27+
"debug": "~4.1.1",
28+
"dotenv": "^8.2.0",
29+
"express": "~4.17.1",
30+
"express-validator": "^6.3.0",
31+
"express-winston": "^2.6.0",
32+
"handlebars": "^4.5.3",
33+
"jsonwebtoken": "^8.5.1",
34+
"memory-cache": "^0.2.0",
35+
"mongoose": "^5.7.14",
36+
"multer": "^1.4.2",
37+
"passport": "^0.4.0",
38+
"passport-local": "^1.0.0",
39+
"q": "^1.5.1",
40+
"qrcode": "^1.4.4",
41+
"winston": "^2.4.4"
42+
},
43+
"devDependencies": {
44+
"@types/express": "^4.17.2",
45+
"@types/google-cloud__storage": "^1.7.2",
46+
"@types/mongodb": "^3.3.12",
47+
"@types/mongoose": "^5.5.32",
48+
"@types/multer": "^1.3.10",
49+
"apidoc": "^0.17.7",
50+
"chai": "^4.2.0",
51+
"chai-http": "^4.3.0",
52+
"eslint": "6.7.2",
53+
"eslint-config-prettier": "6.7.0",
54+
"eslint-plugin-prettier": "3.1.1",
55+
"mocha": "^6.2.2",
56+
"nodemon": "^1.19.4",
57+
"prettier": "1.19.1"
58+
}
5659
}

0 commit comments

Comments
 (0)