Skip to main content

Automations

An automation is a service that acts on Massdriver events. It receives events from an HTTP event destination, verifies the Standard Webhooks signature, and calls the Massdriver API as a service account, or calls another service such as Slack or GitHub.

The automations are open source in massdriver-automations. All of them ship in one image, one automation per container:

shell
docker run -p 8080:8080 \
-v "$PWD/config.yaml:/etc/massdriver-automations/config.yaml:ro" \
-e MASSDRIVER_ORGANIZATION_ID=acme \
-e MASSDRIVER_API_KEY=md_... \
-e MASSDRIVER_SIGNING_SECRET=whsec_... \
ghcr.io/massdriver-cloud/massdriver-automations:0.3 run autodeploy-downstream

AUTOMATION=<name> works in place of run <name>. list prints every automation. Images are multi-arch (linux/amd64, linux/arm64), run as non-root on distroless, and carry an SBOM and a signed build provenance attestation.

AutomationEventsDoes
audit-archiverevery eventArchives every event, unchanged, in S3, Splunk, Datadog, or on disk.
autodeploy-downstreamdeployment.completedDeploys opted-in dependents when an instance deploys.
bundle-scannerrepo.publishedScans each new bundle version with Trivy and Checkov. Uses the -scanner image tag.
chaos-monkeydeployment.completed, deployment.failed, deployment.aborted, deployment.rejectedSends random presets, merged presets, mutated params, and gibberish to the instances that match its attributes, as proposals, plans, or deployments.
cost-explorerdeployment.completedServes a dashboard of instance costs that you can group, filter, and chart over time.
driftdeployment.completed, deployment.failed, deployment.abortedPlans instances on a schedule, alerts Slack about drift, and can re-apply the deployed configuration.
freeze-guardgroup.created, group.updated, group.deletedAdds deny policies for deployment actions to groups during change freeze windows.
github-deploymentsdeployment.*Shows Massdriver deployments as GitHub Deployments.
leaderboardnone; reads GitHub on an intervalRanks the authors of GitHub pull requests and writes the top players to environment leaderboards.
log-resultsdeployment.completed, deployment.failedReads each finished deployment's logs with your rules, such as plan changes, Helm releases, and Checkov findings, and writes the results to the deployment's stash.
oncallnone; reads PagerDuty or incident.io on an intervalWrites who is on call now, by escalation level, to environment on-call cards.
params-to-gitdeployment.completedWrites the params of each successful deployment to params.json in a GitHub repository, by push or pull request.
pr-syncnone; reads GitHub on an intervalWrites the pull requests of a project's GitHub repositories to the project's stash, with their review, check, and merge state.
proposal-chatopsdeployment.proposed, deployment.approved, deployment.rejectedApprove or reject proposed deployments from Slack.
release-notesrepo.publishedPosts new bundle versions, and the instances that can upgrade, to Slack and Teams.
rollback-on-failuredeployment.failedRolls an opted-in instance back to its last completed deployment when a deployment fails.
routerconfigured per routeRuns HTTP requests, commands, and Massdriver API calls for the events that match configured routes. Commands use the -scripts image tag.
sandbox-on-joingroup_membership.*, deployment.completedForks a sandbox environment for each new group member, and removes it when they leave.
scorecardsdeployment.completed, deployment.failed, deployment.aborted, deployment.rejected, alarm.*, alarm_state.created, instance.*, repo.published, group_membership.*, stash_entry.*Scores instances against scorecards of jq checks over stash results and the API, and rolls the scores up to environments and projects.
stale-proposalsnone; reads the API on a schedulePosts a digest of proposed deployments that wait too long for approval, with Slack mentions, and can reject the oldest.
stash-syncnone; reads metrics on an intervalCopies CloudWatch and Prometheus metrics into stash entries for health, usage, traffic, and banner widgets.
statuspagealarm.*, alarm_state.created, deployment.*, instance.*, stash_entry.*Serves a public status page from alarms, instances, deployments, and stash health and banners.
upgrade-trainrepo.published, deployment.completed, deployment.failed, deployment.aborted, deployment.rejectedMoves each new bundle version through stages of instances, such as dev, staging, and prod, with a soak time and an alarm check between stages.

Each automation's page or README has its settings, secrets, permissions, and the mass event destination create command that sends it only the events it uses. The telehealth example has a full set of configs for one company.

Build your own with router​

When no automation does what you need, configure a route in router. A route selects events by type, attributes, and an expression, then runs HTTP requests, commands, and Massdriver API calls in order. Routes are YAML, not Go.

How an automation acts​

An automation has the access of its service account and nothing more. Policies decide what the service account can do in each environment, the same as for a person. An automation that proposes a deployment in an environment with separation of duty cannot approve its own proposal, so a person approves it. A freeze window denies the service accounts in frozen groups like the people in them.

Automations that opt instances in, such as autodeploy-downstream and rollback-on-failure, read an attribute such as autodeploy=true. Set it on a project, an environment, or a component, and every instance below it gets it. The key must be a declared custom attribute before you set it.

Automations that record results write them to the stash of a deployment, instance, environment, or project. Their service accounts need stash:write.

Deploy​

Each automation has a Kubernetes bundle, massdriver-<automation>, and an Amazon ECS bundle, massdriver-<automation>-ecs. Deploy one instance per automation, each with its own service account. Refer to Deploy the automations.

Common settings​

VariableDefault
MASSDRIVER_SIGNING_SECRETRequired. The whsec_ signing secret of the event destination.
MASSDRIVER_ORGANIZATION_IDYour organization's identifier. Required by automations that call the API.
MASSDRIVER_API_KEYAn md_ access token of a service account. Required by automations that call the API.
MASSDRIVER_URLhttps://api.massdriver.cloudThe URL of your Massdriver installation.
CONFIG_FILE/etc/massdriver-automations/config.yamlThe automation's config file.
PORT8080
LOG_FORMATautoauto, json, or text. auto writes colored text when stderr is a terminal and JSON otherwise. NO_COLOR turns off the colors.
LOG_LEVELinfodebug, info, warn, or error.

Every automation receives events on POST /hooks/massdriver and answers health checks on GET /healthz.

Config file​

Environment variables hold credentials and deployment wiring only. Every other setting is in one YAML config file per automation, read once at start. Each automation has a commented config.example.yaml in its directory.

An unknown key, a value of the wrong type, or a value that does not validate stops the automation with one invalid config log record. The record names the file, the line or the key, and the problem, never the value. An automation whose config needs no setting starts without the file.

A setting that needs a credential names the environment variable that holds it, such as token_env: GITHUB_TOKEN. A config file never holds a credential.

Logs​

Each log record is one line on stderr. Every record has time, level, msg, automation, and version. Records about an event also have event_id and event_type. Each request writes one request record; health checks write theirs at debug. While a trace span is active, records also have trace_id and span_id.

json
{"time":"2026-11-25T22:05:42.539271Z","level":"INFO","msg":"request","automation":"router","version":"v1.4.0","method":"POST","path":"/hooks/massdriver","status":204,"duration_ms":10.42,"bytes":0,"event_id":"evt-local-1","event_type":"deployment.completed"}

Tracing​

Every automation can send OpenTelemetry traces to an OTLP endpoint. Tracing is off until OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_TRACES_ENDPOINT is set.

VariableDefault
OTEL_EXPORTER_OTLP_ENDPOINTThe base URL of an OTLP collector, such as http://otel-collector:4318. Spans go to <endpoint>/v1/traces.
OTEL_EXPORTER_OTLP_TRACES_ENDPOINTThe full URL for spans, in place of the base URL.
OTEL_EXPORTER_OTLP_PROTOCOLhttp/protobufhttp/protobuf or grpc. With grpc, the endpoint is the collector's gRPC port, such as http://otel-collector:4317.
OTEL_EXPORTER_OTLP_HEADERSHeaders for the collector, such as authorization=Bearer abc123.
OTEL_SERVICE_NAMEmassdriver-automations
OTEL_RESOURCE_ATTRIBUTESMore resource attributes, such as deployment.environment.name=prod.

The other standard OTEL_* variables of the OTLP exporter, the batch span processor, and the sampler also apply. OTEL_SDK_DISABLED=true or OTEL_TRACES_EXPORTER=none turns tracing off. Each span has the resource attributes service.name, service.version, and automation.

  • Each request gets a server span, such as POST /hooks/massdriver, with http.request.method, http.route, and http.response.status_code. /healthz gets none. The span of an event also has cloudevents.event_id, cloudevents.event_type, and cloudevents.event_subject. A handler error marks the span as failed.
  • Each outgoing HTTP request gets a client span. A Massdriver API call is named for its operation, such as graphql Groups, and a Slack Web API call for its method, such as slack chat.postMessage. Other calls are named <method> <host>. url.full is the scheme and host only. Spans never hold variables, bodies, or headers.

The span of an event continues the trace in the event's traceparent and tracestate attributes (CloudEvents distributed tracing), then in a traceparent header, and otherwise starts a trace. Massdriver sends both, so an automation's spans join the trace of the work that caused the event. Each outgoing request sends a traceparent header. The Massdriver API starts its own trace with a link to the calling span.

Slack​

One Slack app serves every automation:

  1. Create a Slack app from scratch at api.slack.com/apps.
  2. Under OAuth & Permissions, add the bot scopes chat:write and chat:write.public. Without chat:write.public, invite the app to each channel it posts to.
  3. For proposal-chatops, under Interactivity & Shortcuts, turn on interactivity and set the request URL to https://<proposal-chatops host>/slack/interactions.
  4. Install the app in your workspace. Set the bot token (xoxb-...) as SLACK_BOT_TOKEN, and the signing secret from Basic Information as SLACK_SIGNING_SECRET, on each automation that posts.

Each automation posts to slack.channel in its config, and some accept a channel per check, window, or instance. A channel is a name, such as #infra, or a channel ID. Without a channel, an automation does not post to Slack. drift and rollback-on-failure reply in the thread of an alert with its outcome.

AutomationPostsChannel settings
bundle-scannerScan resultsslack.channel
chaos-monkeyWhat each run sent, and how each of its deployments endedslack.channel
driftDrift alerts, the outcome of each resolution in the alert's thread, and run totalsslack.channel, checks[].slack.channel
freeze-guardWindow starts, ends, and liftsslack.channel, windows[].slack.channel
proposal-chatopsProposals with Approve and Reject buttonsslack.channel, slack.channel_attribute
release-notesNew bundle versionsslack.channel
rollback-on-failureRollback notices, and the result of each rollback in the notice's threadslack.channel
stale-proposalsA digest of proposals that wait too long, and the ones it rejectedslack.channel
upgrade-trainEach stage start, soak, and stop, and the end of each runslack.channel, trains[].slack.channel

Incoming webhook​

Without the app, set SLACK_WEBHOOK_URL to an incoming webhook. Every message goes to the webhook's channel, and the channels in the config do nothing; an automation logs one slack channels ignored warning at start when its config names any. A webhook cannot reply in a thread, so a reply is a message of its own. proposal-chatops needs the app, because a webhook cannot update a message or receive a click. When both are set, the bot token wins.

Errors and logs never hold the bot token or the webhook URL.

Run locally​

Run an automation on your computer, and give Massdriver a public URL with a tunnel.

1. Start the automation​

From a clone of the repository:

shell
export MASSDRIVER_ORGANIZATION_ID=acme
export MASSDRIVER_API_KEY=md_...
export MASSDRIVER_SIGNING_SECRET=whsec_... # set after step 3; any whsec_ value works until then
export CONFIG_FILE=automations/autodeploy-downstream/config.example.yaml
go run ./cmd/massdriver-automations run autodeploy-downstream

Or with Docker:

