Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support running on Zeit's Now #233

Merged
merged 1 commit into from
Apr 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ node_modules
*.dat
out
.env
.next
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
language: node_js
node_js: 9
cache: yarn

after_success:
- test $TRAVIS_BRANCH = "master" && test $TRAVIS_PULL_REQUEST = "false" && yarn deploy:staging

env:
global:
secure: LdbIy592OAfSfubnjPXhGqBp2xrt7PQBd7ml0j+2RT6Om+hU1zEhsdCugRyA0HvjGAeSLfQ9WfwjRjQS6oDQ2aoGjSXlE5qIS2IkaOGC8QofjJITGrfr4p10b0EvmyKAjutjfKrxmpBKuF+jvk0EEec/bOdn2+HmrV0l2lsyCbh26Cg5rd66JhSZ7KYZOuMtDPHXV+3lFkCKrQBTStjovoKxGvsCZk6o6V3tePEcs8YvqGn2a2eoWcO0Es//2sznH8qx84q2tMD2KXgP24MH6Uuk2/x/nndikI/EO+P9KUWMgp6GefWfgJXEh1mbciwmGR8i3hMqqdav/K9HTuJcuoYoeqSa5zuWLIdCkP0e7ObUO1TME0808w6kVkX2KnL/JgYQnVEb9SvbToVrKqwB0gEjky+3pj0bsNnQNLCjynGVg7PZwrxJlLmtDGHboyUk1xNlN2mPJ968S3rmiMiN549tkHc2ai6on7gTKCHaiVUoJZnZbBL2nHIUBTd5+wBzR4jqUZCucvrkYf2PC7R/tOInN+1R8hJ3S6ml8CWeBTVPqR6C26w/TgeSU0anIBm1yO8jwCpTR7CHHYL1I7A/U/krpoyfJGUYw6FsIvytYrn9LlSC+KbdeuE0SqQ//pIsFOb/OyJysbPMPoxfZp12+Qrx8EZAeiHC4ccN8nLabDg=
24 changes: 17 additions & 7 deletions docs/env/staging.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@

**Setup:**

* heroku: https://dashboard.heroku.com/apps/peril-danger-staging
* Uses a mongo instance: [mLab](https://dashboard.heroku.com/apps/peril-danger-staging/resources?justInstalledAddonServiceId=3dfb031f-23f4-4123-856f-5cb95ecdadc9)
* Now.js: https://zeit.co/teams/peril
* Uses a mongo instance: [Mongo Atlas](https://cloud.mongodb.com/v2/5adafbc80bd66b23d635b2bb#clusters)
* github app: https://github.com/organizations/danger/settings/apps/danger-in-peril
* hyper, auth'd as me
* hyper func: `hyper func inspect danger-peril-staging` running locally,
* hyper, auth'd as me: https://console.hyper.sh
* hyper func: `hyper func inspect peril-staging` running locally.

---

**Scripts:**

* Logs: `heroku logs --app peril-danger-staging --tail`
* Creating the hyper func: `hyper func create --size s1 --name danger-peril-staging dangersystems/peril node out/scripts/runner/index.js`
* Updating the container for a func: `hyper pull dangersystems/peril:runner` - it will call with the new peril docker image on the next func run
* Logs: `now logs staging-api.peril.systems -T peril`.
* Creating the hyper func:
`hyper func create --size s3 --name peril-staging dangersystems/peril node out/scripts/runner/index.js`.
* Updating the container for a func: `hyper pull dangersystems/peril:runner` - it will call with the new peril docker
image on the next func run. This is handled automatically by Peril.

---

**Tricky Bits**

* Secrets vars are a bit weird in now. You have team-wide secrets, that are then re-used in the env vars by alises.
* Adding the pem to now is hard, I ended up making a file copy of both private and public, then doing this:
`now secrets -T peril add stag_private_github_signing_key "(cat key.pem | base64)"`.
26 changes: 26 additions & 0 deletions now.staging.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "peril-api",
"alias": ["staging-api.peril.systems"],
"type": "npm",
"public": false,
"env": {
"PERIL_BOT_USER_ID": "@stag_peril_bot_user_id",
"PERIL_INTEGRATION_ID": "@stag_peril_integration_id",
"PERIL_WEBHOOK_SECRET": "@stag_peril_webhook_secret",

"PRIVATE_GITHUB_SIGNING_KEY": "@stag_private_github_signing_key",
"PUBLIC_GITHUB_SIGNING_KEY": "@stag_public_github_signing_key",

"HYPER_FUNC_NAME": "@stag_hyper_func_name",
"HYPER_SECRET_KEY": "@stag_hyper_secret_key",
"HYPER_ACCESS_KEY": "@stag_hyper_access_key",

"MONGODB_URI": "@stag_mongodb_uri",

"PUBLIC_FACING_API": "true",
"PUBLIC_API_ROOT_URL": "staging-api.peril.systems",
"PUBLIC_WEB_ROOT_URL": "api.peril.systems",
"GITHUB_CLIENT_ID": "@stag_github_client_id",
"GITHUB_CLIENT_SECRET": "@stag_github_client_secret"
}
}
25 changes: 15 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@
"scripts": {
"start": "node out/index.js",
"compile": "tsc -watch -p ./",
"build": "yarn tsc",
"postinstall": "yarn build; if [ $DATABASE_JSON_FILE ]; then yarn run setup; fi",
"test": "jest && yarn lint",
"test:watch": "jest --watch",
"lint": "tslint source/**/**/**.ts",
"build": "tsc",
"type-check": "tsc --noEmit --pretty",
"types:json": "ts-node source/scripts/json-types.ts && tslint source/**/*.ts --fix",
"prettier": "prettier",
"prettier-project": "prettier --write 'source/**/*.{ts,tsx,md,json}'",
"postinstall": "yarn build; if [ $DATABASE_JSON_FILE ]; then yarn run setup; fi",

"test": "jest && tslint source/**/**/**.ts",
"generate:types:json": "ts-node source/scripts/json-types.ts && tslint source/**/*.ts --fix",

"setup": "yarn run setup:plugins && yarn run setup:env",
"setup:env": "node out/scripts/setup-env.js",
"setup:plugins": "node out/scripts/setup-plugins.js",

"runner": "node out/runner/index.js",

"deploy:staging":
"now deploy --local-config now.staging.json --team peril --token $NOW_TOKEN; yarn deploy:staging:alias",
"deploy:staging:alias": "now alias --local-config now.staging.json --team peril --token $NOW_TOKEN",

"precommit": "lint-staged; yarn build;",
"prepush": "jest; yarn danger local --dangerfile dangerfile.lite.ts",
"runner": "node out/runner/index.js"
"prepush": "jest; yarn danger local --dangerfile dangerfile.lite.ts"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -106,6 +110,7 @@
"husky": "^0.14.0",
"lint-staged": "^7.0.0",
"mockingoose": "^2.9.1",
"now-travis": "^1.2.0",
"prettier": "^1.12.1",
"tslint-config-prettier": "^1.10.0"
},
Expand Down
27 changes: 21 additions & 6 deletions source/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,32 @@ function validates(keys: string[]) {
})
}

