Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

basic smoke test runner (#1958)

Will Hutchinsond166775426e4
diff --git a/infra/bun.lock b/infra/bun.lock
index d973b47e44..41b31a50f4 100644
--- a/infra/bun.lock
+++ b/infra/bun.lock
@@ -118,6 +118,10 @@
"pulumi-fusionauth": "6.0.2",
},
},
+ "stacks/github-runners": {
+ "name": "github-runners-stack",
+ "version": "0.0.0",
+ },
"stacks/image-proxy-service": {
"name": "image-proxy-service-stack",
"version": "0.0.0",
@@ -652,6 +656,8 @@
"get-stream": ["[email protected]", "", {}, "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg=="],
+ "github-runners-stack": ["github-runners-stack@workspace:stacks/github-runners"],
+
"glob": ["[email protected]", "", { "dependencies": { "foreground-child": "^3.1.0", "jackspeak": "^3.1.2", "minimatch": "^9.0.4", "minipass": "^7.1.2", "package-json-from-dist": "^1.0.0", "path-scurry": "^1.11.1" }, "bin": { "glob": "dist/esm/bin.mjs" } }, "sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg=="],
"google-protobuf": ["[email protected]", "", {}, "sha512-MnG7N936zcKTco4Jd2PX2U96Kf9PxygAPKBug+74LHzmHXmceN16MmRcdgZv+DGef/S9YvQAfRsNCn4cjf9yyQ=="],
diff --git a/infra/stacks/github-runners/Pulumi.dev.yaml b/infra/stacks/github-runners/Pulumi.dev.yaml
new file mode 100644
index 0000000000..6084c759ea
--- /dev/null
+++ b/infra/stacks/github-runners/Pulumi.dev.yaml
@@ -0,0 +1,6 @@
+config:
+ aws:region: us-east-1
+ github-runners:instanceType: t3.large
+ github-runners:runnerUrl: https://github.com/macro-inc
+ github-runners:runnerToken:
+ secure: AAABAITqpBY+NbTOaeJMHl8tYniMcggbPuYplw4WAc6giqK4HPdLE/OkMCKLuCqCcs62bEj85Muq1401GQ==
diff --git a/infra/stacks/github-runners/Pulumi.yaml b/infra/stacks/github-runners/Pulumi.yaml
new file mode 100644
index 0000000000..5fa03d6e92
--- /dev/null
+++ b/infra/stacks/github-runners/Pulumi.yaml
@@ -0,0 +1,3 @@
+name: github-runners
+runtime: nodejs
+description: Self-hosted GitHub Actions runners
diff --git a/infra/stacks/github-runners/index.ts b/infra/stacks/github-runners/index.ts
new file mode 100644
index 0000000000..af446feceb
--- /dev/null
+++ b/infra/stacks/github-runners/index.ts
@@ -0,0 +1,26 @@
+import { config, stack } from '../../packages/shared';
+import { get_coparse_api_vpc } from '../../packages/vpc';
+import { SmokeTestRunner } from './runner';
+
+const tags = {
+ environment: stack,
+ tech_lead: 'hutch',
+ project: 'github-runners',
+};
+
+const vpc = get_coparse_api_vpc();
+
+const runnerUrl = config.require('runnerUrl');
+const runnerToken = config.requireSecret('runnerToken');
+
+const smokeRunner = new SmokeTestRunner('macro-smoke-runner', {
+ vpc,
+ tags,
+ runnerUrl,
+ runnerToken,
+ instanceType: config.get('instanceType') || 't3.large',
+ keyPairName: config.get('keyPairName'),
+});
+
+export const instanceId = smokeRunner.instance.id;
+export const privateIp = smokeRunner.instance.privateIp;
diff --git a/infra/stacks/github-runners/package.json b/infra/stacks/github-runners/package.json
new file mode 100644
index 0000000000..1ace6f9bb7
--- /dev/null
+++ b/infra/stacks/github-runners/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "github-runners-stack",
+ "version": "0.0.0",
+ "private": true,
+ "license": "MIT",
+ "main": "index.ts"
+}
diff --git a/infra/stacks/github-runners/runner.ts b/infra/stacks/github-runners/runner.ts
new file mode 100644
index 0000000000..cf425b0b13
--- /dev/null
+++ b/infra/stacks/github-runners/runner.ts
@@ -0,0 +1,176 @@
+import * as fs from 'fs';
+import * as path from 'path';
+import * as aws from '@pulumi/aws';
+import * as pulumi from '@pulumi/pulumi';
+import { stack } from '../../packages/shared';
+
+type SmokeTestRunnerArgs = {
+ vpc: {
+ vpcId: string;
+ privateSubnetIds: string[];
+ };
+ tags: { [key: string]: string };
+ runnerUrl: string;
+ runnerToken: pulumi.Output<string>;
+ instanceType?: string;
+ keyPairName?: string;
+ volumeSizeGb?: number;
+};
+
+export class SmokeTestRunner extends pulumi.ComponentResource {
+ public instance: aws.ec2.Instance;
+ public sg: aws.ec2.SecurityGroup;
+ public role: aws.iam.Role;
+ public instanceProfile: aws.iam.InstanceProfile;
+
+ constructor(
+ name: string,
+ args: SmokeTestRunnerArgs,
+ opts?: pulumi.ComponentResourceOptions
+ ) {
+ super('macro:components:SmokeTestRunner', name, {}, opts);
+
+ const {
+ vpc,
+ tags,
+ runnerUrl,
+ runnerToken,
+ instanceType = 't3.large',
+ keyPairName,
+ volumeSizeGb = 100,
+ } = args;
+
+ // ── AMI ───────────────────────────────────────────────────────────────
+ const ami = aws.ec2.getAmiOutput({
+ mostRecent: true,
+ owners: ['099720109477'], // Canonical
+ filters: [
+ {
+ name: 'name',
+ values: [
+ 'ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-*',
+ ],
+ },
+ { name: 'virtualization-type', values: ['hvm'] },
+ ],
+ });
+
+ // ── Security Group ────────────────────────────────────────────────────
+ this.sg = new aws.ec2.SecurityGroup(
+ `${name}-sg`,
+ {
+ name: `${name}-sg-${stack}`,
+ vpcId: vpc.vpcId,
+ description: `GitHub Actions runner: ${name}`,
+ tags,
+ },
+ { parent: this }
+ );
+
+ new aws.vpc.SecurityGroupEgressRule(
+ `${name}-all-out`,
+ {
+ securityGroupId: this.sg.id,
+ description: 'Allow all outbound',
+ cidrIpv4: '0.0.0.0/0',
+ ipProtocol: '-1',
+ tags,
+ },
+ { parent: this }
+ );
+
+ new aws.vpc.SecurityGroupIngressRule(
+ `${name}-vpc-in`,
+ {
+ securityGroupId: this.sg.id,
+ description: 'Allow VPC inbound',
+ cidrIpv4: '10.0.0.0/16',
+ ipProtocol: '-1',
+ tags,
+ },
+ { parent: this }
+ );
+
+ // ── IAM ───────────────────────────────────────────────────────────────
+ this.role = new aws.iam.Role(
+ `${name}-role`,
+ {
+ name: `${name}-role-${stack}`,
+ assumeRolePolicy: JSON.stringify({
+ Version: '2012-10-17',
+ Statement: [
+ {
+ Effect: 'Allow',
+ Principal: { Service: 'ec2.amazonaws.com' },
+ Action: 'sts:AssumeRole',
+ },
+ ],
+ }),
+ tags,
+ },
+ { parent: this }
+ );
+
+ new aws.iam.RolePolicyAttachment(
+ `${name}-ssm`,
+ {
+ role: this.role.name,
+ policyArn: 'arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore',
+ },
+ { parent: this }
+ );
+
+ this.instanceProfile = new aws.iam.InstanceProfile(
+ `${name}-instance-profile`,
+ {
+ name: `${name}-profile-${stack}`,
+ role: this.role.name,
+ tags,
+ },
+ { parent: this }
+ );
+
+ // ── User Data ─────────────────────────────────────────────────────────
+ const userDataScript = fs.readFileSync(
+ path.join(__dirname, 'user-data.sh'),
+ 'utf-8'
+ );
+
+ const userData = runnerToken.apply((token) =>
+ userDataScript.replace(
+ 'set -euo pipefail',
+ [
+ 'set -euo pipefail',
+ `export GITHUB_RUNNER_URL="${runnerUrl}"`,
+ `export GITHUB_RUNNER_TOKEN="${token}"`,
+ `export GITHUB_RUNNER_NAME="${name}-$(curl -s http://169.254.169.254/latest/meta-data/instance-id)"`,
+ ].join('\n')
+ )
+ );
+
+ // ── EC2 Instance ──────────────────────────────────────────────────────
+ this.instance = new aws.ec2.Instance(
+ `${name}`,
+ {
+ ami: ami.id,
+ instanceType,
+ subnetId: vpc.privateSubnetIds[0],
+ vpcSecurityGroupIds: [this.sg.id],
+ iamInstanceProfile: this.instanceProfile.name,
+ keyName: keyPairName,
+ userData,
+ userDataReplaceOnChange: true,
+ rootBlockDevice: {
+ volumeSize: volumeSizeGb,
+ volumeType: 'gp3',
+ encrypted: true,
+ },
+ tags: {
+ ...tags,
+ Name: `${name}-${stack}`,
+ },
+ },
+ { parent: this }
+ );
+ }
+}
diff --git a/infra/stacks/github-runners/tsconfig.json b/infra/stacks/github-runners/tsconfig.json
new file mode 100644
index 0000000000..4082f16a5d
--- /dev/null
+++ b/infra/stacks/github-runners/tsconfig.json
@@ -0,0 +1,3 @@
+{
+ "extends": "../../tsconfig.json"
+}
diff --git a/infra/stacks/github-runners/user-data.sh b/infra/stacks/github-runners/user-data.sh
new file mode 100644
index 0000000000..5f89996016
--- /dev/null
+++ b/infra/stacks/github-runners/user-data.sh
@@ -0,0 +1,140 @@
+#!/usr/bin/env bash
+# EC2 user-data bootstrap for self-hosted GitHub Actions runners.
+# Logs to /var/log/cloud-init-output.log automatically.
+set -euo pipefail
+
+export DEBIAN_FRONTEND=noninteractive
+
+# ─── System packages & updates ────────────────────────────────────────────────
+apt-get update -y
+apt-get upgrade -y
+
+apt-get install -y \
+ build-essential \
+ pkg-config \
+ libssl-dev \
+ libffi-dev \
+ zlib1g-dev \
+ libbz2-dev \
+ libreadline-dev \
+ libsqlite3-dev \
+ libpq-dev \
+ curl \
+ wget \
+ git \
+ jq \
+ unzip \
+ zip \
+ gnupg \
+ lsb-release \
+ ca-certificates \
+ apt-transport-https \
+ software-properties-common \
+ cmake \
+ clang \
+ llvm \
+ protobuf-compiler \
+ libprotobuf-dev \
+ python3 \
+ python3-pip \
+ python3-venv
+
+# ─── Docker ───────────────────────────────────────────────────────────────────
+install -m 0755 -d /etc/apt/keyrings
+curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
+chmod a+r /etc/apt/keyrings/docker.asc
+
+echo \
+ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
+ $(. /etc/os-release && echo "$VERSION_CODENAME") stable" \
+ > /etc/apt/sources.list.d/docker.list
+
+apt-get update -y
+apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
+
+systemctl enable docker
+systemctl start docker
+
+# ─── Runner user ──────────────────────────────────────────────────────────────
+RUNNER_USER="runner"
+if ! id -u "$RUNNER_USER" &>/dev/null; then
+ useradd -m -s /bin/bash "$RUNNER_USER"
+fi
+usermod -aG docker "$RUNNER_USER"
+
+# ─── Rust ─────────────────────────────────────────────────────────────────────
+sudo -u "$RUNNER_USER" bash -c '
+ curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
+ source "$HOME/.cargo/env"
+ rustup component add clippy rustfmt
+'
+
+# ─── Just ─────────────────────────────────────────────────────────────────────
+curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin
+
+# ─── AWS CLI v2 ───────────────────────────────────────────────────────────────
+cd /tmp
+curl -fsSL "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o awscliv2.zip
+unzip -qo awscliv2.zip
+./aws/install --update
+rm -rf awscliv2.zip aws/
+
+# ─── Pulumi CLI ───────────────────────────────────────────────────────────────
+curl -fsSL https://get.pulumi.com | bash -s -- --install-root /usr/local
+
+# ─── SOPS ─────────────────────────────────────────────────────────────────────
+SOPS_VERSION="3.9.4"
+curl -fsSL "https://github.com/getsops/sops/releases/download/v${SOPS_VERSION}/sops-v${SOPS_VERSION}.linux.amd64" \
+ -o /usr/local/bin/sops
+chmod +x /usr/local/bin/sops
+
+# ─── Node.js LTS (needed by many GH Actions) ─────────────────────────────────
+curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
+apt-get install -y nodejs
+corepack enable
+
+# ─── GitHub Actions Runner ────────────────────────────────────────────────────
+RUNNER_VERSION="2.332.0"
+RUNNER_SHA="f2094522a6b9afeab07ffb586d1eb3f190b6457074282796c497ce7dce9e0f2a"
+RUNNER_HOME="/home/${RUNNER_USER}/actions-runner"
+
+mkdir -p "$RUNNER_HOME"
+cd "$RUNNER_HOME"
+
+curl -fsSL \
+ "https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz" \
+ -o "actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz"
+
+echo "${RUNNER_SHA} actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz" | shasum -a 256 -c
+tar xzf "actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz"
+rm -f "actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz"
+
+# Install runner's own OS-level dependencies
+./bin/installdependencies.sh
+
+chown -R "${RUNNER_USER}:${RUNNER_USER}" "$RUNNER_HOME"
+
+# ─── Configure & start the runner ─────────────────────────────────────────────
+# GITHUB_RUNNER_URL and GITHUB_RUNNER_TOKEN are expected to be injected via
+# Pulumi config / SSM Parameter Store / Secrets Manager at deploy time.
+# The Pulumi stack interpolates them into this script before passing it as userData.
+
+if [[ -n "${GITHUB_RUNNER_URL:-}" && -n "${GITHUB_RUNNER_TOKEN:-}" ]]; then
+ sudo -u "$RUNNER_USER" bash -c "
+ cd ${RUNNER_HOME}
+ ./config.sh \
+ --url '${GITHUB_RUNNER_URL}' \
+ --token '${GITHUB_RUNNER_TOKEN}' \
+ --name '${GITHUB_RUNNER_NAME:-$(hostname)}' \
+ --labels 'self-hosted,linux,x64,smoke-tester' \
+ --runnergroup 'monorepo' \
+ --unattended \
+ --replace
+ "
+
+ cd "$RUNNER_HOME"
+ ./svc.sh install "$RUNNER_USER"
+ ./svc.sh start &
+fi
+
+echo ">>> Bootstrap complete"