Skip to content

Instantly share code, notes, and snippets.

@Oliver-ke
Last active March 8, 2022 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Oliver-ke/855c140b77848bb81055b48c645296e2 to your computer and use it in GitHub Desktop.
Save Oliver-ke/855c140b77848bb81055b48c645296e2 to your computer and use it in GitHub Desktop.
name: Frontend Cloudfront Deployment
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Yarn Install
run: yarn install
- name: Yarn Build
run: yarn build
env:
REACT_APP_API_URL: ${{ secrets.REACT_APP_API_URL }}
- name: Share artifact inside workflow
uses: actions/upload-artifact@v1
with:
name: build-artifact
path: build
deploy:
runs-on: ubuntu-latest
needs: build
steps:
# get build artifact
- name: Get artifact
uses: actions/download-artifact@v1
with:
name: build-artifact
- name: Configure AWS credentials
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: ${{ secrets.AWS_DEFAULT_REGION }}
# Copy build to s3
- name: Deploy to S3
run: |
S3_BUCKET=s3://<s3-bucket-name>
aws s3 sync . $S3_BUCKET --acl private
working-directory: build-artifact
- name: Create Cloudfront Invalidation
run: |
DISTRIBUTION_ID=<distribution-id>
aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths /*
working-directory: build-artifact
@Oliver-ke
Copy link
Author

Get CLI account conical id using aws s3api list-buckets --query Owner.ID --output text

@Oliver-ke
Copy link
Author

secrets to add
AWS_ACCESS_KEY_ID
AWS_DEFAULT_REGION
AWS_SECRET_ACCESS_KEY
REACT_APP_GOOGLE_MAP
REACT_APP_URL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment