-
Notifications
You must be signed in to change notification settings - Fork 373
Modernize Control Plane GitHub flow #725
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| 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") | ||
|
cursor[bot] marked this conversation as resolved.
Outdated
|
||
| 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 }})" | ||
| 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 }} |
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "does not exist vs. real error" disambiguation here relies on A more defensive approach would be to check the exit code meaning explicitly, e.g. by looking at |
||
| 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" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug:
--ssh defaultis added as a single array element instead of two.When
"${docker_build_args[@]}"is expanded, cpflow will receive the argument--ssh defaultas one token rather than--sshanddefaultas two separate flags. Docker's--sshflag expectsid[=socket]as its value in the next argument.