Skip to main content

autodeploy-downstream

When an instance finishes a PROVISION deployment, deploy each instance that depends on it and has the attribute autodeploy=true. Rules select instances by other attributes, and can propose the deployments for review in place of running them.

Set the attribute on a component to opt that component in across every environment. Set it on an environment or a project to opt in everything below it.

An instance depends on the upstream when one of its dependencies resolves to a resource that the upstream produces. All three sources count:

  • a link on the project blueprint
  • an environment default, in any environment
  • a remote reference, in any project

The automation skips an instance that is not PROVISIONED, so it never creates infrastructure for the first time.

A downstream deploy that completes sends its own deployment.completed event, so changes cascade through the graph one level at a time.

Settings​

KeyDefault
rulesone rule, autodeploy=trueThe rules that select downstream instances.
results.prefixmd/v1The start of the result keys.

Without a config file, or with no rules, one rule named autodeploy=true deploys the downstream instances whose attribute autodeploy is true.

The bundle's Settings params have the same keys as the config file, with two differences:

  • In Dependent attributes (downstream) and Upstream attributes (upstream), each value is a string. Separate values with commas, such as api, web, to match any of them. The bundle turns them into lists.
  • Rules needs at least one rule. Its default is one rule named autodeploy that deploys instances with autodeploy = true. A rule name is lowercase letters, numbers, and hyphens.

The full commented file is config.example.yaml.

Rules​

yaml
rules:
- name: staging-cascade
upstream:
md-environment: staging
downstream:
autodeploy: "true"
md-environment: staging
action: deploy
- name: prod-review
upstream:
md-environment: prod
downstream:
autodeploy: "true"
tier: [frontend, api]
action: propose
FieldDefault
nameRequired. Unique. The logs and the deployment message name the rule.
downstreamRequired. Attributes that the effective attributes of a downstream instance must have.
upstreamAttributes that the upstream's deployment.completed event must have.
actiondeploydeploy runs a PROVISION deployment. propose creates a PROVISION deployment in PROPOSED status, which waits for a person to approve it.

An instance must have every attribute of downstream, and the event must have every attribute of upstream. A list of values matches any one of them. The first rule that matches an instance applies, and the others do not.

The deployment message names the rule:

Auto-deploy (rule staging-cascade): upstream api-staging-db completed deployment 6f1c...

An unknown field, a rule without name or downstream, or two rules with one name stops the automation at start.

Declare the attributes​

System attributes, such as md-environment and md-project, need no declaration. Each other key in downstream must be a custom attribute of your organization, with each value that the rules use, before you can set it. Declare it at the COMPONENT scope to set it on components, with required: false, so that components without it stay valid. Custom attribute keys allow only letters, digits, and underscores.

mass has no command for custom attributes. Use the createCustomAttribute mutation of the V2 API, as an account with organization:manageCustomAttributes:

shell
curl https://api.massdriver.cloud/api/v2 \
-H "Authorization: Bearer $MASSDRIVER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"query": "mutation { createCustomAttribute(organizationId: \"acme\", input: {key: \"autodeploy\", scope: COMPONENT, required: false, values: [\"true\", \"false\"]}) { successful messages { field message } } }"}'

Results in the stash​

On each downstream deployment it creates or proposes, the automation writes:

KeyStashLabelValue
md/v1/step/autodeployThe downstream deploymentAutodeploy{"tool": "autodeploy-downstream", "action": "apply", "status": "succeeded", "finished_at": "...", "message": "Deployed by rule autodeploy=true after upstream api-prod-db completed deployment <id>"}

A proposed deployment's message starts with Proposed by rule. 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.

Secrets​

autodeploy-downstream has no secrets of its own. It uses the MASSDRIVER_* variables of the common settings.

Permissions​

The service account needs:

  • instance:deploy on the downstream instances of deploy rules
  • instance:propose on the downstream instances of propose rules
  • view access to their projects
  • stash:write on the downstream instances, for the results
  • with the bundle: organization:manageEventDestinations

Host​

Massdriver sends events to https://<host>/hooks/massdriver, set in Ingress > Host. That path must be public. On ECS, an empty host uses autodeploy-downstream.<domain of the cluster's hosted zone>.

Event attributes adds an attribute filter to the destination, such as md-environment = prod. Refer to Deploy for the platform details.

Event destination​

The bundle creates a destination for deployment.completed, with the Event attributes filter and the condition .data.metadata.deployment_action == "PROVISION". The automation checks each rule's upstream attributes itself.

To create the destination yourself, with mass 2.6.0 or later:

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

The condition drops PLAN and DECOMMISSION deployments, so Massdriver marks them SKIPPED and does not send them. To act on one environment only, add --attribute md-environment=prod.

Copy the signing secret from the destination's Overview tab into MASSDRIVER_SIGNING_SECRET.

Run​

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

Limits​

  • Duplicate events are dropped by id for one hour, in memory. Run one replica.
  • The automation responds before it deploys. A failed deploy is logged, and Massdriver does not retry it.
  • Each downstream deploys with its saved params and its current version constraint.