Skip to content
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 59 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
ee08d3a
Pass correct arg
justin808 Jan 23, 2025
c790151
Set args with =
justin808 Jan 23, 2025
8355030
Address deprecation messages
justin808 Jan 23, 2025
f19d79f
Updates to deployment
justin808 Jan 23, 2025
e487791
updates
justin808 Jan 23, 2025
25e9502
Fixed the deployment_id output in the
justin808 Jan 23, 2025
de55983
fixes
justin808 Jan 23, 2025
5240c9b
fixes
justin808 Jan 23, 2025
2a1b9a3
fixes
justin808 Jan 23, 2025
8918cd2
fixes
justin808 Jan 23, 2025
fe262cb
fixes
justin808 Jan 23, 2025
80d841b
fixes
justin808 Jan 23, 2025
084f0d0
fixes
justin808 Jan 23, 2025
cac41c4
Fixed failure to deploy to review app
justin808 Jan 23, 2025
745ca0e
fixes
justin808 Jan 23, 2025
f77a610
fixes
justin808 Jan 23, 2025
87662fa
Updates, fix crash
justin808 Jan 24, 2025
4970fbe
fixes
justin808 Jan 24, 2025
e26cc72
fixes
justin808 Jan 24, 2025
29ade6f
Fixes
justin808 Jan 24, 2025
8db0511
fixes
justin808 Jan 24, 2025
b7a7229
fixes
justin808 Jan 24, 2025
1cff976
fixes
justin808 Jan 24, 2025
6cbdb04
fixes
justin808 Jan 24, 2025
0b15816
fixes
justin808 Jan 24, 2025
ae8a473
fixes
justin808 Jan 24, 2025
e6d5025
fixes
justin808 Jan 24, 2025
444ec85
fixes
justin808 Jan 24, 2025
8041a01
fixes
justin808 Jan 24, 2025
b03b6d7
fixes
justin808 Jan 24, 2025
a12e0d4
fixes
justin808 Jan 24, 2025
98649f2
fixes
justin808 Jan 24, 2025
b2e710a
fixes
justin808 Jan 24, 2025
c54a544
fixes
justin808 Jan 24, 2025
c80ff43
fixes
justin808 Jan 24, 2025
40473cc
fixes
justin808 Jan 25, 2025
038cf8f
fixes
justin808 Jan 25, 2025
c25211f
fixes
justin808 Jan 25, 2025
304e642
fixes
justin808 Jan 25, 2025
4744c76
fixes
justin808 Jan 25, 2025
5c8b3ab
fixes
justin808 Jan 26, 2025
2a51c92
fixes
justin808 Jan 26, 2025
61213b9
fixes
justin808 Jan 26, 2025
e431bdf
fixes
justin808 Jan 26, 2025
895986c
fixes
justin808 Jan 26, 2025
3fe506e
fixes
justin808 Jan 26, 2025
585c02d
fixes
justin808 Jan 26, 2025
c46f595
fixes
justin808 Jan 26, 2025
65c64d1
fixes
justin808 Jan 26, 2025
e96ac82
doc changes
justin808 Jan 26, 2025
2be9c2f
Changes made:
justin808 Jan 26, 2025
5f50639
fixes
justin808 Jan 26, 2025
e0cf883
fixes
justin808 Jan 26, 2025
b27783e
added promotion and other fixes
justin808 Jan 26, 2025
66a4114
fixes
justin808 Jan 26, 2025
3426aca
fix-for-delete
justin808 Jan 26, 2025
92ad3a7
fix-for-delete
justin808 Jan 26, 2025
7d75738
fix-for-delete
justin808 Jan 26, 2025
d5b8b7f
fix-for-delete
justin808 Jan 26, 2025
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
8 changes: 4 additions & 4 deletions .controlplane/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
ARG RUBY_VERSION=3.3.4
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base

# Current commit hash environment variable
ARG GIT_COMMIT
ENV GIT_COMMIT_SHA=${GIT_COMMIT}

# Install packages needed to build gems and node modules
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential curl git libpq-dev libvips node-gyp pkg-config python-is-python3
Expand Down Expand Up @@ -76,7 +80,3 @@ ENTRYPOINT ["./.controlplane/entrypoint.sh"]
# Default args to pass to the entry point that can be overridden
# For Kubernetes and ControlPlane, these are the "workload args"
CMD ["./bin/rails", "server"]

# Current commit hash environment variable
ARG GIT_COMMIT_SHA
ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA}
29 changes: 29 additions & 0 deletions .controlplane/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,32 @@ cpflow build-image -a $APP_NAME --commit ABCD
### `entrypoint.sh`
- waits for Postgres and Redis to be available
- runs `rails db:prepare` to create/seed or migrate the database

