diff --git a/.github/actions/deploy-to-control-plane.yml b/.github/actions/deploy-to-control-plane.yml new file mode 100644 index 000000000..5e61db6b5 --- /dev/null +++ b/.github/actions/deploy-to-control-plane.yml @@ -0,0 +1,65 @@ +# 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: 'react-webpack-rails-tutorial' + +env: + CPLN_ORG: ${{secrets.CPLN_ORG_STAGING}} + CPLN_TOKEN: ${{secrets.CPLN_TOKEN_STAGING}} + +runs: + - name: Check out the repo + uses: actions/checkout@v2 + + - 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 + 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 ${{ inputs.app_name }} --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 ${{ inputs.app_name }} --image latest + + - name: Deploy to Control Plane + run: | + cpl deploy-image -a ${{ inputs.app_name }} --org ${{secrets.CPLN_ORG_STAGING}} diff --git a/.github/workflows/deploy-to-control-plane-staging.yml b/.github/workflows/deploy-to-control-plane-staging.yml index 393c9a5cd..88b42d44a 100644 --- a/.github/workflows/deploy-to-control-plane-staging.yml +++ b/.github/workflows/deploy-to-control-plane-staging.yml @@ -1,6 +1,7 @@ # Control Plane GitHub Action -name: Deploy-To-Control-Plane +name: Deploy-To-Control-Plane-Staging +description: Deploys to staging # Controls when the workflow will run on: @@ -21,51 +22,6 @@ jobs: runs-on: ubuntu-latest steps: - - 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.yml 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