2023-08-30 16:40:48 +02:00
|
|
|
name: 🚀 Deploy to AWS
|
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- master
|
|
|
|
tags:
|
|
|
|
- '*'
|
|
|
|
paths:
|
|
|
|
- api/**
|
|
|
|
- serverless.yml
|
|
|
|
- package.json
|
2023-08-31 21:33:31 +02:00
|
|
|
- .github/workflows/deploy-aws.yml
|
2023-08-30 16:40:48 +02:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
deploy-api:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Checkout code
|
2024-05-24 05:21:47 +02:00
|
|
|
uses: actions/checkout@v4
|
2023-08-30 16:40:48 +02:00
|
|
|
|
|
|
|
- name: Setup Node.js
|
2024-05-24 05:21:47 +02:00
|
|
|
uses: actions/setup-node@v4
|
2023-08-30 16:40:48 +02:00
|
|
|
with:
|
|
|
|
node-version: 16
|
|
|
|
|
2023-08-31 21:46:01 +02:00
|
|
|
- name: Cache node_modules
|
2024-05-24 05:21:47 +02:00
|
|
|
uses: actions/cache@v4
|
2023-08-31 21:46:01 +02:00
|
|
|
with:
|
|
|
|
path: node_modules
|
|
|
|
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
|
|
|
restore-keys: |
|
|
|
|
${{ runner.os }}-yarn-
|
|
|
|
|
|
|
|
- name: Create GitHub deployment for API
|
2024-05-24 05:21:47 +02:00
|
|
|
uses: chrnorm/deployment-action@releases/v2
|
2023-08-31 21:33:31 +02:00
|
|
|
id: deployment_api
|
|
|
|
with:
|
|
|
|
token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}
|
2023-08-31 21:46:01 +02:00
|
|
|
environment: AWS (Backend API)
|
2023-08-31 21:33:31 +02:00
|
|
|
ref: ${{ github.ref }}
|
|
|
|
|
2023-08-30 16:40:48 +02:00
|
|
|
- name: Install Serverless CLI and dependencies
|
|
|
|
run: |
|
2023-08-30 16:46:34 +02:00
|
|
|
npm i -g serverless
|
2023-08-30 16:40:48 +02:00
|
|
|
yarn
|
2023-08-31 21:33:31 +02:00
|
|
|
|
2023-08-30 16:40:48 +02:00
|
|
|
- name: Deploy to AWS
|
|
|
|
env:
|
|
|
|
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
|
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
2023-09-02 16:39:26 +02:00
|
|
|
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
|
2023-08-30 16:40:48 +02:00
|
|
|
run: serverless deploy
|
2023-08-31 21:33:31 +02:00
|
|
|
|
|
|
|
- name: Update GitHub deployment status (API)
|
|
|
|
if: always()
|
2024-05-24 05:21:47 +02:00
|
|
|
uses: chrnorm/deployment-status@v2
|
2023-08-31 21:33:31 +02:00
|
|
|
with:
|
|
|
|
token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}
|
|
|
|
state: "${{ job.status }}"
|
|
|
|
deployment_id: ${{ steps.deployment_api.outputs.deployment_id }}
|
|
|
|
ref: ${{ github.ref }}
|
2023-08-30 19:01:33 +02:00
|
|
|
|
|
|
|
deploy-frontend:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Checkout code
|
2024-05-24 05:21:47 +02:00
|
|
|
uses: actions/checkout@v4
|
2023-08-30 19:01:33 +02:00
|
|
|
|
|
|
|
- name: Setup Node.js
|
2024-05-24 05:21:47 +02:00
|
|
|
uses: actions/setup-node@v4
|
2023-08-30 19:01:33 +02:00
|
|
|
with:
|
|
|
|
node-version: 16
|
2023-08-31 21:46:01 +02:00
|
|
|
|
|
|
|
- name: Cache node_modules
|
2024-05-24 05:21:47 +02:00
|
|
|
uses: actions/cache@v4
|
2023-08-31 21:46:01 +02:00
|
|
|
with:
|
|
|
|
path: node_modules
|
|
|
|
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
|
|
|
restore-keys: |
|
|
|
|
${{ runner.os }}-yarn-
|
2023-08-30 19:01:33 +02:00
|
|
|
|
2023-08-31 21:46:01 +02:00
|
|
|
- name: Create GitHub deployment for Frontend
|
2024-05-24 05:21:47 +02:00
|
|
|
uses: chrnorm/deployment-action@v2
|
2023-08-31 21:33:31 +02:00
|
|
|
id: deployment_frontend
|
|
|
|
with:
|
|
|
|
token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}
|
2023-08-31 21:46:01 +02:00
|
|
|
environment: AWS (Frontend Web UI)
|
2023-08-31 21:33:31 +02:00
|
|
|
ref: ${{ github.ref }}
|
|
|
|
|
2023-08-30 19:01:33 +02:00
|
|
|
- name: Install dependencies and build
|
|
|
|
run: |
|
|
|
|
yarn install
|
|
|
|
yarn build
|
2023-08-30 21:07:28 +02:00
|
|
|
|
|
|
|
- name: Setup AWS
|
2024-05-24 05:21:47 +02:00
|
|
|
uses: aws-actions/configure-aws-credentials@v4
|
2023-08-30 21:07:28 +02:00
|
|
|
with:
|
|
|
|
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
|
|
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
|
|
|
aws-region: us-east-1
|
2023-08-30 19:01:33 +02:00
|
|
|
|
|
|
|
- name: Upload to S3
|
2023-08-30 21:07:28 +02:00
|
|
|
env:
|
|
|
|
AWS_S3_BUCKET: 'web-check-frontend'
|
|
|
|
run: aws s3 sync ./build/ s3://$AWS_S3_BUCKET/ --delete
|
2023-08-30 19:01:33 +02:00
|
|
|
|
|
|
|
- name: Invalidate CloudFront cache
|
2024-05-24 05:21:47 +02:00
|
|
|
uses: chetan/invalidate-cloudfront-action@v2
|
2023-08-30 19:01:33 +02:00
|
|
|
env:
|
|
|
|
DISTRIBUTION: E30XKAM2TG9FD8
|
|
|
|
PATHS: '/*'
|
|
|
|
AWS_REGION: 'us-east-1'
|
|
|
|
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
|
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
2023-08-31 21:33:31 +02:00
|
|
|
|
|
|
|
- name: Update GitHub deployment status (Frontend)
|
|
|
|
if: always()
|
2024-05-24 05:21:47 +02:00
|
|
|
uses: chrnorm/deployment-status@v2
|
2023-08-31 21:33:31 +02:00
|
|
|
with:
|
|
|
|
token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}
|
|
|
|
state: "${{ job.status }}"
|
|
|
|
deployment_id: ${{ steps.deployment_frontend.outputs.deployment_id }}
|
|
|
|
ref: ${{ github.ref }}
|
2023-08-31 21:46:01 +02:00
|
|
|
|