This document describes the reusable GitHub Actions scaffolding generated by cpflow generate-github-actions.
The goal is to bring the Heroku Flow model into any cpflow project:
- Comment
/deploy-review-appon a pull request to create or update a review app. - Push more commits to the PR to auto-redeploy that review app.
- Push to the staging branch to auto-deploy staging.
- Promote the already-built staging artifact to production from the Actions tab.
- Let a nightly workflow clean up stale review apps.
End-to-end rollout in one view:
cpflow github-flow-readiness— exits non-zero if the repo is not ready to deploy.cpflow generate— creates.controlplane/if missing.cpflow generate-github-actions— adds thecpflow-*composite actions and workflows.- Configure the GitHub repository secrets and variables the workflows expect.
- Push the branch, then comment
/deploy-review-appon a PR to spin up a review environment.
See Bootstrap a Project for command details, Repo Readiness Checklist for what "ready" means, and AI Playbook to run the rollout through an agent.
Run these commands from the project root:
# Check the repo for common rollout blockers before generating files
cpflow github-flow-readiness
# Print the current AI rollout prompt for this repo, if you want to hand it to an agent
cpflow ai-github-flow-prompt
# Create .controlplane/ if it does not exist yet
cpflow generate
# Add reusable GitHub Actions for the Control Plane flow
cpflow generate-github-actionsThese local bootstrap commands do not require cpln to be installed yet. Install and
log into the Control Plane CLI before any command that talks to the real platform.
cpflow github-flow-readiness is the fastest gate: it exits non-zero when the repo is
missing a production Dockerfile, missing Rails runtime files, pinned to a legacy
Ruby or Bundler toolchain, or depends on exact-pinned gem or npm versions that do
not appear to exist in the public registries.
The second command writes namespaced files so they can coexist with an app's existing CI:
.github/actions/cpflow-build-docker-image/action.yml.github/actions/cpflow-delete-control-plane-app/action.yml.github/actions/cpflow-delete-control-plane-app/delete-app.sh.github/actions/cpflow-setup-environment/action.yml.github/workflows/cpflow-review-app-help.yml.github/workflows/cpflow-help-command.yml.github/workflows/cpflow-deploy-review-app.yml.github/workflows/cpflow-delete-review-app.yml.github/workflows/cpflow-deploy-staging.yml.github/workflows/cpflow-promote-staging-to-production.yml.github/workflows/cpflow-cleanup-stale-review-apps.yml
cpflow generate also infers the app prefix from the repo directory, infers the
Docker base Ruby version from .ruby-version, .tool-versions, or the app's
Gemfile, preserves repo-defined frontend precompile hooks such as Shakapacker
precompile_hook commands or React on Rails auto bundle generation, and
switches to persistent SQLite db and storage templates when
config/database.yml shows SQLite in production.
Before generating this flow, confirm that the target repository is already a deployable application rather than a partial sample:
- the repo can be cloned and installed from scratch with published gem and npm package versions
- the repo does not depend on unpublished or inaccessible package versions unless the deployment flow also provisions the credentials needed to fetch them
- the repo is not just a historical generator snapshot pinned to an obsolete Ruby or Bundler toolchain with no validated production build path
- the app has its real runtime scaffold checked in, for example a complete Rails
app with the boot files needed to run
bin/railsandbin/dev - the repo root maps to one deployable app; multi-app monorepos need a separate rollout decision before using this one-app-per-repo flow
- the production Dockerfile can build the app's assets and any SSR or renderer bundles that production needs
- any repo-defined frontend codegen or precompile hooks are preserved before
rails assets:precompile - the runtime workloads, release command, and required secrets are known well
enough to model in
.controlplane/
If any of those fail, stop and fix the application first. Do not merge
cpflow-* workflows into a repository that is not yet runnable from a clean
clone, because the result will be a misleading "deployment flow" for an app that
still cannot build or boot.
The generated workflows assume that .controlplane/controlplane.yml defines:
- one staging app
- one review-app prefix with
match_if_app_name_starts_with: true - one production app with
upstreampointing to staging
Typical shape:
aliases:
common: &common
cpln_org: my-org-staging
default_location: aws-us-east-2
setup_app_templates:
- app
- postgres
- redis
- rails
app_workloads:
- rails
additional_workloads:
- postgres
- redis
apps:
my-app-staging:
<<: *common
my-app-review:
<<: *common
match_if_app_name_starts_with: true
hooks:
post_creation: bundle exec rails db:prepare
pre_deletion: bundle exec rails db:drop
my-app-production:
<<: *common
allow_org_override_by_env: false
allow_app_override_by_env: false
cpln_org: my-org-production
upstream: my-app-staging
release_script: release_script.shImportant points:
REVIEW_APP_PREFIXin GitHub Actions must match the review config key prefix, for examplemy-app-review.match_if_app_name_starts_with: trueis what allows a single config entry to backmy-app-review-123,my-app-review-456, and cleanup commands likecpflow cleanup-stale-apps -a my-app-review.upstream: my-app-stagingis what lets the production promotion workflow copy the exact staging artifact.- If your main web workload is not named
rails, set the optionalPRIMARY_WORKLOADrepository variable described below.
Configure these repository secrets:
CPLN_TOKEN_STAGING: token for the staging Control Plane orgCPLN_TOKEN_PRODUCTION: token for the production Control Plane org
Configure these repository variables:
CPLN_ORG_STAGING: staging org name, for examplecompany-stagingCPLN_ORG_PRODUCTION: production org name, for examplecompany-productionSTAGING_APP_NAME: staging GVC name, for examplemy-app-stagingPRODUCTION_APP_NAME: production GVC name, for examplemy-app-productionREVIEW_APP_PREFIX: review-app prefix, for examplemy-app-reviewSTAGING_APP_BRANCH: optional branch that auto-deploys staging; defaults tomainormasterif unsetPRIMARY_WORKLOAD: optional workload name used to discover the public endpoint and do production health checks; defaults torailsDOCKER_BUILD_EXTRA_ARGS: optional newline-delimited singledocker buildtokens passed through tocpflow build-image, for example--build-arg=FOO=baror--secret=id=npmrc,src=.npmrcDOCKER_BUILD_SSH_KNOWN_HOSTS: optional multi-lineknown_hostscontent used withDOCKER_BUILD_SSH_KEYwhen the build needs SSH access to hosts other than GitHub.com
Recommended org layout:
- keep review apps and staging in a staging org that developers can access
- keep production in a separate org with tighter access controls
Optional repository secret for private dependency builds:
DOCKER_BUILD_SSH_KEY: private SSH key used when the Dockerfile needsRUN --mount=type=sshto fetch private GitHub dependencies during image build
Some apps need extra Docker build configuration before the generated workflows are turnkey. Common examples are:
pnpm,npm,yarn, or Bundler dependencies pulled from private GitHub repositories- Dockerfiles that already use
RUN --mount=type=ssh - builds that need extra
--build-arg,--secret, or relateddocker buildflags
The generated cpflow-build-docker-image action supports this without hardcoding app-specific logic:
- set
DOCKER_BUILD_SSH_KEYif the Docker build needs SSH access to GitHub - optionally set
DOCKER_BUILD_SSH_KNOWN_HOSTSwhen the SSH build host is not GitHub.com or you need custom host entries - set
DOCKER_BUILD_EXTRA_ARGSwhen you need extradocker buildflags
For example, a repo that installs private dependencies from GitHub during Docker build can set:
DOCKER_BUILD_SSH_KEY=<private deploy key secret>
DOCKER_BUILD_SSH_KNOWN_HOSTS=git.example.com ssh-ed25519 AAAA...
DOCKER_BUILD_EXTRA_ARGS=--build-arg=BUNDLE_WITHOUT=development:test
The action will start an SSH agent, add the key, write known_hosts, and pass --ssh=default to cpflow build-image. When DOCKER_BUILD_SSH_KNOWN_HOSTS is unset, the generated action uses pinned GitHub.com host keys by default. If your Dockerfile relies on RUN --mount=type=ssh, validate the build locally with cpflow build-image -a <app> --ssh=default before relying on CI.
cpflow-review-app-help.yml
- Posts a quick reference when a pull request opens, including on fork-based PRs.
cpflow-help-command.yml
- Replies to
/helpon a pull request with the commands and required repo settings.
cpflow-deploy-review-app.yml
- Creates a review app when someone comments
/deploy-review-app. - Redeploys an existing review app automatically on later PR pushes.
- Creates a GitHub deployment and comments with the review URL and logs.
- Leaves PR pushes alone until the first review app is explicitly requested, which keeps demo-app costs down.
- Accepts
/deploy-review-apponly from trusted commenters (OWNER,MEMBER, orCOLLABORATOR). - Skips fork-based PR deploys because the workflow builds Docker images with repository secrets.
cpflow-delete-review-app.yml
- Deletes the review app on
/delete-review-app. - Also deletes it automatically when the pull request closes.
- Accepts
/delete-review-apponly from trusted commenters (OWNER,MEMBER, orCOLLABORATOR).
cpflow-deploy-staging.yml
- Builds and deploys the staging app on pushes to
STAGING_APP_BRANCH. - Falls back to
mainormasterwhenSTAGING_APP_BRANCHis unset. - Fails fast when required staging repo settings are missing instead of surfacing opaque
cpflowerrors.
cpflow-promote-staging-to-production.yml
- Manually promotes the staging artifact to production with a confirmation input.
- Verifies that production has the env var names staging expects.
- Runs a health check against
PRIMARY_WORKLOAD. - Attempts a rollback of every configured application workload if the new production image does not come up healthy.
- Creates a GitHub release after a successful promotion.
cpflow-cleanup-stale-review-apps.yml
- Runs nightly and on demand.
- Deletes stale review apps using
cpflow cleanup-stale-apps.
The generated workflows share these local composite actions:
cpflow-setup-environment: installs Ruby, the Control Plane CLI, and thecpflowgem, then logs into the target orgcpflow-build-docker-image: builds and pushes the app image with the desired commit SHAcpflow-delete-control-plane-app: safely deletes temporary apps and refuses to touch names outside the configured review-app prefix
This flow is a good fit for the React on Rails demo apps because they already follow the same basic assumptions:
- the deployable app is a Rails project
- the primary web workload is usually
rails - review environments should be temporary and opt-in
- staging should auto-follow a single branch
- production should promote the already-tested staging image
In practice, porting the flow into a demo app usually follows five phases.
Before generating:
- Confirm the repo passes the readiness checklist above.
- Generate
.controlplane/if the app does not have it yet. - Generate the
cpflow-*GitHub Actions files.
Verify the generated scaffold:
- Update
.controlplane/controlplane.ymlwith staging, review, and production entries. - Confirm that the generated Dockerfile picked a Ruby base image compatible with the app's declared Ruby requirement.
- For SQLite-backed apps, confirm that the generated scaffold switched to persistent
dbandstoragevolumes, mounted them into the main workload, and added a release script that runsrails db:prepare.
Adapt for the app's runtime:
- Keep Node available in the final app image whenever Rails asset compilation or SSR depends on ExecJS or frontend package managers at build or runtime.
- Preserve repo-defined frontend precompile hooks, such as Shakapacker
precompile_hookcommands or React on Railsconfig.auto_load_bundle = true, beforerails assets:precompile. - Add any additional app workloads the app needs at runtime, for example
sidekiq, a Node renderer, or any other process type that should deploy the same application image. - Adjust
PRIMARY_WORKLOADonly if the public workload is not namedrails.
Wire up GitHub secrets, variables, and private builds:
- Make sure the repo variables and secrets line up with the configured app names.
- If the Dockerfile pulls private dependencies over SSH, configure
DOCKER_BUILD_SSH_KEY, addDOCKER_BUILD_SSH_KNOWN_HOSTSwhen the host is not GitHub.com, and validate that the image can build withRUN --mount=type=ssh.
Validate and push:
- Validate the real production Docker build before relying on the workflows, especially if asset compilation or SSR requires Node, extra system packages, multiple processes, extra Docker build flags, or persistent writable paths.
- Expect review app deploys to run only for branches in the base repository; fork PRs still get help comments, but deploys are skipped because the workflow uses repository secrets.
If you want an AI agent to apply this flow to another project, start with
cpflow github-flow-readiness, then use the standalone
AI rollout prompt. It captures the exact wording,
hard stop conditions, and definition of done for this workflow. You can also
run cpflow ai-github-flow-prompt from inside the target repo to print the
current prompt with that repo's default app prefix already filled in.
Short version:
Set up Control Plane GitHub Flow for this repo. Start with `cpflow github-flow-readiness` and stop on any reported blockers. The repo must be deployable from a clean clone, with published package versions and a production Dockerfile that can really build the app. Stop and report blockers for unpublished packages, inaccessible private dependencies, legacy toolchains, or missing production build paths instead of generating workflows blindly. Then run `cpflow generate` if `.controlplane/` is missing, run `cpflow generate-github-actions`, adapt the generated scaffold to the real workloads, document the required GitHub secrets and variables, validate the real build path locally, push the branch, and check the GitHub Actions results.
Expand that prompt with app-specific requirements before editing files:
- verify the repo is a real deployable app, not a partial code sample or a demo pinned to unpublished package versions
- stop and report a scope decision when the repo is a monorepo or contains multiple deployable apps without an already-decided single flow target
- inspect the production Dockerfile and make sure it can build the app's assets in CI
- make sure the generated Dockerfile uses a Ruby base image compatible with the app's declared Ruby requirement
- preserve repo-defined frontend precompile hooks, such as Shakapacker
precompile_hookcommands or React on Railsconfig.auto_load_bundle = true - keep Node available in the final image if Rails or SSR depends on ExecJS, Yarn, or
pnpmafter the mainnpm installlayer - if
config/database.ymlshows SQLite in production, confirm thatcpflow generateemitted persistentdbandstoragevolumes plus arails db:preparerelease script; otherwise keep the default Postgres workload - inspect the production Dockerfile and package sources for private GitHub dependencies, and wire
DOCKER_BUILD_SSH_KEYplusDOCKER_BUILD_SSH_KNOWN_HOSTSwhen the build usesRUN --mount=type=sshagainst non-GitHub hosts - add extra
app_workloadsand template files for any runtime sidecars, workers, or renderer processes - make sure any sidecar process exposed to sibling workloads binds to
0.0.0.0instead of container-locallocalhost - make sure sidecar caches or bundle directories live in writable paths for the runtime user, such as
tmp/, instead of root-owned image paths - keep workflow files generic and put app names, org names, branch names, and Docker build knobs in repository
varsandsecrets
When the agent applies this to a project, it should avoid hardcoding app names or org names into the workflow files. Those belong in repository vars and secrets.