|
1 | 1 | # Control Plane GitHub Action
|
2 | 2 |
|
3 |
| -name: Deploy-To-Control-Plane |
4 |
| -description: 'Deploys both to staging and to review apps' |
| 3 | +name: Deploy to Control Plane |
| 4 | +description: 'Deploys the application to Control Plane' |
5 | 5 |
|
6 | 6 | inputs:
|
7 | 7 | app_name:
|
8 |
| - description: 'The name of the app to deploy' |
| 8 | + description: 'Name of the application' |
9 | 9 | required: true
|
10 | 10 | org:
|
11 |
| - description: 'The org of the app to deploy' |
| 11 | + description: 'Organization name' |
12 | 12 | required: true
|
13 | 13 | github_token:
|
14 |
| - description: 'The GitHub token for authentication' |
| 14 | + description: 'GitHub token' |
15 | 15 | required: true
|
16 | 16 |
|
17 | 17 | outputs:
|
18 | 18 | rails_url:
|
19 |
| - description: 'The URL of the deployed Rails application' |
| 19 | + description: 'URL of the deployed Rails application' |
20 | 20 | value: ${{ steps.deploy.outputs.rails_url }}
|
21 | 21 |
|
22 | 22 | runs:
|
23 |
| - using: 'composite' |
| 23 | + using: "composite" |
24 | 24 | steps:
|
25 |
| - - name: Setup Environment |
26 |
| - uses: ./.github/actions/setup-environment |
27 |
| - |
28 |
| - - name: Get correct commit SHA |
| 25 | + - name: Get commit SHA |
29 | 26 | id: get_sha
|
30 | 27 | shell: bash
|
31 | 28 | run: |
|
32 |
| - if [[ "$GITHUB_EVENT_NAME" == "issue_comment" ]]; then |
33 |
| - PR_SHA=$(gh pr view ${{ env.PR_NUMBER }} --json headRefOid --jq '.headRefOid') |
34 |
| - echo "sha=$PR_SHA" >> $GITHUB_OUTPUT |
35 |
| - echo "sha_short=${PR_SHA:0:7}" >> $GITHUB_OUTPUT |
36 |
| - else |
37 |
| - echo "sha=$GITHUB_SHA" >> $GITHUB_OUTPUT |
38 |
| - echo "sha_short=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT |
39 |
| - fi |
40 |
| - env: |
41 |
| - GITHUB_TOKEN: ${{ inputs.github_token }} |
42 |
| - PR_NUMBER: ${{ env.PR_NUMBER }} |
43 |
| - |
44 |
| - # Updated caching step to v3 |
45 |
| - - uses: actions/cache@v3 |
46 |
| - with: |
47 |
| - path: /tmp/.docker-cache |
48 |
| - key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile', '**/package.json', '**/yarn.lock') }}-${{ github.sha }} |
49 |
| - restore-keys: | |
50 |
| - ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile', '**/package.json', '**/yarn.lock') }} |
51 |
| - ${{ runner.os }}-docker- |
52 |
| -
|
53 |
| - - name: cpflow setup-app |
54 |
| - shell: bash |
55 |
| - run: | |
56 |
| - if ! cpflow exists -a ${{ inputs.app_name }} ; then |
57 |
| - cpflow setup-app -a ${{ inputs.app_name }} |
58 |
| - fi |
59 |
| -
|
60 |
| - # Provision all infrastructure on Control Plane. |
61 |
| - # app react-webpack-rails-tutorial will be created per definition in .controlplane/controlplane.yml |
62 |
| - - name: Build and deploy |
63 |
| - shell: bash |
64 |
| - run: | |
65 |
| - cpln image docker-login |
66 |
| - # Use BUILDKIT_PROGRESS=plain to get more verbose logging of the build |
67 |
| - # BUILDKIT_PROGRESS=plain cpflow build-image -a ${{ inputs.app_name }} --commit ${{steps.get_sha.outputs.sha_short}} --org ${{inputs.org}} |
68 |
| - cpflow build-image -a ${{ inputs.app_name }} --commit=${{steps.get_sha.outputs.sha_short}} --org=${{inputs.org}} |
| 29 | + echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT |
| 30 | + echo "Using commit SHA: $(git rev-parse --short HEAD)" |
69 | 31 |
|
70 | 32 | - name: Deploy to Control Plane
|
71 | 33 | id: deploy
|
72 | 34 | shell: bash
|
73 | 35 | run: |
|
74 |
| - # Debug git commit information |
75 |
| - echo "🔍 Debugging git commit information:" |
76 |
| - echo "Current directory: $(pwd)" |
77 |
| - echo "Git status:" |
78 |
| - git status |
79 |
| - echo "Git log (last 5 commits):" |
80 |
| - git log -n 5 --oneline |
81 |
| - echo "steps.get_sha.outputs.sha_short: ${{steps.get_sha.outputs.sha_short}}" |
82 |
| - echo "Full SHA from git rev-parse HEAD: $(git rev-parse HEAD)" |
83 |
| - echo "Short SHA from git rev-parse --short HEAD: $(git rev-parse --short HEAD)" |
84 |
| - |
85 |
| - # Deploy rails workload |
86 |
| - echo "🚀 Starting deployment process..." |
87 |
| - echo "📦 Building image with commit SHA: ${{steps.get_sha.outputs.sha_short}}" |
88 |
| - |
89 |
| - # Create a temporary file for the output |
| 36 | + # Create temp file for output |
90 | 37 | TEMP_OUTPUT=$(mktemp)
|
91 | 38 |
|
92 |
| - # Run the command and tee output to both stdout and temp file |
93 |
| - set -o pipefail # Make sure we get the correct exit code from the cpln command |
| 39 | + echo "🚀 Deploying with commit: ${{steps.get_sha.outputs.sha_short}}" |
94 | 40 |
|
95 |
| - echo "🔄 Building and deploying with cpflow..." |
| 41 | + # Build and deploy |
96 | 42 | if cpflow build-image -a ${{ inputs.app_name }} --commit=${{steps.get_sha.outputs.sha_short}} --org=${{inputs.org}} | tee "$TEMP_OUTPUT" && \
|
97 | 43 | cpflow deploy-image -a ${{ inputs.app_name }} --run-release-phase --org ${{inputs.org}} --verbose | tee -a "$TEMP_OUTPUT"; then
|
98 | 44 |
|
99 |
| - # Extract the URL from the deployment output |
100 |
| - RAILS_URL=$(grep -o 'https://rails-[^[:space:]]*\.cpln\.app' "$TEMP_OUTPUT" || true) |
| 45 | + # Extract Rails URL |
| 46 | + RAILS_URL=$(grep -o 'https://rails-[^[:space:]]*\.cpln\.app' "$TEMP_OUTPUT") |
101 | 47 | if [ -n "$RAILS_URL" ]; then
|
102 |
| - echo "🌐 Found Rails deployment URL: $RAILS_URL" |
103 | 48 | echo "rails_url=$RAILS_URL" >> $GITHUB_OUTPUT
|
104 |
| - rm "$TEMP_OUTPUT" |
| 49 | + echo "✅ Deployment successful: $RAILS_URL" |
105 | 50 | else
|
106 |
| - rm "$TEMP_OUTPUT" |
107 |
| - echo "❌ Failed to extract Rails URL from deployment output" |
| 51 | + echo "❌ Failed to extract Rails URL" |
108 | 52 | exit 1
|
109 | 53 | fi
|
110 | 54 | else
|
111 |
| - rm "$TEMP_OUTPUT" |
112 |
| - echo "❌ Deployment command failed" |
| 55 | + echo "❌ Deployment failed" |
113 | 56 | exit 1
|
114 | 57 | fi
|
| 58 | + rm -f "$TEMP_OUTPUT" |
0 commit comments