-
Notifications
You must be signed in to change notification settings - Fork 0
Add Control Plane GitHub flow #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
justin808
wants to merge
6
commits into
main
Choose a base branch
from
add-cpflow-github-flow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fc397aa
Add Control Plane GitHub flow
justin808 d236f86
Restore CI Ruby version file
justin808 fd6b542
Fix demo CI prerequisites
justin808 957b012
Generate packs before test bundle build
justin808 0910a27
Sync Control Plane flow hardening
justin808 288dd05
Tighten Docker build action arguments
justin808 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # Keys beginning with "cpln_" correspond to your settings in Control Plane. | ||
| # | ||
| # This demo uses the repository root Dockerfile and mounts `/rails/storage` | ||
| # so SQLite, Solid Cache, Solid Queue, and Solid Cable state persist. | ||
|
|
||
| allow_org_override_by_env: true | ||
| allow_app_override_by_env: true | ||
|
|
||
| aliases: | ||
| common: &common | ||
| cpln_org: my-org-staging | ||
| default_location: aws-us-east-2 | ||
|
|
||
| setup_app_templates: | ||
| - app | ||
| - storage | ||
| - rails | ||
|
|
||
| one_off_workload: rails | ||
| app_workloads: | ||
| - rails | ||
| additional_workloads: [] | ||
|
|
||
| dockerfile: ../Dockerfile | ||
| release_script: release_script.sh | ||
|
|
||
| stale_app_image_deployed_days: 5 | ||
| image_retention_days: 7 | ||
|
|
||
| production: &production | ||
| <<: *common | ||
| allow_org_override_by_env: false | ||
| allow_app_override_by_env: false | ||
| cpln_org: my-org-production | ||
| upstream: react-on-rails-demo-v16-ssr-staging | ||
|
|
||
| apps: | ||
| react-on-rails-demo-v16-ssr-staging: | ||
| <<: *common | ||
|
|
||
| react-on-rails-demo-v16-ssr-review: | ||
| <<: *common | ||
| match_if_app_name_starts_with: true | ||
|
|
||
| react-on-rails-demo-v16-ssr-production: | ||
| <<: *production |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # Control Plane Deployment Notes | ||
|
|
||
| This repo now includes `cpflow` scaffolding for: | ||
|
|
||
| - opt-in PR review apps | ||
| - automatic staging deploys from `main` | ||
| - manual promotion from staging to production | ||
|
|
||
| ## Why This Shape | ||
|
|
||
| This app ships a production-ready Dockerfile at the repository root and stores | ||
| its production SQLite, Solid Cache, Solid Queue, and Solid Cable databases under | ||
| `/rails/storage`. | ||
|
|
||
| The Control Plane setup mirrors that: | ||
|
|
||
| - `.controlplane/controlplane.yml` points `dockerfile: ../Dockerfile` | ||
| - `templates/storage.yml` creates a persistent volume for `/rails/storage` | ||
| - `templates/rails.yml` runs the public `rails` workload on port `80` | ||
| - `release_script.sh` runs `bin/rails db:prepare` before deploys switch images | ||
|
|
||
| The root `Dockerfile` now installs Node.js in both the build and runtime stages, | ||
| compiles the auto-generated React on Rails packs plus `server-bundle.js`, and | ||
| keeps Node available for ExecJS-based SSR at runtime. | ||
|
|
||
| ## Required Runtime Secrets | ||
|
|
||
| Before the app will boot on Control Plane, populate `SECRET_KEY_BASE` in the | ||
| generated secret dictionaries: | ||
|
|
||
| - `react-on-rails-demo-v16-ssr-staging-secrets` | ||
| - `react-on-rails-demo-v16-ssr-review-secrets` | ||
| - `react-on-rails-demo-v16-ssr-production-secrets` | ||
|
|
||
| `cpflow setup-app` creates those dictionaries automatically. You only need to | ||
| add a `SECRET_KEY_BASE` entry to each one before the first deploy. | ||
|
|
||
| ## Local cpflow Flow | ||
|
|
||
| Typical setup: | ||
|
|
||
| ```sh | ||
| export APP_NAME=react-on-rails-demo-v16-ssr-staging | ||
|
|
||
| cpflow setup-app -a "$APP_NAME" | ||
| cpflow build-image -a "$APP_NAME" | ||
| cpflow deploy-image -a "$APP_NAME" --run-release-phase | ||
| cpflow open -a "$APP_NAME" | ||
| ``` | ||
|
|
||
| ## GitHub Actions Variables And Secrets | ||
|
|
||
| Set these in GitHub before enabling the generated `cpflow-*` workflows: | ||
|
|
||
| - `CPLN_TOKEN_STAGING` | ||
| - `CPLN_TOKEN_PRODUCTION` | ||
| - `CPLN_ORG_STAGING` | ||
| - `CPLN_ORG_PRODUCTION` | ||
| - `STAGING_APP_NAME=react-on-rails-demo-v16-ssr-staging` | ||
| - `PRODUCTION_APP_NAME=react-on-rails-demo-v16-ssr-production` | ||
| - `REVIEW_APP_PREFIX=react-on-rails-demo-v16-ssr-review` | ||
|
|
||
| Optional: | ||
|
|
||
| - `STAGING_APP_BRANCH=main` | ||
| - `PRIMARY_WORKLOAD=rails` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| ./bin/rails db:prepare |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| kind: gvc | ||
| name: {{APP_NAME}} | ||
| spec: | ||
| env: | ||
| - name: RAILS_ENV | ||
| value: production | ||
| - name: RAILS_LOG_LEVEL | ||
| value: info | ||
| - name: RAILS_SERVE_STATIC_FILES | ||
| value: "true" | ||
| - name: SOLID_QUEUE_IN_PUMA | ||
| value: "true" | ||
| - name: SECRET_KEY_BASE | ||
| value: cpln://secret/{{APP_SECRETS}}.SECRET_KEY_BASE | ||
| staticPlacement: | ||
| locationLinks: | ||
| - {{APP_LOCATION_LINK}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| kind: workload | ||
| name: rails | ||
| spec: | ||
| type: standard | ||
| containers: | ||
| - name: rails | ||
| cpu: 500m | ||
| inheritEnv: true | ||
| image: {{APP_IMAGE_LINK}} | ||
| memory: 1Gi | ||
| ports: | ||
| - number: 80 | ||
| protocol: http | ||
| volumes: | ||
| - path: /rails/storage | ||
| recoveryPolicy: retain | ||
| uri: cpln://volumeset/rails-storage | ||
| defaultOptions: | ||
| autoscaling: | ||
| minScale: 1 | ||
| maxScale: 1 | ||
| capacityAI: false | ||
| timeoutSeconds: 60 | ||
| firewallConfig: | ||
| external: | ||
| inboundAllowCIDR: | ||
| - 0.0.0.0/0 | ||
| outboundAllowCIDR: | ||
| - 0.0.0.0/0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| kind: volumeset | ||
| name: rails-storage | ||
| spec: | ||
| fileSystemType: ext4 | ||
| initialCapacity: 10 | ||
| performanceClass: general-purpose-ssd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| name: Build Docker Image | ||
| description: Builds and pushes the app image for a Control Plane workload | ||
|
|
||
| inputs: | ||
| app_name: | ||
| description: Name of the application | ||
| required: true | ||
| org: | ||
| description: Control Plane organization name | ||
| required: true | ||
| commit: | ||
| description: Commit SHA to tag the image with | ||
| required: true | ||
| pr_number: | ||
| description: Pull request number for status messaging | ||
| required: false | ||
| docker_build_extra_args: | ||
| description: Optional newline-delimited extra arguments passed through to docker build | ||
| required: false | ||
| docker_build_ssh_key: | ||
| description: Optional private SSH key used for Docker builds that fetch private dependencies with RUN --mount=type=ssh | ||
| required: false | ||
|
|
||
| outputs: | ||
| image_tag: | ||
| description: Fully qualified image tag | ||
| value: ${{ steps.build.outputs.image_tag }} | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Build Docker image | ||
| id: build | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| PR_INFO="" | ||
| docker_build_args=() | ||
|
|
||
| if [[ -n "${{ inputs.pr_number }}" ]]; then | ||
| PR_INFO=" for PR #${{ inputs.pr_number }}" | ||
| fi | ||
|
|
||
| if [[ -n "${{ inputs.docker_build_extra_args }}" ]]; then | ||
| while IFS= read -r arg; do | ||
| arg="${arg%$'\r'}" | ||
| [[ -n "${arg}" ]] || continue | ||
| docker_build_args+=("${arg}") | ||
| done <<< "${{ inputs.docker_build_extra_args }}" | ||
| fi | ||
|
|
||
| if [[ -n "${{ inputs.docker_build_ssh_key }}" ]]; then | ||
| mkdir -p ~/.ssh | ||
| chmod 700 ~/.ssh | ||
| ssh-keyscan -H github.com >> ~/.ssh/known_hosts | ||
| chmod 600 ~/.ssh/known_hosts | ||
|
|
||
| eval "$(ssh-agent -s)" | ||
| trap 'ssh-agent -k >/dev/null' EXIT | ||
| ssh-add - <<< "${{ inputs.docker_build_ssh_key }}" | ||
| docker_build_args+=("--ssh" "default") | ||
| fi | ||
|
|
||
| echo "🏗️ Building Docker image${PR_INFO} (commit ${{ inputs.commit }})..." | ||
| cpflow build-image -a "${{ inputs.app_name }}" --commit="${{ inputs.commit }}" --org="${{ inputs.org }}" "${docker_build_args[@]}" | ||
|
|
||
| image_tag="${{ inputs.org }}/${{ inputs.app_name }}:${{ inputs.commit }}" | ||
| echo "image_tag=${image_tag}" >> "$GITHUB_OUTPUT" | ||
| echo "✅ Docker image build successful${PR_INFO} (commit ${{ inputs.commit }})" |
24 changes: 24 additions & 0 deletions
24
.github/actions/cpflow-delete-control-plane-app/action.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| name: Delete Control Plane App | ||
| description: Deletes a Control Plane app and all associated resources | ||
|
|
||
| inputs: | ||
| app_name: | ||
| description: Name of the application to delete | ||
| required: true | ||
| cpln_org: | ||
| description: Control Plane organization name | ||
| required: true | ||
| review_app_prefix: | ||
| description: Prefix used for review app names | ||
| required: true | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Delete application | ||
| shell: bash | ||
| run: ${{ github.action_path }}/delete-app.sh | ||
| env: | ||
| APP_NAME: ${{ inputs.app_name }} | ||
| CPLN_ORG: ${{ inputs.cpln_org }} | ||
| REVIEW_APP_PREFIX: ${{ inputs.review_app_prefix }} |
37 changes: 37 additions & 0 deletions
37
.github/actions/cpflow-delete-control-plane-app/delete-app.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| : "${APP_NAME:?APP_NAME environment variable is required}" | ||
| : "${CPLN_ORG:?CPLN_ORG environment variable is required}" | ||
| : "${REVIEW_APP_PREFIX:?REVIEW_APP_PREFIX environment variable is required}" | ||
|
|
||
| expected_prefix="${REVIEW_APP_PREFIX}-" | ||
| if [[ "$APP_NAME" != "${expected_prefix}"* ]]; then | ||
| echo "❌ ERROR: refusing to delete an app outside the review app prefix" >&2 | ||
| echo "App name: $APP_NAME" >&2 | ||
| echo "Expected prefix: ${expected_prefix}" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "🔍 Checking if application exists: $APP_NAME" | ||
| exists_output="" | ||
| if ! exists_output="$(cpflow exists -a "$APP_NAME" --org "$CPLN_ORG" 2>&1)"; then | ||
| if [[ -z "$exists_output" ]]; then | ||
| echo "⚠️ Application does not exist: $APP_NAME" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "❌ ERROR: failed to determine whether application exists: $APP_NAME" >&2 | ||
| printf '%s\n' "$exists_output" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ -n "$exists_output" ]]; then | ||
| printf '%s\n' "$exists_output" | ||
| fi | ||
|
|
||
| echo "🗑️ Deleting application: $APP_NAME" | ||
| cpflow delete -a "$APP_NAME" --org "$CPLN_ORG" --yes | ||
|
|
||
| echo "✅ Successfully deleted application: $APP_NAME" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| name: Setup Control Plane Environment | ||
| description: Sets up Ruby, installs the Control Plane CLI and cpflow gem, and configures a default profile | ||
|
|
||
| inputs: | ||
| token: | ||
| description: Control Plane token | ||
| required: true | ||
| org: | ||
| description: Control Plane organization | ||
| required: true | ||
| ruby_version: | ||
| description: Ruby version used for cpflow | ||
| required: false | ||
| default: "3.4.6" | ||
| cpln_cli_version: | ||
| description: "@controlplane/cli version" | ||
| required: false | ||
| default: "3.3.1" | ||
| cpflow_version: | ||
| description: cpflow gem version | ||
| required: false | ||
| default: "4.2.0" | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Set up Ruby | ||
| uses: ruby/setup-ruby@v1 | ||
| with: | ||
| ruby-version: ${{ inputs.ruby_version }} | ||
|
|
||
| - name: Install Control Plane CLI and cpflow gem | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| sudo npm install -g @controlplane/cli@${{ inputs.cpln_cli_version }} | ||
| cpln --version | ||
|
|
||
| gem install cpflow -v ${{ inputs.cpflow_version }} | ||
| cpflow --version | ||
|
|
||
| - name: Setup Control Plane profile and registry login | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| TOKEN="${{ inputs.token }}" | ||
| ORG="${{ inputs.org }}" | ||
|
|
||
| if [[ -z "$TOKEN" ]]; then | ||
| echo "Error: Control Plane token not provided" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ -z "$ORG" ]]; then | ||
| echo "Error: Control Plane organization not provided" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| create_output="" | ||
| if ! create_output="$(cpln profile create default --token "$TOKEN" --org "$ORG" 2>&1)"; then | ||
| if ! echo "$create_output" | grep -qi "already exists"; then | ||
| echo "$create_output" >&2 | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| cpln profile update default --org "$ORG" --token "$TOKEN" | ||
| cpln image docker-login --org "$ORG" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.