|
| 1 | +# AWS CodeBuild CI for CortexLM/cli |
| 2 | + |
| 3 | +Public-repo CodeBuild integration for Linux **x64** and **arm64**. GitHub |
| 4 | +Actions assumes a dedicated IAM role with **OIDC** (no long-lived AWS keys) |
| 5 | +and starts the projects. Each project posts a commit status comparable to |
| 6 | +the CortexLM/backend checks `cortex-gha-x64` / `cortex-gha-arm64`. |
| 7 | + |
| 8 | +Marker: `CLI_CODEBUILD_CI_READY` |
| 9 | + |
| 10 | +Existing workflows stay in place: `ci.yml`, `release.yml`, `publish-r2.yml`, |
| 11 | +`homebrew.yml`, `winget.yml`, `version-bump.yml`, `test-stability.yml`. |
| 12 | +CodeBuild **extends** them. It does not replace R2 publishing, version |
| 13 | +bumps, or macOS/Windows release jobs. Staging/prod app deploy remains |
| 14 | +unchanged (prod HOLD). |
| 15 | + |
| 16 | +Windows CodeBuild is **out of scope**. Compliance treats Windows CI as |
| 17 | +outside the production gate; keep `windows-latest` on GitHub-hosted runners |
| 18 | +in `ci.yml` / `release.yml` until a separate follow-up. |
| 19 | + |
| 20 | +Do not commit AWS account IDs, access keys, PATs, or internal hostnames. |
| 21 | + |
| 22 | +## Status checks (branch protection) |
| 23 | + |
| 24 | +After the one-time AWS setup below, add these **required** checks on `main`: |
| 25 | + |
| 26 | +| Context | Project | Arch | |
| 27 | +|---------|---------|------| |
| 28 | +| `cortex-cli-gha-x64` | `cortex-cli-gha-x64` | Linux x86_64 | |
| 29 | +| `cortex-cli-gha-arm64` | `cortex-cli-gha-arm64` | Linux aarch64 | |
| 30 | + |
| 31 | +Keep the existing `ci.yml` checks (`Format`, `Clippy`, `Test`, `TUI checks`, |
| 32 | +`Security Audit`, `Source and dependency policy`, `Changed-line coverage`, |
| 33 | +`CLI Version and Distribution`, `CI Success`). Do not remove them in this |
| 34 | +change. After CodeBuild is required and stable, a later PR can slim the |
| 35 | +duplicate GitHub-hosted Linux cargo jobs. |
| 36 | + |
| 37 | +Same-repo PRs and pushes to `main` start CodeBuild. Fork PRs keep using |
| 38 | +GitHub-hosted `ci.yml` only (OIDC is not granted to forks). |
| 39 | + |
| 40 | +## Prefer existing org projects? |
| 41 | + |
| 42 | +If this AWS account already hosts backend projects `cortex-gha-x64` / |
| 43 | +`cortex-gha-arm64`, **reuse the GitHub OIDC provider** and the account, not |
| 44 | +the projects. A CodeBuild project has one source/buildspec; do not point |
| 45 | +backend projects at this public CLI repo. Create dedicated |
| 46 | +`cortex-cli-gha-*` projects. Override names only via GitHub **variables** |
| 47 | +if an admin already created equivalent CLI projects. |
| 48 | + |
| 49 | +## One-time admin setup |
| 50 | + |
| 51 | +### 1. Reuse or create the GitHub OIDC provider |
| 52 | + |
| 53 | +In the AWS account that already runs CortexLM/backend CodeBuild (or a new |
| 54 | +account dedicated to public CLI CI): |
| 55 | + |
| 56 | +1. IAM → Identity providers → `token.actions.githubusercontent.com`. |
| 57 | +2. If it exists, **do not recreate it**. Continue to the role. |
| 58 | +3. If it does not exist, create it: |
| 59 | + - Provider URL: `https://token.actions.githubusercontent.com` |
| 60 | + - Audience: `sts.amazonaws.com` |
| 61 | + - Or pass `CreateGithubOidcProvider=true` to the stack below. |
| 62 | + |
| 63 | +### 2. Deploy the stack (recommended) |
| 64 | + |
| 65 | +From a workstation that can assume an admin role (never from this repo's |
| 66 | +CI, and never with keys committed here): |
| 67 | + |
| 68 | +```bash |
| 69 | +aws cloudformation deploy \ |
| 70 | + --stack-name cortex-cli-codebuild \ |
| 71 | + --template-file deploy/aws/codebuild/cloudformation.yaml \ |
| 72 | + --capabilities CAPABILITY_NAMED_IAM \ |
| 73 | + --parameter-overrides \ |
| 74 | + GitHubOrgRepo=CortexLM/cli \ |
| 75 | + ProjectNameX64=cortex-cli-gha-x64 \ |
| 76 | + ProjectNameArm64=cortex-cli-gha-arm64 \ |
| 77 | + GhaRoleName=cortex-cli-codebuild-gha \ |
| 78 | + CreateGithubOidcProvider=false |
| 79 | +``` |
| 80 | + |
| 81 | +Copy the `GithubActionsRoleArn` output. It contains the account ID; store |
| 82 | +it as a GitHub **variable**, not in git. |
| 83 | + |
| 84 | +### 3. Manual IAM if you do not use CloudFormation |
| 85 | + |
| 86 | +1. Create role `cortex-cli-codebuild-gha`. |
| 87 | +2. Trust policy: `iam-trust-policy.json` with `ACCOUNT_ID` replaced at |
| 88 | + deploy time. Subject must be `repo:CortexLM/cli:*` only. |
| 89 | +3. Permissions: `iam-gha-permissions.json` with `ACCOUNT_ID` and `REGION` |
| 90 | + replaced. Actions are only `codebuild:StartBuild`, |
| 91 | + `codebuild:BatchGetBuilds`, and `logs:GetLogEvents` on the two CLI |
| 92 | + projects. |
| 93 | +4. Create CodeBuild projects `cortex-cli-gha-x64` (Linux x86, |
| 94 | + `aws/codebuild/standard:7.0`, `BUILD_GENERAL1_LARGE`) and |
| 95 | + `cortex-cli-gha-arm64` (Linux ARM, |
| 96 | + `aws/codebuild/amazonlinux-aarch64-standard:3.0`, |
| 97 | + `BUILD_GENERAL1_LARGE`). Source type **NO_SOURCE**. S3 cache on a |
| 98 | + private bucket. Build timeout 90 minutes. |
| 99 | +5. CodeBuild service role: CloudWatch Logs for those projects plus |
| 100 | + read/write on the cache bucket. No deploy, no R2, no production secrets. |
| 101 | + |
| 102 | +### 4. GitHub repository variables (not secrets) |
| 103 | + |
| 104 | +On `CortexLM/cli` → Settings → Secrets and variables → Actions → Variables: |
| 105 | + |
| 106 | +| Variable | Value | |
| 107 | +|----------|--------| |
| 108 | +| `AWS_CODEBUILD_ROLE_ARN` | `GithubActionsRoleArn` stack output | |
| 109 | +| `AWS_REGION` | Region of the stack (default in the workflow is `us-east-1`) | |
| 110 | +| `AWS_CODEBUILD_PROJECT_X64` | Optional override; default `cortex-cli-gha-x64` | |
| 111 | +| `AWS_CODEBUILD_PROJECT_ARM64` | Optional override; default `cortex-cli-gha-arm64` | |
| 112 | + |
| 113 | +Do **not** add `AWS_ACCESS_KEY_ID` / `AWS_SECRET_ACCESS_KEY`. Do not put |
| 114 | +staging or production app secrets on these projects. |
| 115 | + |
| 116 | +Until `AWS_CODEBUILD_ROLE_ARN` is set, `.github/workflows/codebuild.yml` |
| 117 | +validates the in-repo assets and **skips** StartBuild. It does not post a |
| 118 | +green `cortex-cli-gha-*` status for that skip (no mock-success). |
| 119 | + |
| 120 | +### 5. Require the checks |
| 121 | + |
| 122 | +Branch protection / ruleset on `main`: require |
| 123 | +`cortex-cli-gha-x64` and `cortex-cli-gha-arm64` in addition to the |
| 124 | +existing `ci.yml` jobs. Require these only after a successful StartBuild |
| 125 | +has been observed on a test PR. |
| 126 | + |
| 127 | +## What CodeBuild runs |
| 128 | + |
| 129 | +`buildspec-ci.yml` clones the public `CortexLM/cli` commit over HTTPS |
| 130 | +(no PAT) and runs `run-ci.sh`: |
| 131 | + |
| 132 | +- `cargo fmt --all -- --check` |
| 133 | +- `./scripts/clippy.sh` |
| 134 | +- `./scripts/check-cli-version.sh` |
| 135 | +- `python3 scripts/readiness/tests.py` |
| 136 | +- `cargo test --locked --workspace --doc` |
| 137 | +- `python3 scripts/readiness/schema.py` |
| 138 | +- `cargo build --locked -p cortex-cli -p cortex-app-server` |
| 139 | +- `python3 scripts/readiness/qa.py` |
| 140 | +- headless TUI / snapshot packages (same set as `ci.yml`) |
| 141 | +- changed-line coverage against the real PR base SHA |
| 142 | + |
| 143 | +Cargo registry, git, rustup, and `target/` are cached in S3. |
| 144 | + |
| 145 | +## Follow-up (Windows) |
| 146 | + |
| 147 | +Not in this change. If Windows CodeBuild is added later, use a separate |
| 148 | +project and a non-required check. Do not block production on it. |
0 commit comments