export let privateKey = getEnv("PRIVATE_GITHUB_SIGNING_KEY") && getEnv("PRIVATE_GITHUB_SIGNING_KEY").trim()
// Now has issues with putting in complex vars, they want it base64'd
// so if this var doesn't have the RSA header, then convert it
if (!privateKey.includes("-----BEGIN RSA PRIVATE KEY")) {
privateKey = new Buffer(privateKey, "base64").toString()
if (!privateKey.includes("-----BEGIN RSA PRIVATE KEY")) {
throw new Error("Expected PRIVATE_GITHUB_SIGNING_KEY to be a private key after being base64'd, got " + privateKey)
}
}

export let publicKey = getEnv("PUBLIC_GITHUB_SIGNING_KEY") && getEnv("PUBLIC_GITHUB_SIGNING_KEY").trim()
// This can be null on single-org installations
if (publicKey && !publicKey.includes("-----BEGIN PUBLIC")) {
publicKey = new Buffer(publicKey, "base64").toString()
if (!publicKey.includes("-----BEGIN PUBLIC")) {
throw new Error("Expected PUBLIC_GITHUB_SIGNING_KEY to be a public key after being base64'd, got " + publicKey)
}
}

/** Private key for the app
*
* To set it on heroku: heroku config:add PRIVATE_GITHUB_SIGNING_KEY="$(cat thekey.pem)"
*/
export const PRIVATE_GITHUB_SIGNING_KEY =
getEnv("PRIVATE_GITHUB_SIGNING_KEY") && getEnv("PRIVATE_GITHUB_SIGNING_KEY").trim()

export const PRIVATE_GITHUB_SIGNING_KEY = privateKey
/** Used only for verifying JWT keys, so is not useful for non-public */
export const PUBLIC_GITHUB_SIGNING_KEY =
getEnv("PUBLIC_GITHUB_SIGNING_KEY") && getEnv("PUBLIC_GITHUB_SIGNING_KEY").trim()

export const PUBLIC_GITHUB_SIGNING_KEY = publicKey
/**
* The ID for the GitHub integration
*/
Expand Down
Loading