Skip to main content

Deploy the Automations

Each automation has two bundles in massdriver-automations:

BundleRuns onDependencies
massdriver-<automation>A Kubernetes cluster with an ingress controllermassdriver-kubernetes-cluster, massdriver-service-account
massdriver-<automation>-ecsAmazon ECS with Fargate, behind an Application Load Balanceraws-iam-role, aws-ecs-cluster, massdriver-service-account

Each bundle runs one automation and creates the event destination that sends it only the events it uses. Deploy one instance per automation, each with its own service account that has only that automation's permissions.

The bundles are generated by scripts/bundles.py. Each -ecs bundle has an operator guide, operator.md, with the instance's host, logs, and troubleshooting steps.

Get the bundles​

From the AWS catalog​

The AWS catalog vendors every -ecs bundle with scripts/sync-automation-bundles.sh. Publishing the catalog publishes them. The catalog's copies differ from upstream:

  • The dependencies are pinned to the catalog's types: aws-iam-role@0.0.0, aws-ecs-cluster@0.0.0, massdriver-service-account@~0.1, and website@~0.1.
  • Checkov halts deployments to instances whose environment is prod or production.
  • The Development and Production presets use the image tag latest.

From massdriver-automations​

Publish the resource types a bundle uses before you publish the bundle:

TypeUsed bySource
massdriver-service-accountEvery bundleOfficial, in massdriver-resource-types
massdriver-kubernetes-clusterKubernetes bundlesOfficial, in massdriver-resource-types
aws-iam-role-ecs bundlesThe AWS credential type of the AWS catalog or massdriver-catalog, or your own
aws-ecs-cluster-ecs bundlesExample in examples/resource-types/aws-ecs-cluster
websitestatuspage and cost-explorer bundlesExample in examples/resource-types/website

Install the official types. The example types are not official. Publish them as they are, or change them and the bundles to match your organization:

shell
git clone https://github.com/massdriver-cloud/massdriver-automations.git
cd massdriver-automations
for type in website aws-ecs-cluster; do
mass resource-type create "$type"
mass resource-type publish "examples/resource-types/$type"
done

Then build and publish each automation's bundle:

shell
cd bundles/massdriver-drift   # massdriver-drift-ecs for ECS
mass bundle build
mass bundle publish

Service account​

A deployment cannot create event destinations, so each bundle depends on a massdriver-service-account resource. The bundle creates the event destination with it, and the automation calls the Massdriver API with it as MASSDRIVER_URL, MASSDRIVER_ORGANIZATION_ID, and MASSDRIVER_API_KEY.

Create one service account per automation. Each needs organization:manageEventDestinations, plus the permissions on its automation's page. Automations that write results to the stash also need stash:write. Refer to Access control for each action.

Connect the service account to the one instance with a remote reference, so no other instance in the environment resolves it:

shell
mass resource grant create <service-account-resource-id> --condition md-project=automations
mass instance remote-reference set automations-main-drift service_account <service-account-resource-id>

Requirements​

Every bundle needs TLS on its host. Massdriver and Slack send requests to https:// URLs only.

Kubernetes​

  • A massdriver-kubernetes-cluster resource. The bundle deploys into the namespace of that resource, or default when it has none. It does not create the namespace.
  • An ingress controller, and a DNS record for the host that points at it.
  • A cert-manager ClusterIssuer, a TLS secret with a certificate for the host, or TLS that ends in front of the ingress controller.

Amazon ECS​

  • An aws-iam-role resource. With arn and an optional external_id, the role trusts Massdriver's AWS account. With arn and token_level, the role trusts the deployment's identity token of that level.
  • An aws-ecs-cluster resource: the cluster, its load balancer and listener, the VPC with private subnets, and an optional DNS zone.
  • An HTTPS listener with a certificate for the host.
  • Private subnets that reach the internet, so tasks can pull images and call the Massdriver API, Slack, GitHub, and the other services in their settings.

Params​