## CI Automation, Review Apps and Staging

_Note, some of the URL references are internal for the ShakaCode team._

Review Apps (deployment of apps based on a PR) are done via Github Actions.

The review apps work by creating isolated deployments for each branch through this automated process. When a branch is pushed, the action:

1. Sets up the necessary environment and tools
2. Creates a unique deployment for that branch if it doesn't exist
3. Builds a Docker image tagged with the branch's commit SHA
4. Deploys this image to Control Plane with its own isolated environment

This allows teams to:
- Preview changes in a production-like environment
- Test features independently
- Share working versions with stakeholders
- Validate changes before merging to main branches

The system uses Control Plane's infrastructure to manage these deployments, with each branch getting its own resources as defined in the controlplane.yml configuration.


### Workflow for Developing Github Actions for Review Apps

1. Create a PR with changes to the Github Actions workflow
2. Make edits to file such as `.github/actions/deploy-to-control-plane/action.yml`
3. Run a script like `ga .github && gc -m fixes && gp` to commit and push changes (ga = git add, gc = git commit, gp = git push)
4. Check the Github Actions tab in the PR to see the status of the workflow
6 changes: 6 additions & 0 deletions .controlplane/shakacode-team.md
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)
6 changes: 4 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ dump.rdb
.DS_Store

# Ignore bundle dependencies
vendor/ruby
vendor/bundle

# Ignore GitHub Actions and workflows
.github/

# RVM gemset
.ruby-gemset
Expand All @@ -45,6 +48,5 @@ yarn-debug.log*
###################################################
# Specific to .dockerignore
.git/
.github/
spec/
scripts/
32 changes: 32 additions & 0 deletions .github/actions/build-docker-image/action.yml
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:
Comment on lines +16 to +20
Copy link

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:

      - name: Validate Required Secrets
        run: |
          for secret in "CPLN_TOKEN_STAGING" "CPLN_ORG_STAGING"; do
            if [ -z "${!secret}" ]; then
              echo "❌ Required secret $secret is not set"
              exit 1
            fi
          done

- 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
20 changes: 20 additions & 0 deletions .github/actions/delete-control-plane-app/action.yml
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 }}
100 changes: 63 additions & 37 deletions .github/actions/deploy-to-control-plane/action.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,82 @@
# 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: 600

outputs:
rails_url:
description: 'URL of the deployed Rails application'
value: ${{ steps.deploy.outputs.rails_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}..."

# Deploy the application and capture the Rails URL
if ! DEPLOY_OUTPUT=$(cpflow deploy-image -a "${{ inputs.app_name }}" --run-release-phase --org "${{ inputs.org }}" 2>&1); then
echo "❌ Deployment failed for PR #${PR_NUMBER}"
echo "Error output:"
echo "${DEPLOY_OUTPUT}"
exit 1
fi

# Extract Rails URL from deployment output
RAILS_URL=$(echo "${DEPLOY_OUTPUT}" | grep -oP 'https://rails-[^[:space:]]*\.cpln\.app(?=\s|$)' | head -n1)
if [ -z "${RAILS_URL}" ]; then
echo "❌ Failed to get Rails URL from deployment output"
echo "Deployment output:"
echo "${DEPLOY_OUTPUT}"
exit 1
fi

# Wait for all workloads to be ready
WAIT_TIMEOUT=${WAIT_TIMEOUT:-${{ inputs.wait_timeout }}}
echo "⏳ Waiting for all workloads to be ready (timeout: ${WAIT_TIMEOUT}s)..."
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add timeout validation and remove trailing spaces.

The timeout value should be validated and trailing spaces should be removed.

Apply this diff to add validation and remove trailing spaces:

-WAIT_TIMEOUT=${WAIT_TIMEOUT:-${{ inputs.wait_timeout }}}
-echo "⏳ Waiting for all workloads to be ready (timeout: ${WAIT_TIMEOUT}s)..."
+# Validate timeout value
+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)"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
WAIT_TIMEOUT=${WAIT_TIMEOUT:-${{ inputs.wait_timeout }}}
echo "⏳ Waiting for all workloads to be ready (timeout: ${WAIT_TIMEOUT}s)..."
# Validate timeout value
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
if ! timeout "${WAIT_TIMEOUT}" bash -c "cpflow ps:wait -a \"${{ inputs.app_name }}\"" 2>&1; 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 "Last deployment output:"
echo "${DEPLOY_OUTPUT}"
exit 1
fi