shell
docker run --rm -p 8080:8080 \
-v "$PWD/automations/autodeploy-downstream/config.example.yaml:/etc/massdriver-automations/config.yaml:ro" \
-e MASSDRIVER_ORGANIZATION_ID -e MASSDRIVER_API_KEY -e MASSDRIVER_SIGNING_SECRET \
ghcr.io/massdriver-cloud/massdriver-automations:0.3 run autodeploy-downstream

The automation listens on port 8080. Set PORT to change it.

2. Open a tunnel​

Massdriver refuses a destination URL whose host is a private address. Use a tunnel that prints a public https:// URL and forwards to port 8080, such as ngrok http 8080 or cloudflared tunnel --url http://localhost:8080. Refer to Send events to your computer for more tunnels.

3. Create the event destination​

Use the command on the automation's page, with the tunnel URL and the /hooks/massdriver path:

shell
mass event destination create \
--name autodeploy-downstream-local \
--url https://<tunnel-host>/hooks/massdriver \
--event-type deployment.completed \
--condition '.data.metadata.deployment_action == "PROVISION"'

Copy the signing secret from the destination's Overview tab into MASSDRIVER_SIGNING_SECRET, and restart the automation. Click Send test event on the destination. The automation answers 204 to the event_destination.tested event when the URL and the secret work.

When the tunnel URL changes, update the destination:

shell
mass event destination update <id> --url https://<new-tunnel-host>/hooks/massdriver

Events that arrived while the tunnel was down wait as failed deliveries. Send them again with mass event destination redeliver <id>.

Send an event without Massdriver​

scripts/send-event.sh signs a CloudEvent file the way Massdriver does and posts it. It needs jq, openssl, xxd, and curl.

shell
cat > event.json <<'JSON'
{"specversion":"1.0","id":"4b0b5a8e-0f6c-4a53-9d0c-5a1f4ad5c1c2","type":"deployment.completed",
"subject":"mri:acme:api:prod:database","time":"2026-11-24T05:54:03Z",
"data":{"entity":{"id":"b9dc3d18-19fc-429c-8d36-6753615fe17c","action":"PROVISION"},
"attributes":{"md-instance":"api-prod-database"},
"metadata":{"deployment_action":"PROVISION"}}}
JSON
MASSDRIVER_SIGNING_SECRET=whsec_... scripts/send-event.sh event.json http://localhost:8080/hooks/massdriver

It prints the status code. Each automation drops an event id it has already handled, so change id to send the same event again. To copy real events, run mass event destination preview --event-type <type> -o json.

Write an automation​

For a reaction that needs no code, such as an HTTP request, a script, or one GraphQL call, configure a route in router.

Otherwise, an automation is a Go package that implements one method:

go
type Automation interface {
Handle(ctx context.Context, ev automation.Event) error
}
  • pkg/automation verifies the signature, drops repeated event ids, and calls Handle. Return an error to respond 500, so Massdriver sends the event again. Massdriver waits 10 seconds for a response, so start long work in a goroutine.
  • Implement Routes(mux *http.ServeMux) to serve more routes, such as a callback from Slack or a web page.
  • Read settings with automation.LoadConfig(&cfg). It decodes the file at CONFIG_FILE and refuses unknown keys. Give the config a Validate() error method to check it and fill its defaults. Read only credentials and deployment wiring from the environment.
  • Call other services with automation.HTTPClient(timeout), so the calls are in the event's trace.
  • pkg/slack posts to Slack with the bot token or the webhook. Give the config a slack section of type slack.Config.
  • pkg/massdriver calls the V2 GraphQL API. Put each operation in a .graphql file under queries/ and load it with //go:embed.
  • Export a Definition and add it to automations/registry.go. Set its Test to give the automation a massdriver-automations test <name> command that checks a config against local input.
  • Test with automation.Handler and automation.SignRequest, against httptest fakes of the APIs you call.

autodeploy-downstream is a short, complete example.

pkg/automation, pkg/massdriver, and pkg/slack are importable, so you can build automations in your own repository.