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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Every composition now lives under `compositions/<name>/` so docs, examples, test
- [Core concepts](docs/concepts.md)
- [Authoring guide](docs/authoring.md)
- [Verification model](docs/verification.md)
- [Production deploys](docs/production-deploys.md)
- [Roadmap](docs/roadmap.md)
- [Using this stack from OCI](docs/using-this-stack-from-oci.md)

Expand Down
19 changes: 17 additions & 2 deletions compositions/cloudflare-pages-turbo/compositions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ spec:
buildCommand:
type: string
description: Override the default turbo build command
smokeCommand:
type: string
description: Post-deploy verification command (e.g. curl the live Pages URL)
additionalProperties: false
additionalProperties: true
jobs:
Expand Down Expand Up @@ -102,12 +105,15 @@ spec:
shell: bash
run: |
if [ "{{.Environment}}" != "production" ] || [ "${GITHUB_REF:-}" != "refs/heads/{{.productionBranch}}" ]; then
echo "Skipping Cloudflare Pages project reconciliation for {{.Component}} in {{.Environment}} on ${GITHUB_REF:-local}."
echo "::notice::SKIPPED: Cloudflare Pages project reconciliation for {{.Component}} in {{.Environment}} on ${GITHUB_REF:-local} (not production branch)."
exit 0
fi

echo "::group::Validate Cloudflare credentials"
: "${CLOUDFLARE_ACCOUNT_ID:?CLOUDFLARE_ACCOUNT_ID is required for deployment}"
: "${CLOUDFLARE_API_TOKEN:?CLOUDFLARE_API_TOKEN is required for deployment}"
echo "CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN are set."
echo "::endgroup::"

api_root="https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/pages/projects"
response_file="${RUNNER_TEMP:-/tmp}/cloudflare-pages-project.json"
Expand Down Expand Up @@ -140,14 +146,23 @@ spec:
shell: bash
run: |
if [ "{{.Environment}}" != "production" ] || [ "${GITHUB_REF:-}" != "refs/heads/{{.productionBranch}}" ]; then
echo "Skipping Cloudflare Pages deploy for {{.Component}} in {{.Environment}} on ${GITHUB_REF:-local}."
echo "::notice::SKIPPED: Cloudflare Pages deploy for {{.Component}} in {{.Environment}} on ${GITHUB_REF:-local} (not production branch)."
exit 0
fi

: "${CLOUDFLARE_ACCOUNT_ID:?CLOUDFLARE_ACCOUNT_ID is required for deployment}"
: "${CLOUDFLARE_API_TOKEN:?CLOUDFLARE_API_TOKEN is required for deployment}"

echo "::notice::LIVE DEPLOY: Uploading {{.Component}} to Cloudflare Pages from ${GITHUB_REF:-}."
pnpm exec wrangler pages deploy "{{.outputDir}}" \
--project-name "{{.projectName}}" \
--branch "{{.productionBranch}}"

{{if .smokeCommand}}
echo "::group::Post-deploy smoke test"
{{.smokeCommand}}
echo "::endgroup::"
{{end}}

echo "::notice::DEPLOY SUCCESS: {{.Component}} deployed to Cloudflare Pages."
onFailure: stop
48 changes: 45 additions & 3 deletions compositions/cloudflare-worker-turbo/compositions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ spec:
productionBranch:
type: string
description: Branch that is allowed to deploy the Worker app
wranglerConfig:
type: string
description: Wrangler config filename (defaults to detecting wrangler.jsonc or wrangler.toml)
preBuildCommand:
type: string
description: Optional command to run before the build (e.g. codegen, schema generation)
Expand All @@ -48,9 +51,18 @@ spec:
typecheckCommand:
type: string
description: Override the default turbo typecheck command
preDeployCommand:
type: string
description: Command to run before deploy (e.g. resource provisioning, D1 database creation)
migrationCommand:
type: string
description: Command to run D1 migrations or other pre-deploy schema changes
deployCommand:
type: string
description: Override the default deploy command
smokeCommand:
type: string
description: Post-deploy verification command (e.g. curl the live endpoint)
additionalProperties: false
additionalProperties: true
jobs:
Expand Down Expand Up @@ -88,7 +100,11 @@ spec:
shell: bash
run: |
test -f package.json
test -f wrangler.jsonc
{{if .wranglerConfig}}
test -f "{{.wranglerConfig}}"
{{else}}
test -f wrangler.jsonc || test -f wrangler.toml
{{end}}
onFailure: stop
- name: build-worker
run: "{{if .buildCommand}}{{.buildCommand}}{{else}}pnpm exec turbo run build --filter=./{{end}}"
Expand All @@ -100,18 +116,44 @@ spec:
shell: bash
run: |
if [ "{{.Environment}}" = "dev" ]; then
echo "Running wrangler deploy dry-run for {{.Component}} in dev environment."
echo "::notice::DRY-RUN: Running wrangler deploy --dry-run for {{.Component}} in dev environment."
pnpm exec wrangler deploy --dry-run
exit 0
fi

