-
Notifications
You must be signed in to change notification settings - Fork 373
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·64 lines (55 loc) · 1.93 KB
/
deploy.sh
File metadata and controls
executable file
·64 lines (55 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/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:
# - ENV APP_URL: URL of the deployed 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 2>&1 | tee "$TEMP_OUTPUT"; then
echo "❌ Deployment failed"
echo "Full output:"
cat "$TEMP_OUTPUT"
exit 1
fi
# Extract app URL from deployment output
APP_URL=$(grep -oP 'https://[^[:space:]]*\.cpln\.app(?=\s|$)' "$TEMP_OUTPUT" | head -n1)
if [ -z "$APP_URL" ]; then
echo "❌ Error: Could not find app URL in deployment output"
exit 1
fi
# Wait for all workloads to be ready
echo "⏳ Waiting for all workloads to be ready (timeout: ${WAIT_TIMEOUT}s)"
if ! timeout "${WAIT_TIMEOUT}" bash -c "cpflow ps:wait -a \"$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"
fi
echo "Full output:"
cat "$TEMP_OUTPUT"
exit 1
fi
echo "✅ Deployment successful"
echo "🌐 App URL: $APP_URL"
echo "APP_URL=$APP_URL" >> "$GITHUB_OUTPUT"