A simplified PR bot that creates github deployments
The base command are:
<botCommand> help
<botCommand> deploy <microservice> to <env>
Future development should support:
<botCommand> status
to get the status of environments for a pull request<botCommand> cancel <microservice> to <env>
to abort a deployment to an environment
This is a Github App and requires enough access in your organization/repo to install it.
- Firstly create a Github App in your organization by following these instructions. Depending on whether you are testing this for local development or setting up a production server you will need to take additional steps as described below.
The Github App will require the following permissions at a minimum to do its work. If you add more capabilities to the bot you will first need to update permissions for the Github App and then have the repository accept the permission changes (you can do this by navigating to your organizations installations page and configuring the github app).
The following permissions are required:
Object | Permission |
---|---|
Deployments | Read & Write |
Contents | Read |
Issues | Read & Write |
Pull Requests | Read & Write |
The following events are required:
Event |
---|
Issue Comment |
Pull Request |
- Create the Github App so that you can retrieve the app id and other important information to populate the
.env
file - In the local project directory copy env vars
cp .env.example .env
- Install packages
npm install
- Run dev server
npm run dev
- In order to accept webhook requests you will need to register a
smee.io
channel as described in the probot getting started docs
Please check out the Readme
The App is configured by src/config/index.json
. This is transpiled to lib/config/index.json
on prod runtime. This can be overwritten via a volume mounted file if need be for runtime config changes.
environments: string[]
: This is a list of the valid github deployment environments your app supports. This will prevent deploy commands to unsupported environments from triggering a workflow. The available environments are production, staging, qa, development. Take a look at github deployment docs for more info.environmentSynonyms: object
: To make deploy commands easier to write you can config a table of synonyms that should map to a valid deployment. For example:
{
"environmentSynonyms": {
"prod": "production"
}
}
-
validGithubRoles: string[]
: This is a list of valid github permission roles a user can have. This will validate that a command issued by a user will run. By default the valid roles are['maintain', 'admin', 'write']
-
botCommand: string
: This is the issuing command that the bot will look for to prepend every command. This can be any single word. Recommend prepending a/
to the command to seperate it from english text. Defaults to/deploy-tron
-
microservices: string[]
: This is a list of 'microservices' that your repositories codebase supports. This passed into any create deployment as apayload
which will allow your ci/cd tool of choice to filter github deployments. The microservice list is also used to validate the deploy commanddeploy <microservice> to <env>
-
requiredEnvironments: { [env]: string[] }
: This creates dependencies between environments for a github ref/branch. For example you can configure that thetest
environment is only deployable if the sameref/branch
was deployed todev
first. It's usage:
{
"requiredEnvironments": {
"development": [],
"staging": ["development"],
"production": ["staging"]
}
}
take note that required environments uses the valid github deployment environment nomenclature and not your synonyms.
-
environmentsThatAllowConcurrentDeploys: string[]
: A list of github deployment environments that allow requests from different refs/branches to create deployments to the same environment. For example in a PR based pipeline every PR may deploy code to a development environment. Usage is:"environmentsThatAllowConcurrentDeploys": ["development"]
-
maxDeploymentsToLookupForPending: int
: By default when checking for previous pending deployments for a ref/branch. Only the last 10 deployments are checked. The others are assumed to be inactive. This can be configured to look further back if needed. -
requiredContexts: { [env]: string[] }
: This is a environment mapping to therequired_contexts
property of a github deployment.
If you have suggestions for how deploy-tron could be improved, or want to report a bug, open an issue! We'd love all and any contributions.
For more, check out the Contributing Guide.
ISC © 2020 Patrick Simonian [email protected]