Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ compositions:
sources:
- name: stack-tectonic
kind: oci
ref: oci://ghcr.io/sourceplane/stack-tectonic:0.11.0
ref: oci://ghcr.io/sourceplane/stack-tectonic:0.12.0
```

Keep the `orun` runtime pinned separately in `kiox.yaml`, then plan or run against that intent. The full consumer workflow is in [docs/using-this-stack-from-oci.md](docs/using-this-stack-from-oci.md).
Keep the `orun` runtime pinned separately in `kiox.yaml`, then plan or run against that intent. The full consumer workflow is in [docs/using-this-stack-from-oci.md](docs/using-this-stack-from-oci.md), and the opt-in remote-state matrix pattern is documented in [docs/remote-state-matrix-ci.md](docs/remote-state-matrix-ci.md).

## Catalog layout

Expand Down Expand Up @@ -75,6 +75,7 @@ Every composition now lives under `compositions/<name>/` so docs, examples, test
- [Authoring guide](docs/authoring.md)
- [Verification model](docs/verification.md)
- [Production deploys](docs/production-deploys.md)
- [Remote-state matrix CI](docs/remote-state-matrix-ci.md)
- [Roadmap](docs/roadmap.md)
- [Using this stack from OCI](docs/using-this-stack-from-oci.md)

Expand All @@ -83,6 +84,6 @@ Every composition now lives under `compositions/<name>/` so docs, examples, test
1. Update `stack.yaml`.
2. Run `./scripts/verify.sh`.
3. Merge to `main`.
4. Push a matching tag like `v0.11.0`.
4. Push a matching tag like `v0.12.0`.

The release workflow publishes the OCI package, creates the GitHub release, and uploads the generated registry index.
238 changes: 238 additions & 0 deletions docs/remote-state-matrix-ci.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
# Remote-state matrix CI

This guide shows an **opt-in advanced** GitHub Actions pattern for consumer repositories that need backend-coordinated matrix execution. It compiles one `orun` plan, uploads `.orun/plans/`, fans jobs out across a matrix, and verifies the shared remote state afterward.

It is adapted from the upstream `sourceplane/orun` remote-state references:

- `examples/github-actions/remote-state-matrix.yml`
- `examples/remote-state-matrix/README.md`
- `.github/workflows/remote-state-conformance.yml`

Do **not** make this your default pull-request lane just because the workflow exists. Keep it in a dedicated workflow and enable it only when the repository already has a real `orun-backend`, OIDC configured, and a reason to distribute execution across runners.

## Required repository configuration

Set these GitHub Actions repository variables before enabling the workflow:

| Setting | Location | Value |
| --- | --- | --- |
| `ORUN_BACKEND_URL` | Settings -> Variables -> Actions | URL of your `orun-backend` instance |
| `REMOTE_STATE_MATRIX_CI` | Settings -> Variables -> Actions | Optional `true` switch if you later decide to auto-run this workflow on push or PR |

The workflow permissions must include:

```yaml
permissions:
contents: read
id-token: write
```

`id-token: write` is mandatory because current Orun remote-state flows authenticate GitHub Actions runners with OIDC. Do not hard-code backend URLs, tokens, Cloudflare credentials, or production-only settings in the workflow file.

## Consumer repo assumptions

This pattern assumes the consumer repository pins the runtime and stack separately:

### `kiox.yaml`

```yaml
apiVersion: kiox.io/v1
kind: Workspace
metadata:
name: my-platform
providers:
orun:
source: ghcr.io/sourceplane/orun:v1.12.0
```

### `intent.yaml`

```yaml
compositions:
sources:
- name: stack-tectonic
kind: oci
ref: oci://ghcr.io/sourceplane/stack-tectonic:0.12.0
```

This guide keeps remote state opt-in at the workflow layer by passing `--remote-state` and `--backend-url` explicitly. That keeps normal local `orun validate`, `orun plan`, and `orun run` behavior local unless you intentionally opt into backend-backed execution.

## Copyable workflow

Start with a dedicated manual workflow. If you later want push or pull-request automation, add those triggers behind a repo-level gate such as `vars.REMOTE_STATE_MATRIX_CI == 'true'`.

```yaml
name: remote-state-matrix

on:
workflow_dispatch:

permissions:
contents: read
id-token: write

