From 2b5eda670908447f4bb2ac84c1ebdbbaaf8865a5 Mon Sep 17 00:00:00 2001 From: louis-md Date: Tue, 30 Jan 2024 13:01:29 +0100 Subject: [PATCH] Add production deployment scripts --- .../scripts/prepar_production_deployment.sh | 17 ++++++ .github/workflows/deploy-release.yml | 52 +++++++++++++++++++ .github/workflows/deploy.yml | 6 +-- 3 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 .github/scripts/prepar_production_deployment.sh create mode 100644 .github/workflows/deploy-release.yml diff --git a/.github/scripts/prepar_production_deployment.sh b/.github/scripts/prepar_production_deployment.sh new file mode 100644 index 00000000..1d15edc5 --- /dev/null +++ b/.github/scripts/prepar_production_deployment.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -ev + +# Only: +# - Tagged commits +# - Security env variables are available. +if [ -n "$VERSION_TAG" ] && [ -n "$PROD_DEPLOYMENT_HOOK_TOKEN" ] && [ -n "$PROD_DEPLOYMENT_HOOK_URL" ] +then + curl --silent --output /dev/null --write-out "%{http_code}" -X POST \ + -F token="$PROD_DEPLOYMENT_HOOK_TOKEN" \ + -F ref=master \ + -F "variables[TRIGGER_RELEASE_COMMIT_TAG]=$VERSION_TAG" \ + $PROD_DEPLOYMENT_HOOK_URL +else + echo "[ERROR] Production deployment could not be prepared" +fi diff --git a/.github/workflows/deploy-release.yml b/.github/workflows/deploy-release.yml new file mode 100644 index 00000000..a7f99e5c --- /dev/null +++ b/.github/workflows/deploy-release.yml @@ -0,0 +1,52 @@ +name: Release + +on: + release: + types: [published] + +jobs: + deploy: + runs-on: ubuntu-latest + permissions: write-all + + name: Deploy release + + steps: + - name: Cancel previous runs + uses: styfle/cancel-workflow-action@0.8.0 + with: + access_token: ${{ github.token }} + + - uses: actions/checkout@v3 + + - uses: pnpm/action-setup@v2 + with: + version: 8 + + - name: Install dependencies + shell: bash + run: pnpm install --frozen-lockfile + + - name: Build app + shell: bash + run: pnpm build + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v3 + with: + role-to-assume: ${{ secrets.AWS_ROLE }} + aws-region: ${{ secrets.AWS_REGION }} + + # Deploy the main branch to production environment + - name: Deploy to the production S3 + if: github.ref == 'refs/heads/main' + env: + BUCKET: s3://${{ secrets.AWS_STAGING_BUCKET_NAME }}/releases/${{ github.event.release.tag_name }} + run: bash ./.github/scripts/s3_upload.sh + + # Script to prepare production deployments + - run: bash ./.github/scripts/prepare_production_deployment.sh + env: + PROD_DEPLOYMENT_HOOK_TOKEN: ${{ secrets.PROD_DEPLOYMENT_HOOK_TOKEN }} + PROD_DEPLOYMENT_HOOK_URL: ${{ secrets.PROD_DEPLOYMENT_HOOK_URL }} + VERSION_TAG: ${{ github.event.release.tag_name }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3fd6ec0f..bc91f080 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,7 +3,7 @@ name: Deploy to staging on: push: branches: - - nextra + - development jobs: deploy: @@ -38,9 +38,9 @@ jobs: role-to-assume: ${{ secrets.AWS_ROLE }} aws-region: ${{ secrets.AWS_REGION }} - # Deploy the nextra branch to staging + # Deploy the development branch to staging - name: Deploy to the staging S3 - if: github.ref == 'refs/heads/nextra' + if: github.ref == 'refs/heads/development' env: BUCKET: s3://${{ secrets.AWS_STAGING_BUCKET_NAME }}/current run: bash ./.github/scripts/s3_upload.sh