From 8688fd23f5d15f6fcaa7009cf01a5908f810c27c Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Wed, 30 Aug 2023 20:07:28 +0100 Subject: [PATCH 1/3] Use native AWS CLI to upload to S3 --- .github/workflows/deploy-aws.yml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deploy-aws.yml b/.github/workflows/deploy-aws.yml index f7e24ad..abad002 100644 --- a/.github/workflows/deploy-aws.yml +++ b/.github/workflows/deploy-aws.yml @@ -52,15 +52,18 @@ jobs: run: | yarn install yarn build + + - name: Setup AWS + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 - name: Upload to S3 - uses: shallwefootball/s3-upload-action@v1.3.3 - id: S3 - with: - aws_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}} - aws_bucket: 'web-check-frontend' - source_dir: './' + env: + AWS_S3_BUCKET: 'web-check-frontend' + run: aws s3 sync ./build/ s3://$AWS_S3_BUCKET/ --delete - name: Invalidate CloudFront cache uses: chetan/invalidate-cloudfront-action@v2.4 From 33e1adb974989af6450f9b2c352e46093dc278de Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Thu, 31 Aug 2023 20:33:31 +0100 Subject: [PATCH 2/3] Update AWS workflow to update the deployment state for environments --- .github/workflows/deploy-aws.yml | 38 +++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-aws.yml b/.github/workflows/deploy-aws.yml index abad002..bbaa8ed 100644 --- a/.github/workflows/deploy-aws.yml +++ b/.github/workflows/deploy-aws.yml @@ -11,6 +11,7 @@ on: - api/** - serverless.yml - package.json + - .github/workflows/deploy-aws.yml jobs: deploy-api: @@ -25,16 +26,33 @@ jobs: with: node-version: 16 + - uses: chrnorm/deployment-action@releases/v1 + name: Create GitHub deployment for API + id: deployment_api + with: + token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} + environment: api + ref: ${{ github.ref }} + - name: Install Serverless CLI and dependencies run: | npm i -g serverless yarn + - name: Deploy to AWS env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} run: serverless deploy - + + - name: Update GitHub deployment status (API) + if: always() + uses: chrnorm/deployment-status@releases/v1 + with: + token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} + state: "${{ job.status }}" + deployment_id: ${{ steps.deployment_api.outputs.deployment_id }} + ref: ${{ github.ref }} deploy-frontend: runs-on: ubuntu-latest @@ -48,6 +66,14 @@ jobs: with: node-version: 16 + - uses: chrnorm/deployment-action@releases/v1 + name: Create GitHub deployment for Frontend + id: deployment_frontend + with: + token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} + environment: frontend + ref: ${{ github.ref }} + - name: Install dependencies and build run: | yarn install @@ -73,3 +99,13 @@ jobs: AWS_REGION: 'us-east-1' AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + + - name: Update GitHub deployment status (Frontend) + if: always() + uses: chrnorm/deployment-status@releases/v1 + with: + token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} + state: "${{ job.status }}" + deployment_id: ${{ steps.deployment_frontend.outputs.deployment_id }} + ref: ${{ github.ref }} + From b314168da13712a9b33d80d275e068d0030f20c7 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Thu, 31 Aug 2023 20:46:01 +0100 Subject: [PATCH 3/3] Add caching for node_modules and rename environment deploy status --- .github/workflows/deploy-aws.yml | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deploy-aws.yml b/.github/workflows/deploy-aws.yml index bbaa8ed..977720b 100644 --- a/.github/workflows/deploy-aws.yml +++ b/.github/workflows/deploy-aws.yml @@ -26,12 +26,20 @@ jobs: with: node-version: 16 - - uses: chrnorm/deployment-action@releases/v1 - name: Create GitHub deployment for API + - name: Cache node_modules + uses: actions/cache@v2 + with: + path: node_modules + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Create GitHub deployment for API + uses: chrnorm/deployment-action@releases/v1 id: deployment_api with: token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} - environment: api + environment: AWS (Backend API) ref: ${{ github.ref }} - name: Install Serverless CLI and dependencies @@ -65,13 +73,21 @@ jobs: uses: actions/setup-node@v1 with: node-version: 16 + + - name: Cache node_modules + uses: actions/cache@v2 + with: + path: node_modules + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- - - uses: chrnorm/deployment-action@releases/v1 - name: Create GitHub deployment for Frontend + - name: Create GitHub deployment for Frontend + uses: chrnorm/deployment-action@releases/v1 id: deployment_frontend with: token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} - environment: frontend + environment: AWS (Frontend Web UI) ref: ${{ github.ref }} - name: Install dependencies and build @@ -108,4 +124,4 @@ jobs: state: "${{ job.status }}" deployment_id: ${{ steps.deployment_frontend.outputs.deployment_id }} ref: ${{ github.ref }} - +