-
Notifications
You must be signed in to change notification settings - Fork 384
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
Improvements to deployments #615
Merged
Merged
Changes from all commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
ee08d3a
Pass correct arg
justin808 c790151
Set args with =
justin808 8355030
Address deprecation messages
justin808 f19d79f
Updates to deployment
justin808 e487791
updates
justin808 25e9502
Fixed the deployment_id output in the
justin808 de55983
fixes
justin808 5240c9b
fixes
justin808 2a1b9a3
fixes
justin808 8918cd2
fixes
justin808 fe262cb
fixes
justin808 80d841b
fixes
justin808 084f0d0
fixes
justin808 cac41c4
Fixed failure to deploy to review app
justin808 745ca0e
fixes
justin808 f77a610
fixes
justin808 87662fa
Updates, fix crash
justin808 4970fbe
fixes
justin808 e26cc72
fixes
justin808 29ade6f
Fixes
justin808 8db0511
fixes
justin808 b7a7229
fixes
justin808 1cff976
fixes
justin808 6cbdb04
fixes
justin808 0b15816
fixes
justin808 ae8a473
fixes
justin808 e6d5025
fixes
justin808 444ec85
fixes
justin808 8041a01
fixes
justin808 b03b6d7
fixes
justin808 a12e0d4
fixes
justin808 98649f2
fixes
justin808 b2e710a
fixes
justin808 c54a544
fixes
justin808 c80ff43
fixes
justin808 40473cc
fixes
justin808 038cf8f
fixes
justin808 c25211f
fixes
justin808 304e642
fixes
justin808 4744c76
fixes
justin808 5c8b3ab
fixes
justin808 2a51c92
fixes
justin808 61213b9
fixes
justin808 e431bdf
fixes
justin808 895986c
fixes
justin808 3fe506e
fixes
justin808 585c02d
fixes
justin808 c46f595
fixes
justin808 65c64d1
fixes
justin808 e96ac82
doc changes
justin808 2be9c2f
Changes made:
justin808 5f50639
fixes
justin808 e0cf883
fixes
justin808 b27783e
added promotion and other fixes
justin808 66a4114
fixes
justin808 3426aca
fix-for-delete
justin808 92ad3a7
fix-for-delete
justin808 7d75738
fix-for-delete
justin808 d5b8b7f
fix-for-delete
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 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
This file contains 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
This file contains 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 @@ | ||
# Internal Notes to the Shakacode Team | ||
|
||
## Links | ||
|
||
- [Control Plane Org for Staging and Review Apps](https://console.cpln.io/console/org/shakacode-open-source-examples-staging/-info) | ||
- [Control Plane Org for Deployed App](https://console.cpln.io/console/org/shakacode-open-source-examples/-info) |
This file contains 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
This file contains 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,32 @@ | ||
name: Build Docker Image | ||
description: 'Builds a Docker image for the application' | ||
|
||
inputs: | ||
app_name: | ||
description: 'Name of the application' | ||
required: true | ||
org: | ||
description: 'Organization name' | ||
required: true | ||
commit: | ||
description: 'Commit SHA to tag the image with' | ||
required: true | ||
PR_NUMBER: | ||
description: 'PR number' | ||
required: true | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Build Docker Image | ||
id: build | ||
shell: bash | ||
run: | | ||
echo "🏗️ Building Docker image for PR #${PR_NUMBER} (commit ${{ inputs.commit }})..." | ||
|
||
if cpflow build-image -a "${{ inputs.app_name }}" --commit="${{ inputs.commit }}" --org="${{ inputs.org }}"; then | ||
echo "✅ Docker image build successful for PR #${PR_NUMBER} (commit ${{ inputs.commit }})" | ||
else | ||
echo "❌ Docker image build failed for PR #${PR_NUMBER} (commit ${{ inputs.commit }})" | ||
exit 1 | ||
fi |
This file contains 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,20 @@ | ||
name: Delete Control Plane App | ||
description: 'Deletes a Control Plane application and all its resources' | ||
|
||
inputs: | ||
app_name: | ||
description: 'Name of the application to delete' | ||
required: true | ||
org: | ||
description: 'Organization name' | ||
required: true | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Delete Application | ||
shell: bash | ||
run: ${{ github.action_path }}/../deploy-to-control-plane/scripts/delete-app.sh | ||
env: | ||
APP_NAME: ${{ inputs.app_name }} | ||
CPLN_ORG: ${{ inputs.org }} |
This file contains 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 |
---|---|---|
@@ -1,56 +1,91 @@ | ||
# Control Plane GitHub Action | ||
|
||
name: Deploy-To-Control-Plane | ||
description: 'Deploys both to staging and to review apps' | ||
name: Deploy to Control Plane | ||
description: 'Deploys an application to Control Plane' | ||
|
||
inputs: | ||
app_name: | ||
description: 'The name of the app to deploy' | ||
description: 'Name of the application' | ||
required: true | ||
default: | ||
org: | ||
description: 'The org of the app to deploy' | ||
description: 'Organization name' | ||
required: true | ||
default: | ||
github_token: | ||
description: 'GitHub token' | ||
required: true | ||
wait_timeout: | ||
description: 'Timeout in seconds for waiting for workloads to be ready' | ||
required: false | ||
default: '900' | ||
|
||
outputs: | ||
review_app_url: | ||
description: 'URL of the deployed application' | ||
value: ${{ steps.deploy.outputs.review_app_url }} | ||
|
||
runs: | ||
using: 'composite' | ||
using: "composite" | ||
steps: | ||
- name: Setup Environment | ||
uses: ./.github/actions/setup-environment | ||
|
||
- name: Set Short SHA | ||
id: vars | ||
- name: Get Commit SHA | ||
id: get_sha | ||
shell: bash | ||
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" | ||
|
||
# Caching step | ||
- uses: actions/cache@v2 | ||
with: | ||
path: /tmp/.docker-cache | ||
key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile', '**/package.json', '**/yarn.lock') }}-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile', '**/package.json', '**/yarn.lock') }} | ||
${{ runner.os }}-docker- | ||
run: ${{ github.action_path }}/scripts/get-commit-sha.sh | ||
env: | ||
GITHUB_TOKEN: ${{ inputs.github_token }} | ||
PR_NUMBER: ${{ env.PR_NUMBER }} | ||
|
||
- name: cpflow setup-app | ||
shell: bash | ||
run: | | ||
if ! cpflow exists -a ${{ inputs.app_name }} ; then | ||
cpflow setup-app -a ${{ inputs.app_name }} | ||
fi | ||
# Provision all infrastructure on Control Plane. | ||
# app react-webpack-rails-tutorial will be created per definition in .controlplane/controlplane.yml | ||
- name: cpflow build-image | ||
shell: bash | ||
run: | | ||
cpln image docker-login | ||
# Use BUILDKIT_PROGRESS=plain to get more verbose logging of the build | ||
# BUILDKIT_PROGRESS=plain cpflow build-image -a ${{ inputs.app_name }} --commit ${{steps.vars.outputs.sha_short}} --org ${{inputs.org}} | ||
cpflow build-image -a ${{ inputs.app_name }} --commit ${{steps.vars.outputs.sha_short}} --org ${{inputs.org}} | ||
# --cache /tmp/.docker-cache | ||
- name: Deploy to Control Plane | ||
id: deploy | ||
shell: bash | ||
run: | | ||
echo "Deploying to Control Plane" | ||
cpflow deploy-image -a ${{ inputs.app_name }} --run-release-phase --org ${{inputs.org}} --verbose | ||
echo "🚀 Deploying app for PR #${PR_NUMBER}..." | ||
|
||
# Create temp file for output | ||
TEMP_OUTPUT=$(mktemp) | ||
trap 'rm -f "${TEMP_OUTPUT}"' EXIT | ||
|
||
# Deploy the application and show output in real-time while capturing it | ||
if ! cpflow deploy-image -a "${{ inputs.app_name }}" --run-release-phase --org "${{ inputs.org }}" 2>&1 | tee "${TEMP_OUTPUT}"; then | ||
echo "❌ Deployment failed for PR #${PR_NUMBER}" | ||
echo "Error output:" | ||
cat "${TEMP_OUTPUT}" | ||
exit 1 | ||
fi | ||
|
||
# Extract app URL from captured output | ||
REVIEW_APP_URL=$(grep -oP 'https://rails-[^[:space:]]*\.cpln\.app(?=\s|$)' "${TEMP_OUTPUT}" | head -n1) | ||
if [ -z "${REVIEW_APP_URL}" ]; then | ||
echo "❌ Failed to get app URL from deployment output" | ||
echo "Deployment output:" | ||
cat "${TEMP_OUTPUT}" | ||
exit 1 | ||
fi | ||
|
||
# Wait for all workloads to be ready | ||
WAIT_TIMEOUT=${WAIT_TIMEOUT:-${{ inputs.wait_timeout }}} | ||
if ! [[ "${WAIT_TIMEOUT}" =~ ^[0-9]+$ ]]; then | ||
echo "❌ Invalid timeout value: ${WAIT_TIMEOUT}" | ||
exit 1 | ||
fi | ||
echo "⏳ Waiting for all workloads to be ready (timeout: ${WAIT_TIMEOUT}s)" | ||
|
||
# Use timeout command with ps:wait and show output in real-time | ||
if ! timeout "${WAIT_TIMEOUT}" bash -c "cpflow ps:wait -a \"${{ inputs.app_name }}\"" 2>&1 | tee -a "${TEMP_OUTPUT}"; then | ||
TIMEOUT_EXIT=$? | ||
if [ ${TIMEOUT_EXIT} -eq 124 ]; then | ||
echo "❌ Timed out waiting for workloads after ${WAIT_TIMEOUT} seconds" | ||
else | ||
echo "❌ Workloads did not become ready for PR #${PR_NUMBER} (exit code: ${TIMEOUT_EXIT})" | ||
fi | ||
echo "Full output:" | ||
cat "${TEMP_OUTPUT}" | ||
exit 1 | ||
fi | ||
|
||
echo "✅ Deployment successful for PR #${PR_NUMBER}" | ||
echo "🌐 App URL: ${REVIEW_APP_URL}" | ||
echo "review_app_url=${REVIEW_APP_URL}" >> $GITHUB_OUTPUT | ||
echo "REVIEW_APP_URL=${REVIEW_APP_URL}" >> $GITHUB_ENV |
36 changes: 36 additions & 0 deletions
36
.github/actions/deploy-to-control-plane/scripts/delete-app.sh
This file contains 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,36 @@ | ||
#!/bin/bash | ||
|
||
# Script to delete a Control Plane application | ||
# Required environment variables: | ||
# - APP_NAME: Name of the application to delete | ||
# - CPLN_ORG: Organization name | ||
|
||
set -e | ||
|
||
# Validate required environment variables | ||
: "${APP_NAME:?APP_NAME environment variable is required}" | ||
: "${CPLN_ORG:?CPLN_ORG environment variable is required}" | ||
|
||
# Safety check: prevent deletion of production or staging apps | ||
if echo "$APP_NAME" | grep -iqE '(production|staging)'; then | ||
echo "❌ ERROR: Cannot delete apps containing 'production' or 'staging' in their name" >&2 | ||
echo "🛑 This is a safety measure to prevent accidental deletion of production or staging environments" >&2 | ||
echo " App name: $APP_NAME" >&2 | ||
exit 1 | ||
fi | ||
|
||
# Check if app exists before attempting to delete | ||
echo "🔍 Checking if application exists: $APP_NAME" | ||
if ! cpflow exists -a "$APP_NAME"; then | ||
echo "⚠️ Application does not exist: $APP_NAME" | ||
exit 0 | ||
fi | ||
|
||
# Delete the application | ||
echo "🗑️ Deleting application: $APP_NAME" | ||
if ! cpflow delete -a "$APP_NAME" --force; then | ||
echo "❌ Failed to delete application: $APP_NAME" >&2 | ||
exit 1 | ||
fi | ||
|
||
echo "✅ Successfully deleted application: $APP_NAME" |
This file contains 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,51 @@ | ||
#!/bin/bash | ||
|
||
# This script handles the deployment to Control Plane and extracts the Rails URL | ||
# | ||
# Required environment variables: | ||
# - APP_NAME: Name of the application to deploy | ||
# - CPLN_ORG: Control Plane organization | ||
# | ||
# Optional environment variables: | ||
# - WAIT_TIMEOUT: Timeout in seconds for deployment (default: 900) | ||
# Must be a positive integer | ||
# | ||
# Outputs: | ||
# - rails_url: URL of the deployed Rails application | ||
|
||
set -e | ||
|
||
# Validate required environment variables | ||
: "${APP_NAME:?APP_NAME environment variable is required}" | ||
: "${CPLN_ORG:?CPLN_ORG environment variable is required}" | ||
|
||
# Set and validate deployment timeout | ||
WAIT_TIMEOUT=${WAIT_TIMEOUT:-900} | ||
if ! [[ "${WAIT_TIMEOUT}" =~ ^[0-9]+$ ]]; then | ||
echo "❌ Invalid timeout value: ${WAIT_TIMEOUT}" | ||
exit 1 | ||
fi | ||
|
||
TEMP_OUTPUT=$(mktemp) | ||
trap 'rm -f "$TEMP_OUTPUT"' EXIT | ||
|
||
# Deploy the application | ||
echo "🚀 Deploying to Control Plane (timeout: ${WAIT_TIMEOUT}s)" | ||
if timeout "$WAIT_TIMEOUT" cpflow deploy-image -a "$APP_NAME" --run-release-phase --org "$CPLN_ORG" --verbose | tee "$TEMP_OUTPUT"; then | ||
# Extract Rails URL from deployment output | ||
RAILS_URL=$(grep -oP 'https://rails-[^[:space:]]*\.cpln\.app(?=\s|$)' "$TEMP_OUTPUT" | head -n1) | ||
if [ -n "$RAILS_URL" ]; then | ||
echo "rails_url=$RAILS_URL" >> "$GITHUB_OUTPUT" | ||
echo "✅ Deployment successful" | ||
echo "🚀 Rails URL: $RAILS_URL" | ||
else | ||
echo "❌ Failed to extract Rails URL from deployment output" | ||
exit 1 | ||
fi | ||
elif [ $? -eq 124 ]; then | ||
echo "❌ Deployment timed out after $WAIT_TIMEOUT seconds" | ||
exit 1 | ||
else | ||
echo "❌ Deployment to Control Plane failed" | ||
exit 1 | ||
fi |
34 changes: 34 additions & 0 deletions
34
.github/actions/deploy-to-control-plane/scripts/get-commit-sha.sh
This file contains 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,34 @@ | ||
#!/bin/bash | ||
|
||
# This script retrieves the commit SHA for deployment | ||
# It handles both PR and direct branch deployments | ||
# | ||
# Required environment variables: | ||
# - PR_NUMBER: Pull request number (optional) | ||
# - GITHUB_TOKEN: GitHub token for API access | ||
# | ||
# Outputs: | ||
# - sha: Full commit SHA | ||
# - sha_short: Short (7 char) commit SHA | ||
|
||
set -e | ||
|
||
if [ -n "${PR_NUMBER}" ]; then | ||
# If PR_NUMBER is set, get the PR's head SHA | ||
if ! PR_SHA=$(gh pr view "${PR_NUMBER}" --json headRefOid --jq '.headRefOid'); then | ||
echo "Failed to get PR head SHA" >&2 | ||
exit 1 | ||
fi | ||
echo "sha=${PR_SHA}" >> "$GITHUB_OUTPUT" | ||
echo "sha_short=${PR_SHA:0:7}" >> "$GITHUB_OUTPUT" | ||
echo "Using PR head commit SHA: ${PR_SHA:0:7}" | ||
else | ||
# For direct branch deployments, use the current commit SHA | ||
if ! CURRENT_SHA=$(git rev-parse HEAD); then | ||
echo "Failed to get current SHA" >&2 | ||
exit 1 | ||
fi | ||
echo "sha=${CURRENT_SHA}" >> "$GITHUB_OUTPUT" | ||
echo "sha_short=${CURRENT_SHA:0:7}" >> "$GITHUB_OUTPUT" | ||
echo "Using branch commit SHA: ${CURRENT_SHA:0:7}" | ||
fi |
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.
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.
🛠️ Refactor suggestion
Add validation for required secrets.
The workflow should validate that required secrets are available before proceeding.
Add this step after the checkout: