Skip to content

Commit

Permalink
Merge pull request #10 from ecobee/revert-9-revert-8-feature/add-supp…
Browse files Browse the repository at this point in the history
…ort-for-gcp

Feature/add support for gcp (for real this time)
  • Loading branch information
nonAlgebraic authored Apr 10, 2019
2 parents 82d23bf + b14ca2f commit 0c7743d
Show file tree
Hide file tree
Showing 7 changed files with 304 additions and 127 deletions.
8 changes: 7 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ WEBHOOK_PROXY_URL=
PRIVATE_KEY=

# Get this api key from your SendGrid account.
SENDGRID_API_KEY=
SENDGRID_API_KEY=

# Google Cloud Platform project ID
GCP_PROJECT=consumer-web-dev-208518

# Credentials file for the df GCP API
GCP_CREDENTIALS=~/.gcloud/keyfile.json
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This is the repository for the **Release Buddy** Github bot. Release Buddy is in

### Application structure

`handler.js`: When you deploy this to a lambda on AWS, handler.js will be the official entry point.
`handler.js`: When you deploy this to a cloud function on GCP, handler.js will be the official entry point.

`index.js`: handler is really just a wrapper around the index file, which serves the bulk of the application code. When you run the application locally, it is being served by index.js.

Expand All @@ -26,29 +26,26 @@ yarn install
yarn start
```

- Visit the url that is created when you run your setup and follow the instructions to setup your github app. The webhook url can be your local smee url for now, but you will eventually want to replace this with the lambda url once you deploy it to AWS.
- Visit the url that is created when you run your setup and follow the instructions to setup your github app. The webhook url can be your local smee url for now, but you will eventually want to replace this with the GCF url once you deploy it to GCP.

- Add the required environment variables from the `.env.example` file to a `.env` file in the root folder.

- Setup serverless to work with your AWS account. See the [Quick Start](https://serverless.com/framework/docs/providers/aws/guide/quick-start#pre-requisites) guide.
- Setup serverless to work with your GCP account. See the [Quick Start](https://serverless.com/framework/docs/providers/google/guide/quick-start#pre-requisites) guide.

- Add the required environment variables to your [AWS Parameter Store](https://us-east-2.console.aws.amazon.com/systems-manager/parameters/create), so they can be accessed from the lambda once it has been deployed. You can find the references to these environment variables in the `serverless.yml` file under `functions` > `environment`. They should be entered into Parameter store using that same format (ex: `release-buddy-webhook-secret`).
- Deploy the function using `yarn deploy`.

- Deploy the lambda using `yarn serverless deploy`.

- Update the webhook url Github App you created earlier in your [Developer settings](https://github.com/settings/apps). Select the app name you created, and edit the **Webhook URL** field to the AWS lambda field you deployed.
- Update the webhook url Github App you created earlier in your [Developer settings](https://github.com/settings/apps). Select the app name you created, and edit the **Webhook URL** field to the URL of the GCF you deployed.

### Using Release Buddy in your project

Once you have setup the Release Buddy AWS lambda server and created the Github App, you can add Release Buddy to your Github projects following the directions below.
Once you have setup the Release Buddy GCF and created the Github App, you can add Release Buddy to your Github projects following the directions below.

- Add a `releaseBuddy.config.json` file to the root of your projects. See the configuration details below.

``` json
```json
{
"teamName": "Consumer Website Team", // Enter the name of your team.
"slackSettings": {

"enabled": true, // enable/disable the Slack notifier
"slackWebhookUrl": "https://hooks.slack.com/your-slack-webhook-url-here", // your Slack webhook url
"userName": "Release Buddy", // Slackbot user name
Expand All @@ -57,8 +54,8 @@ Once you have setup the Release Buddy AWS lambda server and created the Github A
"shipEmojis": ":ship: :ship_it_parrot: :rocket: :ship_it_parrot: :ship:" // These will appear in the slack message to add some pizazz to your release message
},
"emailSettings": {
"enabled": true, // enable/disable the email notifier
// Sendgrid api docs for formatting: https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html
"enabled": true, // enable/disable the email notifier
// Sendgrid api docs for formatting: https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html
"to": {
"name": "Release Buddy", // Replace with any name.
"email": "[email protected]" // Replace with email of your choice.
Expand Down
4 changes: 2 additions & 2 deletions handler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// handler.js
const { serverless } = require('@probot/serverless-lambda')
const appFn = require('./')
const { serverless } = require('@probot/serverless-gcf')
const appFn = require('./index')

module.exports.probot = serverless(appFn)
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,26 @@
"github",
"probot-app"
],
"main": "handler.js",
"scripts": {
"simulate": "yarn probot simulate release test/fixtures/release.published.json ./index.js",
"dev": "nodemon",
"start": "probot run ./index.js",
"lint": "standard --fix",
"test": "jest",
"test:watch": "jest --watch --notify --notifyMode=change --coverage"
"test:watch": "jest --watch --notify --notifyMode=change --coverage",
"deploy": "node_modules/.bin/dotenv serverless deploy"
},
"dependencies": {
"@probot/serverless-lambda": "^0.2.0",
"@probot/serverless-gcf": "^0.2.0",
"@sendgrid/mail": "^6.3.1",
"dotenv": "^7.0.0",
"dotenv-cli": "^2.0.0",
"markdown": "^0.5.0",
"node-fetch": "^2.2.0",
"probot": "^7.2.0",
"remove-markdown": "^0.3.0",
"serverless-google-cloudfunctions": "^2.3.2",
"slackify-markdown": "^1.0.4"
},
"devDependencies": {
Expand All @@ -37,7 +42,7 @@
"eslint-plugin-jsx-a11y": "^6.1.1",
"eslint-plugin-react": "^7.11.0",
"jest": "^22.4.3",
"nodemon": "^1.17.2",
"nodemon": "^1.18.10",
"prettier": "^1.14.2",
"serverless": "^1.34.1",
"serverless-offline": "^3.25.17",
Expand Down
26 changes: 15 additions & 11 deletions serverless.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
service: release-buddy

package:
exclude:
- ./test/**

provider:
name: aws
runtime: nodejs8.10
region: us-east-1
name: google
runtime: nodejs8
project: ${env:GCP_PROJECT}
credentials: ${env:GCP_CREDENTIALS}

plugins:
- serverless-google-cloudfunctions
- serverless-offline

functions:
release-buddy:
handler: handler.probot
handler: probot

environment:
WEBHOOK_SECRET: ${ssm:release-buddy-webhook-secret}
PRIVATE_KEY: ${ssm:release-buddy-private-key}
SENDGRID_API_KEY: ${ssm:release-buddy-sendgrid-api-key}
APP_ID: ${ssm:release-buddy-app-id}
WEBHOOK_SECRET: ${env:WEBHOOK_SECRET}
PRIVATE_KEY: ${env:PRIVATE_KEY}
APP_ID: ${env:APP_ID}
SENDGRID_API_KEY: ${env:SENDGRID_API_KEY}
LOG_FORMAT: json

events:
- http:
path: /probot
method: post
- http: /probot
2 changes: 1 addition & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { Application } = require('probot')
// Requiring our app implementation
const myProbotApp = require('..')
const myProbotApp = require('../index')

const releasePublishedPayload = require('./fixtures/release.published.json')
const { slackAndEmail, emailOnly, slackOnly } = require('./fixtures/releaseBuddy.config')
Expand Down
Loading

0 comments on commit 0c7743d

Please sign in to comment.