github-deployments
Shows Massdriver deployments as GitHub Deployments in the repository that holds the code of an instance.
The repository comes from the github_repo attribute, in the form owner/name. Massdriver attributes are set on
projects, environments, and components, and every instance below them gets them. Declare github_repo as a
custom attribute at the component scope, with one value for each repository, and set it on each component.
For each Massdriver deployment, the automation creates one GitHub deployment and adds a status at each step:
| Massdriver event | GitHub deployment status |
|---|---|
deployment.started | in_progress |
deployment.completed (PROVISION) | success |
deployment.completed (DECOMMISSION) | inactive |
deployment.failed | failure |
deployment.aborted | error |
PLAN deployments are skipped.
- The GitHub environment is the Massdriver environment, such as
prod. Setgithub.environment_nametoproject-environmentto useapi-prodinstead. - The ref is the value of the
github_refattribute. Without it, the ref is the default branch of the repository. - The GitHub deployment has the task
massdriverand a payload withmassdriver_deployment_id,instance,bundle, andaction. - Each status links to the deployment in the instance's history in Massdriver.
- GitHub does not merge the default branch into the ref and does not wait for commit checks, because the deployment already ran.
Results in the stash​
With MASSDRIVER_API_KEY set, the automation writes the commit that GitHub resolved the ref to, for each
Massdriver deployment:
| Key | Stash | Label | Value |
|---|---|---|---|
md/v1/source | The deployment | Source | {"repo": "acme/api", "ref": "main", "commit": "a41c9e2...", "url": "https://github.com/acme/api/commit/a41c9e2..."}. url is left out when github.api_url is neither github.com nor a GitHub Enterprise Server /api/v3 URL. |
Entries in a deployment's stash are immutable. When Massdriver sends an event again, the first value stays.
A failed write is logged at debug and never fails the event, so Massdriver does not send it again.
Without MASSDRIVER_API_KEY, the automation does not call the Massdriver API.
Settings​
Every key is optional. An unknown key stops the automation at start. The bundle's Settings params have the
keys of the config file, except github.token_env: the bundle always passes the token as GITHUB_TOKEN. The full
commented file is
config.example.yaml.
| Key | Default | |
|---|---|---|
github.api_url | https://api.github.com | For GitHub Enterprise Server, https://<host>/api/v3. |
github.token_env | GITHUB_TOKEN | The variable that holds the GitHub token. |
github.repo_attribute | github_repo | The instance attribute that names the repository, as owner/name. |
github.ref_attribute | github_ref | The instance attribute that names the ref. |
github.environment_name | environment | environment (such as prod) or project-environment (such as api-prod). |
massdriver.app_url | https://app.massdriver.cloud | The Massdriver UI, for the status links. |
results.prefix | md/v1 | The start of the result keys. |
Secrets​
| Variable | |
|---|---|
GITHUB_TOKEN | Required, or the variable that github.token_env names. A GitHub token with the Deployments: write and Metadata: read repository permissions (fine-grained), or the repo_deployment scope (classic). |
MASSDRIVER_SIGNING_SECRET is required. MASSDRIVER_API_KEY turns on the stash results and needs
MASSDRIVER_ORGANIZATION_ID. These and the other shared variables are in the
common settings.
Permissions​
Without MASSDRIVER_API_KEY, none. With it, the service account needs stash:write on the instances. The bundle
always sets MASSDRIVER_API_KEY, so deployed with the bundle, the service account needs stash:write and
organization:manageEventDestinations.
Host​
The bundle serves the automation at Ingress > Host. /hooks/massdriver must be public. See
Deploy for the platform details.
Event destination​
The bundle creates a destination for deployment.started, deployment.completed, deployment.failed, and
deployment.aborted, with a condition that drops PLAN deployments and instances without the repository
attribute. The condition uses github.repo_attribute.
To create it yourself:
mass event destination create \
--name github-deployments \
--url https://github-deployments.example.com/hooks/massdriver \
--event-type deployment.started \
--event-type deployment.completed \
--event-type deployment.failed \
--event-type deployment.aborted \
--condition '.data.metadata.deployment_action != "PLAN" and (.data.attributes.github_repo // "") != ""'
If you change github.repo_attribute, change github_repo in the condition too.
Copy the signing secret from the destination into MASSDRIVER_SIGNING_SECRET.
Run​
docker run -p 8080:8080 \
-v "$PWD/config.yaml:/etc/massdriver-automations/config.yaml:ro" \
-e MASSDRIVER_SIGNING_SECRET=whsec_... \
-e GITHUB_TOKEN=github_pat_... \
ghcr.io/massdriver-cloud/massdriver-automations:0.3 run github-deployments
Limits​
- The automation handles one event at a time, so a
startedand acompletedevent that arrive together make one GitHub deployment. - It remembers the GitHub deployment of each Massdriver deployment in memory. After a restart, it finds the
deployment in the 100 newest
massdriverdeployments of the environment. Run one replica. - A
startedevent that arrives after the deployment ended adds no status. - A GitHub error returns
500, so Massdriver sends the event again. - Custom attribute keys allow only letters, digits, and underscores, so the keys use underscores. A custom attribute has a fixed list of values. Add each repository and ref to that list.
- GitHub marks older successful deployments in the same environment as inactive. Two components that use one
repository and one environment replace each other's active deployment. Use separate repositories, or set
github.environment_name: project-environmentwhen the components are in different projects. - Authentication is by token. GitHub App authentication is not supported.