echo "✅ Deployment successful for PR #${PR_NUMBER}"
echo "🌐 Rails URL: ${RAILS_URL}"
echo "rails_url=${RAILS_URL}" >> $GITHUB_OUTPUT
36 changes: 36 additions & 0 deletions .github/actions/deploy-to-control-plane/scripts/delete-app.sh
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"
43 changes: 43 additions & 0 deletions .github/actions/deploy-to-control-plane/scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/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
#
# Outputs:
# - rails_url: URL of the deployed Rails application

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add validation for required environment variables.

The script should validate that required environment variables are set before proceeding.

Add environment variable validation:

 set -e
+
+# Validate required environment variables
+: "${APP_NAME:?APP_NAME environment variable is required}"
+: "${CPLN_ORG:?CPLN_ORG environment variable is required}"

Committable suggestion skipped: line range outside the PR's diff.

set -e

# Validate required environment variables
: "${APP_NAME:?APP_NAME environment variable is required}"
: "${CPLN_ORG:?CPLN_ORG environment variable is required}"

# Set deployment timeout (15 minutes)
TIMEOUT=900

TEMP_OUTPUT=$(mktemp)
trap 'rm -f "$TEMP_OUTPUT"' EXIT

# Deploy the application
echo "🚀 Deploying to Control Plane..."
if timeout "$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 $TIMEOUT seconds"
exit 1
else
echo "❌ Deployment to Control Plane failed"
exit 1
fi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add health check after deployment.

The script should verify that the deployed application is healthy and responding correctly.

Add a health check after successful deployment:

 if [ -n "$RAILS_URL" ]; then
     echo "rails_url=$RAILS_URL" >> "$GITHUB_OUTPUT"
     echo "✅ Deployment successful"
     echo "🚀 Rails URL: $RAILS_URL"
+    # Wait for the application to be ready
+    echo "🏥 Checking application health..."
+    MAX_ATTEMPTS=30
+    ATTEMPT=0
+    while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
+        if curl -s -f -o /dev/null "$RAILS_URL/health"; then
+            echo "✅ Application is healthy"
+            break
+        fi
+        ATTEMPT=$((ATTEMPT + 1))
+        if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then
+            echo "❌ Application failed to become healthy"
+            exit 1
+        fi
+        echo "⏳ Waiting for application to become healthy (attempt $ATTEMPT/$MAX_ATTEMPTS)..."
+        sleep 10
+    done
 else
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if timeout "$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 $TIMEOUT seconds"
exit 1
else
echo "❌ Deployment to Control Plane failed"
exit 1
fi
if timeout "$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"
# Wait for the application to be ready
echo "🏥 Checking application health..."
MAX_ATTEMPTS=30
ATTEMPT=0
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
if curl -s -f -o /dev/null "$RAILS_URL/health"; then
echo "✅ Application is healthy"
break
fi
ATTEMPT=$((ATTEMPT + 1))
if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then
echo "❌ Application failed to become healthy"
exit 1
fi
echo "⏳ Waiting for application to become healthy (attempt $ATTEMPT/$MAX_ATTEMPTS)..."
sleep 10
done
else
echo "❌ Failed to extract Rails URL from deployment output"
exit 1
fi
elif [ $? -eq 124 ]; then
echo "❌ Deployment timed out after $TIMEOUT seconds"
exit 1
else
echo "❌ Deployment to Control Plane failed"
exit 1
fi

34 changes: 34 additions & 0 deletions .github/actions/deploy-to-control-plane/scripts/get-commit-sha.sh
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
23 changes: 19 additions & 4 deletions .github/actions/setup-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,27 @@ runs:
- name: Install Control Plane CLI and cpflow gem
shell: bash
run: |
sudo npm install -g @controlplane/cli@3.1.0
sudo npm install -g @controlplane/cli@3.3.0
cpln --version
gem install cpflow -v 4.0.0
gem install cpflow -v 4.1.0
cpflow --version

- name: cpln profile
- name: Setup Control Plane Profile
shell: bash
run: |
cpln profile update default
if [ -z "$CPLN_TOKEN" ]; then
echo " Error: CPLN_TOKEN environment variable is not set"
exit 1
fi

if [ -z "$CPLN_ORG" ]; then
echo " Error: CPLN_ORG environment variable is not set"
exit 1
fi

echo "Setting up Control Plane profile..."
echo "Organization: $CPLN_ORG"
cpln profile update default --org "$CPLN_ORG" --token "$CPLN_TOKEN"

echo "Setting up Docker login for Control Plane registry..."
cpln image docker-login --org "$CPLN_ORG"
Loading
Loading