ParamDefault
Image > Repositoryghcr.io/massdriver-cloud/massdriver-automationsbundle-scanner adds -scanner to the tag, and router adds -scripts when it runs commands.
Image > Tag0.3A moving tag, such as 0.3 or latest, restarts the automation on the image the tag names at each deploy. Pin a version, such as 0.3.0, to run the same code on every deploy.
Ingress > HostKubernetes: required. ECS: <automation>.<domain of the cluster's DNS zone>.Massdriver sends events to https://<host>/hooks/massdriver.
Ingress > Ingress classThe cluster's defaultKubernetes only.
Ingress > cert-manager ClusterIssuerKubernetes only. Issues a certificate for the host.
Ingress > TLS secretKubernetes only. A Secret in the namespace with a certificate for the host. Ignored when a ClusterIssuer is set.
Ingress > Create a DNS recordOnECS only. Creates a CNAME to the load balancer when the host is in the cluster's DNS zone.
Logs > Retention (days)90ECS only. The Development preset sets 7 and the Production preset 365.
SettingsThe automation's config file. A setting left empty uses the automation's default.
Event attributesOn automations whose events carry attributes. Adds an attribute filter to the event destination, such as md-environment = prod.
State storage (GiB)1Kubernetes only, for cost-explorer, drift, freeze-guard, statuspage, and upgrade-train. Cannot change after the first deploy.
Tracing > OTLP endpointThe OTLP/HTTP base URL of a collector. Empty turns tracing off. Set the OTEL_EXPORTER_OTLP_HEADERS secret when the collector needs credentials.

An attribute value with commas, such as api, web, matches any of its values wherever the config file accepts a list.

Set each automation's secrets on its instance. The secrets are on the automation's page.

What the bundle creates​

KubernetesAmazon ECS
WorkloadA Deployment with one replicaAn ECS service with one Fargate task (ARM64). An init container writes the config file, and router's Scripts, to task volumes.
SettingsA ConfigMap with the config file, and a Secret with the environment variablesA Secrets Manager secret with the secret environment variables
RoutingA Service, and an Ingress for the host that sends every path to the automationA target group with a health check on /healthz, a rule for the host on the cluster's HTTPS listener, and, with Create a DNS record, a CNAME record
State, for cost-explorer, drift, freeze-guard, statuspage, and upgrade-trainA PersistentVolumeClaim for STATE_DIRAn EFS file system and an access point for STATE_DIR, with a task role that can mount only that access point
LogsContainer logsA CloudWatch log group
Event destinationNamed for the instance, sending to https://<host>/hooks/massdriverThe same

The destination's signing secret goes to the automation as MASSDRIVER_SIGNING_SECRET.

On Kubernetes, statuspage with an output directory gets a second claim, <instance>-site, mounted at that directory, and router gets a ConfigMap with its Scripts, mounted as executables in /scripts.

On ECS, the instance also gets a KMS key for the secret and the logs. The task execution role can read only that secret and write only that log group. audit-archiver with an S3 bucket and no AWS key secrets gets a task role that can write to the bucket. stash-sync with CloudWatch rules or presets and no AWS key secrets gets a task role that can call cloudwatch:GetMetricData and cloudwatch:DescribeAlarms. On Kubernetes, both read AWS credentials from the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY secrets.

statuspage and cost-explorer produce a website resource with the URL to open. The other bundles produce no resources.

Limits​

  • Each automation runs one replica and restarts on every change of its settings. It keeps its queues and repeated event ids in memory, and a restart loses them. Massdriver sends the events that fail during a restart again.
  • router runs the <tag>-scripts image when a route has an exec step or Scripts has a file. That image has sh, jq, curl, and python3. For other tools, build an image from it, push it with the same -scripts tag to your own registry, and set Image > Repository. On ECS, the image needs an ARM64 variant.
  • On ECS, a task definition holds at most 64 KiB, which includes the config file and router's Scripts.
  • Resource sizes are fixed. Kubernetes: requests of 25m CPU and 64Mi memory, limits of 500m and 256Mi; bundle-scanner 250m and 512Mi, up to 2 CPUs and 2Gi. ECS: 0.25 vCPU and 512 MiB; bundle-scanner 1 vCPU and 2 GiB.