Skip to content

Commit

Permalink
chore: setup CICD to deploy to S3 (#85)
Browse files Browse the repository at this point in the history
Signed-off-by: Nam Hoang <[email protected]>
  • Loading branch information
namhoang1604 authored Aug 9, 2023
1 parent 71d85c0 commit 46b7fc2
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/deploy-to-s3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Deploy to S3

on:
push:
branches:
- demo

jobs:
install_and_build:
runs-on: ubuntu-latest

env:
CI: false

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Cache dependencies
id: cache
uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install pnpm
run: npm install -g [email protected]

- name: Install dependencies
run: pnpm install

- name: 'Create env file'
run: |
touch .env
echo REACT_APP_ENCRYPTED_ENDPOINT=${{ vars.REACT_APP_ENCRYPTED_ENDPOINT}} >> .env
echo REACT_APP_QRCODE_VERIFY_ENDPOINT=${{ vars.REACT_APP_QRCODE_VERIFY_ENDPOINT }} >> .env
echo REACT_APP_SCHEMA_URL=${{ vars.REACT_APP_SCHEMA_URL }} >> .env
echo REACT_APP_REMOTE_AGENT_API_KEY=${{ vars.REACT_APP_REMOTE_AGENT_API_KEY }} >> .env
echo REACT_APP_DEFAULT_AGENT_ID=${{ vars.REACT_APP_DEFAULT_AGENT_ID }} >> .env
cat .env
- name: Build
run: pnpm build

deploy_to_s3:
needs: install_and_build
runs-on: ubuntu-latest

permissions:
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install AWS CLI
run: |
sudo apt-get -q install -y python3-pip
pip3 install awscli --upgrade --user
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_ROLE_GITHUB_ACTION_ARN }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Deploy to S3
run: aws s3 sync packages/demo-explorer/build/explorer/ s3://${{ vars.AWS_S3_BUCKET_NAME }} --acl public-read --delete

- name: Invalidate CloudFront
run: |
DISTRIBUTION_ID=${{ vars.AWS_CLOUDFRONT_DISTRIBUTION_ID }}
INVALIDATION_PATH="/*"
# Create a new CloudFront invalidation
aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths $INVALIDATION_PATH

0 comments on commit 46b7fc2

Please sign in to comment.