Skip to content

Commit

Permalink
Get Review Apps working (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
justin808 authored Jan 16, 2024
1 parent 3690cc6 commit 5979804
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 45 deletions.
70 changes: 70 additions & 0 deletions .github/actions/deploy-to-control-plane/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Control Plane GitHub Action

name: Deploy-To-Control-Plane
description: 'Deploys both to staging and to review apps'

inputs:
# The name of the app to deploy
app_name:
description: 'The name of the app to deploy'
required: true
default:
org:
description: 'The org of the app to deploy'
required: true
default:

runs:
using: 'composite'
steps:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2' # Specify your Ruby version here

- name: Install Control Plane CLI
shell: bash
run: |
sudo npm install -g @controlplane/cli
cpln --version
gem install cpl -v 1.2.0
- name: Set Short SHA
id: vars
shell: bash
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"

- name: cpl profile
shell: bash
run: |
cpln profile update default
# cpln profile update default --token ${CPLN_TOKEN}

# 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-
- name: cpl build-image
shell: bash
run: |
cpln image docker-login
cpl build-image -a ${{ inputs.app_name }} --commit ${{steps.vars.outputs.sha_short}} --org ${{inputs.org}}
# --cache /tmp/.docker-cache
- name: Run release script
shell: bash
run: |
# Run database migrations (or other release tasks) with the latest image,
# while the app is still running on the previous image.
# This is analogous to the release phase.
cpl run:detached './.controlplane/release_script.sh' -a ${{ inputs.app_name }} --image latest
- name: Deploy to Control Plane
shell: bash
run: |
cpl deploy-image -a ${{ inputs.app_name }} --org ${{inputs.org}}
26 changes: 26 additions & 0 deletions .github/workflows/deploy-to-control-plane-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Control Plane GitHub Action

name: Deploy-To-Control-Plane-Staging

# Controls when the workflow will run
on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Convert the GitHub secret variables to environment variables for use by the Control Plane CLI
env:
CPLN_ORG: ${{secrets.CPLN_ORG_STAGING}}
CPLN_TOKEN: ${{secrets.CPLN_TOKEN_STAGING}}

jobs:
deploy-to-control-plane-staging:
runs-on: ubuntu-latest

steps:
- name: Check out the repo
uses: actions/checkout@v2

- uses: ./.github/actions/deploy-to-control-plane
with:
app_name: qa-react-webpack-rails-tutorial-pr-${{ github.event.pull_request.number }}
org: ${{ secrets.CPLN_ORG_STAGING }}
49 changes: 4 additions & 45 deletions .github/workflows/deploy-to-control-plane-staging.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Control Plane GitHub Action

name: Deploy-To-Control-Plane
name: Deploy-To-Control-Plane-Staging

# Controls when the workflow will run
on:
Expand All @@ -24,48 +24,7 @@ jobs:
- name: Check out the repo
uses: actions/checkout@v2

- name: Set up Ruby
uses: ruby/setup-ruby@v1
- uses: ./.github/actions/deploy-to-control-plane
with:
ruby-version: '3.2' # Specify your Ruby version here

- name: Install Control Plane CLI
shell: bash
run: |
sudo npm install -g @controlplane/cli
cpln --version
gem install cpl -v 1.2.0
- name: Set Short SHA
id: vars
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"

- name: cpl profile
run: |
cpln profile update default
# cpln profile update default --token ${CPLN_TOKEN}

# 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-
- name: cpl build-image
run: |
cpln image docker-login
cpl build-image -a ${{ secrets.APP_NAME_STAGING }} --commit ${{steps.vars.outputs.sha_short}} --org ${{secrets.CPLN_ORG_STAGING}}
- name: Run release script
run: |
# Run database migrations (or other release tasks) with the latest image,
# while the app is still running on the previous image.
# This is analogous to the release phase.
cpl run:detached './.controlplane/release_script.sh' -a ${{ secrets.APP_NAME_STAGING }} --image latest
- name: Deploy to Control Plane
run: |
cpl deploy-image -a ${{ secrets.APP_NAME_STAGING }} --org ${{secrets.CPLN_ORG_STAGING}}
app_name: ${{ secrets.APP_NAME_STAGING }}
org: ${{ secrets.CPLN_ORG_STAGING }}

0 comments on commit 5979804

Please sign in to comment.