if [ "{{.Environment}}" != "production" ] || [ "${GITHUB_REF:-}" != "refs/heads/{{.productionBranch}}" ]; then
echo "Skipping Cloudflare Worker deploy for {{.Component}} in {{.Environment}} on ${GITHUB_REF:-local}."
echo "::notice::SKIPPED: Cloudflare Worker deploy for {{.Component}} in {{.Environment}} on ${GITHUB_REF:-local} (not production branch)."
exit 0
fi

echo "::group::Validate Cloudflare credentials"
: "${CLOUDFLARE_ACCOUNT_ID:?CLOUDFLARE_ACCOUNT_ID is required for deploy}"
: "${CLOUDFLARE_API_TOKEN:?CLOUDFLARE_API_TOKEN is required for deploy}"
echo "CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN are set."
echo "::endgroup::"

{{if .preDeployCommand}}
echo "::group::Pre-deploy"
{{.preDeployCommand}}
echo "::endgroup::"
{{end}}

{{if .migrationCommand}}
echo "::group::Run migrations"
{{.migrationCommand}}
echo "::endgroup::"
{{end}}

echo "::group::Deploy Worker"
echo "::notice::LIVE DEPLOY: Deploying {{.Component}} to Cloudflare from ${GITHUB_REF:-}."
{{if .deployCommand}}{{.deployCommand}}{{else}}pnpm run deploy{{end}}
echo "::endgroup::"

{{if .smokeCommand}}
echo "::group::Post-deploy smoke test"
{{.smokeCommand}}
echo "::endgroup::"
{{end}}

echo "::notice::DEPLOY SUCCESS: {{.Component}} deployed to Cloudflare."
onFailure: stop
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ spec:
nodeVersion: "20"
pnpmVersion: "10.12.1"
productionBranch: main
# Optional: specify wrangler config file explicitly
# wranglerConfig: wrangler.jsonc
# Optional: run D1 migrations before deploy
# migrationCommand: "pnpm exec wrangler d1 migrations apply my-db --remote"
# Optional: provision resources before deploy
# preDeployCommand: "./scripts/bootstrap-cloudflare.sh"
# Optional: verify live endpoint after deploy
# smokeCommand: "curl -sf https://my-api.workers.dev/health"
labels:
team: platform
layer: runtime
surface: api
runtime: cloudflare
runtime: cloudflare
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ spec:
team: platform
layer: runtime
surface: api
runtime: cloudflare
runtime: cloudflare
46 changes: 44 additions & 2 deletions compositions/cloudflare-worker/compositions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ spec:
productionBranch:
type: string
description: Branch that is allowed to deploy the Worker app
wranglerConfig:
type: string
description: Wrangler config filename (defaults to detecting wrangler.jsonc or wrangler.toml)
preDeployCommand:
type: string
description: Command to run before deploy (e.g. resource provisioning, D1 database creation)
migrationCommand:
type: string
description: Command to run D1 migrations or other pre-deploy schema changes
smokeCommand:
type: string
description: Post-deploy verification command (e.g. curl the live endpoint)
additionalProperties: false
additionalProperties: true
jobs:
Expand Down Expand Up @@ -81,7 +93,11 @@ spec:
shell: bash
run: |
test -f package.json
{{if .wranglerConfig}}
test -f "{{.wranglerConfig}}"
{{else}}
test -f wrangler.jsonc || test -f wrangler.toml
{{end}}
onFailure: stop
- name: build-worker
run: "{{.buildCommand}}"
Expand All @@ -99,18 +115,44 @@ spec:
shell: bash
run: |
if [ "{{.Environment}}" = "dev" ]; then
echo "Running wrangler deploy dry-run for {{.Component}} in dev environment."
echo "::notice::DRY-RUN: Running wrangler deploy --dry-run for {{.Component}} in dev environment."
pnpm exec wrangler deploy --dry-run
exit 0
fi

if [ "{{.Environment}}" != "production" ] || [ "${GITHUB_REF:-}" != "refs/heads/{{.productionBranch}}" ]; then
echo "Skipping Cloudflare Worker deploy for {{.Component}} in {{.Environment}} on ${GITHUB_REF:-local}."
echo "::notice::SKIPPED: Cloudflare Worker deploy for {{.Component}} in {{.Environment}} on ${GITHUB_REF:-local} (not production branch)."
exit 0
fi

echo "::group::Validate Cloudflare credentials"
: "${CLOUDFLARE_ACCOUNT_ID:?CLOUDFLARE_ACCOUNT_ID is required for deploy}"
: "${CLOUDFLARE_API_TOKEN:?CLOUDFLARE_API_TOKEN is required for deploy}"
echo "CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN are set."
echo "::endgroup::"

{{if .preDeployCommand}}
echo "::group::Pre-deploy"
{{.preDeployCommand}}
echo "::endgroup::"
{{end}}

{{if .migrationCommand}}
echo "::group::Run migrations"
{{.migrationCommand}}
echo "::endgroup::"
{{end}}

echo "::group::Deploy Worker"
echo "::notice::LIVE DEPLOY: Deploying {{.Component}} to Cloudflare from ${GITHUB_REF:-}."
{{.deployCommand}}
echo "::endgroup::"

{{if .smokeCommand}}
echo "::group::Post-deploy smoke test"
{{.smokeCommand}}
echo "::endgroup::"
{{end}}

echo "::notice::DEPLOY SUCCESS: {{.Component}} deployed to Cloudflare."
onFailure: stop
98 changes: 98 additions & 0 deletions docs/production-deploys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Production deploys

This document explains how to configure reliable production deployments using stack-tectonic compositions on the production branch.

## The `--changed` trap

When using `orun run --changed` on production branch pushes (e.g. after a squash merge to `main`), the change detection compares the merge commit against its parent. Because a squash merge produces a single commit whose parent is the previous `main` HEAD, and the new commit already includes all changes, `--changed` may resolve to zero changed components:

```text
0 components x 3 envs -> 0 jobs
```

This produces a **green CI run with zero deployments** — a false positive that masks the absence of any live deployment.

## Recommended patterns

### Pattern 1: Run all production jobs on main (recommended for small repos)

Remove `--changed` from the production branch push step:

```yaml
- name: Execute
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
run: kiox -- orun run
```

This ensures every deployable component runs its production job on every push to main. For repos with fewer than 10 components, this adds minimal overhead.

### Pattern 2: Changed-only with correct base ref

If the repo has many components and full runs are expensive, pass explicit base/head refs:

```yaml
- name: Execute
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
run: kiox -- orun run --changed --base "${{ github.event.before }}" --head "${{ github.sha }}"
```

Using `github.event.before` as the base ensures the diff covers the actual changes introduced by the merge.

### Pattern 3: Separate deploy workflow on main

Keep `--changed` for PR validation but add a dedicated production deploy step:

```yaml
jobs:
deploy:
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: sourceplane/kiox-action@v2.1.2
with:
version: v0.4.3
- name: Deploy all production components
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
run: kiox -- orun run --env production
```

## Composition behavior

Stack-tectonic Cloudflare compositions (`cloudflare-worker-turbo`, `cloudflare-worker`, `cloudflare-pages-turbo`, `cloudflare-pages`) all follow the same deploy semantics:

| Condition | Behavior | CI annotation |
| --- | --- | --- |
| Environment = `dev` | Dry-run only | `DRY-RUN` |
| Environment != `production` or branch != `productionBranch` | Skip deploy | `SKIPPED` |
| Environment = `production` AND branch = `productionBranch` AND credentials present | Live deploy | `LIVE DEPLOY` → `DEPLOY SUCCESS` |
| Credentials missing on production deploy | Hard failure | Step fails with clear error |

## Verifying a deploy actually happened

After a production push, check CI logs for:
- `::notice::LIVE DEPLOY: Deploying <component> to Cloudflare`
- `::notice::DEPLOY SUCCESS: <component> deployed to Cloudflare`

If you see only `SKIPPED` or `DRY-RUN` annotations, the deploy did not run.

A green run with `0 components x 3 envs -> 0 jobs` means **no deployment occurred**. This is never evidence of a successful deploy.

## Consumer repo checklist

Before relying on production deploys:

1. Set `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN` as GitHub repository secrets
2. Ensure your workflow passes these as environment variables to the `orun run` step
3. Choose one of the patterns above for your production branch push behavior
4. Replace `PLACEHOLDER` database IDs in `wrangler.jsonc` with real resource IDs
5. If using D1, configure `migrationCommand` in your `component.yaml` inputs
6. Optionally add `smokeCommand` to verify the live endpoint after deploy
4 changes: 2 additions & 2 deletions registry/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"stack": {
"name": "stack-tectonic",
"title": "Stack Tectonic",
"version": "0.11.0",
"oci": "oci://ghcr.io/sourceplane/stack-tectonic:0.11.0"
"version": "0.12.0",
"oci": "oci://ghcr.io/sourceplane/stack-tectonic:0.12.0"
},
"catalog": {
"compositions": [
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Stack
metadata:
name: stack-tectonic
title: Stack Tectonic
version: 0.11.0
version: 0.12.0
description: Versioned OCI-hosted catalog of platform compositions and blueprints for Sourceplane repositories.
owner: sourceplane
tags:
Expand Down
Loading