Wow! We now have a way to automatically close Heroku apps after they've been merged in or closed on github.
We use Zappa to deploy a serverless Python lambda function that runs a webhook every time there is a pull request on the Joplin branch.
If a PR on a branch besides "master" or "production" is closed or merged, then the heroku build for that branch will be destroyed, unless that heroku build has an environment variable called "DELETION_PROTECTION" set to a truthy value (preferably 1).
This lambda also runs a scheduled "joplin_cron_clean_up" job every day at midnight. This will delete heroku joplin PR builds that don't have a corresponding open PR and don't have DELETION_PROTECTION enabled. This is to catch clean_up jobs that failed to complete (for example, during race conditions where a PR is merged or closed before the circleci build completes).
To redeploy this lambda function:
- Make sure you've got a valid GITHUB_WEBHOOK_SECRET_TOKEN and HEROKU_KEY in your .env file.
- Install dependencies
Integrate with github
- In the Joplin repo on github, go to Settings > Webhooks.
- Edit or create a new webhook to listen on "pull_request" events.
Here's what you should plug in for the required values:
- Payload URL
- The "Payload URL" is the URL of the lambda function generated by Zappa at the route /postreceive.
- ex: https://[random-string].execute-api.us-east-1.amazonaws.com/staging/postreceive
- The "Secret" can be anything, as long as it's the same value plugged in as your "GITHUB_WEBHOOK_SECRET_TOKEN" environment variable.
- Which events would you like to trigger this webhook?
- Select "Let me select individual events."
- Then choose "Pull requests"
- View logs at https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logStream:group=/aws/lambda/coa-joplin-build-cleanup-staging
- The AWS stack generated by Zappa is called "coa-joplin-build-cleanup-staging"
Wait I don't want you to automatically delete my app
Set an environment variable within your Heroku PR build called "DELETION_PROTECTION" and set it equal to 1.