jobs:
plan:
name: Compile plan
runs-on: ubuntu-latest
outputs:
plan_id: ${{ steps.plan.outputs.plan_id }}
run_id: ${{ steps.plan.outputs.run_id }}
jobs: ${{ steps.matrix.outputs.jobs }}
first_job: ${{ steps.matrix.outputs.first_job }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: sourceplane/kiox-action@v2.1.2

- name: Compile plan
id: plan
run: |
kiox -- orun validate --intent intent.yaml
kiox -- orun plan --intent intent.yaml --name remote-state-stack --all
plan_id="$(kiox -- orun get plans -o json | jq -r '.[] | select(.Name == "remote-state-stack") | .Checksum')"
run_id="gha-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}-${plan_id}"
echo "plan_id=${plan_id}" >> "${GITHUB_OUTPUT}"
echo "run_id=${run_id}" >> "${GITHUB_OUTPUT}"

- name: Build job matrix
id: matrix
run: |
jobs="$(kiox -- orun get jobs --plan '${{ steps.plan.outputs.plan_id }}' --all -o json \
| jq -c '[.[] | {job: .id, env: .environment, component: .component}]')"
first_job="$(printf '%s' "${jobs}" | jq -r '.[0].job')"
echo "jobs=${jobs}" >> "${GITHUB_OUTPUT}"
echo "first_job=${first_job}" >> "${GITHUB_OUTPUT}"

- name: Upload compiled plan
uses: actions/upload-artifact@v4
with:
name: orun-plan
path: .orun/plans/
if-no-files-found: error

run-one-job-per-runner:
name: "Run: ${{ matrix.job }}"
needs: plan
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.plan.outputs.jobs) }}
env:
ORUN_BACKEND_URL: ${{ vars.ORUN_BACKEND_URL }}
ORUN_EXEC_ID: ${{ needs.plan.outputs.run_id }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: sourceplane/kiox-action@v2.1.2

- name: Download compiled plan
uses: actions/download-artifact@v4
with:
name: orun-plan
path: .orun/plans/

- name: Run selected job through remote state
run: |
kiox -- orun run '${{ needs.plan.outputs.plan_id }}' \
--job '${{ matrix.job }}' \
--remote-state \
--backend-url "${ORUN_BACKEND_URL}" \
--exec-id "${ORUN_EXEC_ID}" \
--gha \
--verbose

verify:
name: Verify remote status and logs
needs: [plan, run-one-job-per-runner]
if: always()
runs-on: ubuntu-latest
env:
ORUN_BACKEND_URL: ${{ vars.ORUN_BACKEND_URL }}
ORUN_EXEC_ID: ${{ needs.plan.outputs.run_id }}
steps:
- uses: actions/checkout@v4

- uses: sourceplane/kiox-action@v2.1.2

- name: Download compiled plan
uses: actions/download-artifact@v4
with:
name: orun-plan
path: .orun/plans/

- name: Capture remote status
id: status
run: |
status_json="$(kiox -- orun status \
--remote-state \
--backend-url "${ORUN_BACKEND_URL}" \
--exec-id "${ORUN_EXEC_ID}" \
--json)"
echo "${status_json}" | jq .
{
echo 'status_json<<EOF'
echo "${status_json}"
echo 'EOF'
} >> "${GITHUB_OUTPUT}"

- name: Capture remote logs
run: |
kiox -- orun logs \
--remote-state \
--backend-url "${ORUN_BACKEND_URL}" \
--exec-id "${ORUN_EXEC_ID}" \
--job '${{ needs.plan.outputs.first_job }}'

- name: Fail if remote state reports failed or incomplete jobs
env:
STATUS_JSON: ${{ steps.status.outputs.status_json }}
run: |
failed="$(printf '%s' "${STATUS_JSON}" | jq '(.state.jobs // {}) | to_entries | map(select(.value.status == "failed")) | length')"
incomplete="$(printf '%s' "${STATUS_JSON}" | jq '(.state.jobs // {}) | to_entries | map(select(.value.status != "completed")) | length')"
total="$(printf '%s' "${STATUS_JSON}" | jq '(.state.jobs // {}) | to_entries | length')"
completed="$(printf '%s' "${STATUS_JSON}" | jq '(.state.jobs // {}) | to_entries | map(select(.value.status == "completed")) | length')"

if [ "${failed}" -gt 0 ]; then
echo "::error::${failed} remote-state job(s) failed"
exit 1
fi

if [ "${incomplete}" -gt 0 ]; then
echo "::error::${incomplete} remote-state job(s) did not reach completed status"
exit 1
fi

echo "Remote state verification: ${completed}/${total} jobs completed successfully."
```

## Optional guarded automatic trigger

If this workflow becomes a useful recurring lane, add `push` and `pull_request` triggers and gate the `plan` job instead of running it for every PR by default:

```yaml
if: github.event_name == 'workflow_dispatch' || vars.REMOTE_STATE_MATRIX_CI == 'true'
```

That keeps remote-state matrix CI intentionally enabled instead of silently becoming a default branch or PR requirement.

## What this pattern gives you

- one plan compiled once per workflow run
- `.orun/plans/` shared to matrix runners instead of recompiling
- a deterministic `ORUN_EXEC_ID` shared by every runner
- remote job claiming so two runners do not execute the same job
- dependency-aware fan-out where downstream jobs wait until upstream jobs complete
- explicit post-run `orun status --remote-state` and `orun logs --remote-state` inspection
- a hard workflow failure when remote state reports failed or incomplete jobs

## What this guide intentionally omits

The upstream Orun examples also cover duplicate-claim and environment-fanout conformance cases. Those are intentionally omitted here because Stack Tectonic consumer guidance should stay focused on the smallest copyable workflow that proves one-plan matrix coordination.

If you are validating backend semantics rather than adopting the pattern in an application repo, start from the upstream Orun examples instead of this simplified consumer guide.
14 changes: 12 additions & 2 deletions docs/using-this-stack-from-oci.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ compositions:
sources:
- name: stack-tectonic
kind: oci
ref: oci://ghcr.io/sourceplane/stack-tectonic:0.11.0
ref: oci://ghcr.io/sourceplane/stack-tectonic:0.12.0

discovery:
roots:
Expand All @@ -63,11 +63,17 @@ environments:
The important line is the OCI source:

```yaml
ref: oci://ghcr.io/sourceplane/stack-tectonic:0.11.0
ref: oci://ghcr.io/sourceplane/stack-tectonic:0.12.0
```

Pin a released version instead of `latest` so plans stay reproducible.

## Keep remote state opt-in

Most consumer repositories should keep their default local `orun` workflow simple: validate, plan, and run without remote coordination unless they explicitly need matrix-safe distributed runners.

When you do need backend-backed execution, keep it in a dedicated GitHub Actions workflow instead of baking remote state into every default repo run. The copyable advanced example is in [remote-state-matrix-ci.md](remote-state-matrix-ci.md).

## Local component ownership

The consuming repository should keep `component.yaml` files next to the code or infrastructure they own.
Expand Down Expand Up @@ -110,6 +116,10 @@ The component stays repo-local. Only the execution contract for `cloudflare-page
3. Run `orun validate` and `orun plan`.
4. Promote the catalog upgrade through environments like any other platform change.

## GitHub Actions matrix example

For an opt-in consumer workflow that compiles a single plan and runs it through a remote-state matrix in GitHub Actions, see [remote-state-matrix-ci.md](remote-state-matrix-ci.md).

## Why this repo now uses a catalog structure

The old flat layout worked for a small prototype, but it would become noisy as the stack grows. The current layout separates:
Expand Down
8 changes: 4 additions & 4 deletions kiox.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
providers:
- alias: orun
provider: sourceplane/orun
source: ghcr.io/sourceplane/orun:v0.9.6
version: v0.9.6
resolved: ghcr.io/sourceplane/orun@sha256:c259e8c8f2ebacbe68a7eccbbb52fe29e5caa7a502243ef4cc6146664896e1a6
store: c99e023eb0799af3ad9bb3abbb796af41b9c3895b713585276567b3d29486189
source: ghcr.io/sourceplane/orun:v1.12.0
version: v1.12.0
resolved: ghcr.io/sourceplane/orun@sha256:d27e781c68e531542a1968f524bdcf0471b9777f05e098f151bb02d06ba79f33
store: 994e4dd192cd8303e300f15146bf67d44c44df7a3befde5f07656a5695d2e961
2 changes: 1 addition & 1 deletion kiox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ metadata:
name: stack-tectonic
providers:
orun:
source: ghcr.io/sourceplane/orun:v0.9.6
source: ghcr.io/sourceplane/orun:v1.12.0
Loading