1
1
#! /bin/bash
2
2
3
3
# This script handles the deployment to Control Plane and extracts the Rails URL
4
- #
4
+ #
5
5
# Required environment variables:
6
6
# - APP_NAME: Name of the application to deploy
7
7
# - CPLN_ORG: Control Plane organization
11
11
# Must be a positive integer
12
12
#
13
13
# Outputs:
14
- # - ENV APP_URL : URL of the deployed application
14
+ # - rails_url : URL of the deployed Rails application
15
15
16
16
set -e
17
17
18
18
# Validate required environment variables
19
19
: " ${APP_NAME:? APP_NAME environment variable is required} "
20
20
: " ${CPLN_ORG:? CPLN_ORG environment variable is required} "
21
21
22
- auth_check=$( cpln profile get 2>&1 )
23
- echo " $auth_check "
24
-
25
22
# Set and validate deployment timeout
26
23
WAIT_TIMEOUT=${WAIT_TIMEOUT:- 900}
27
24
if ! [[ " ${WAIT_TIMEOUT} " =~ ^[0-9]+$ ]]; then
@@ -34,41 +31,21 @@ trap 'rm -f "$TEMP_OUTPUT"' EXIT
34
31
35
32
# Deploy the application
36
33
echo " 🚀 Deploying to Control Plane (timeout: ${WAIT_TIMEOUT} s)"
37
- if ! timeout " ${WAIT_TIMEOUT} " cpflow deploy-image -a " $APP_NAME " --run-release-phase --org " $CPLN_ORG " --verbose 2>&1 | tee " $TEMP_OUTPUT " ; then
38
- echo " ❌ Deployment failed"
39
- echo " Full output:"
40
- cat " $TEMP_OUTPUT "
41
- exit 1
42
- fi
43
-
44
- echo " 🚀 Rocket launched!"
45
-
46
- # Wait for all workloads to be ready
47
- echo " ⏳ Waiting for all workloads to be ready (timeout: ${WAIT_TIMEOUT} s)"
48
- if ! timeout " ${WAIT_TIMEOUT} " bash -c " cpflow ps:wait -a \" $APP_NAME \" " 2>&1 | tee -a " $TEMP_OUTPUT " ; then
49
- TIMEOUT_EXIT=$?
50
- if [ ${TIMEOUT_EXIT} -eq 124 ]; then
51
- echo " ❌ Timed out waiting for workloads after ${WAIT_TIMEOUT} seconds"
52
- else
53
- echo " ❌ Workloads did not become ready"
54
- fi
55
- echo " Full output:"
56
- cat " $TEMP_OUTPUT "
57
- exit 1
58
- fi
59
-
60
- echo " ⏳ Wait complete!"
61
-
62
- # Extract app URL from deployment output
63
- echo " 🙏 Extracting app URL"
64
- APP_URL=$( grep -oP ' https://[^[:space:]]*\.cpln\.app(?=\s|$)' " $TEMP_OUTPUT " | head -n1)
65
- if [ -z " $APP_URL " ]; then
66
- echo " ❌ Error: Could not find app URL in deployment output"
67
- echo " Full output:"
68
- cat " $TEMP_OUTPUT "
69
- exit 1
34
+ if timeout " $WAIT_TIMEOUT " cpflow deploy-image -a " $APP_NAME " --run-release-phase --org " $CPLN_ORG " --verbose | tee " $TEMP_OUTPUT " ; then
35
+ # Extract Rails URL from deployment output
36
+ RAILS_URL=$( grep -oP ' https://rails-[^[:space:]]*\.cpln\.app(?=\s|$)' " $TEMP_OUTPUT " | head -n1)
37
+ if [ -n " $RAILS_URL " ]; then
38
+ echo " rails_url=$RAILS_URL " >> " $GITHUB_OUTPUT "
39
+ echo " ✅ Deployment successful"
40
+ echo " 🚀 Rails URL: $RAILS_URL "
41
+ else
42
+ echo " ❌ Failed to extract Rails URL from deployment output"
43
+ exit 1
44
+ fi
45
+ elif [ $? -eq 124 ]; then
46
+ echo " ❌ Deployment timed out after $WAIT_TIMEOUT seconds"
47
+ exit 1
48
+ else
49
+ echo " ❌ Deployment to Control Plane failed"
50
+ exit 1
70
51
fi
71
-
72
- echo " ✅ Deployment successful"
73
- echo " 🌐 App URL: $APP_URL "
74
- echo " APP_URL=$APP_URL " >> " $GITHUB_OUTPUT "
0 commit comments