UPDATED #71
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# name: Deploy Frontend to S3 | |
# on: | |
# push: | |
# branches: | |
# - main | |
# - frontend # Adjust this if you want to deploy from a different branch. | |
# jobs: | |
# build-and-deploy: | |
# runs-on: ubuntu-latest | |
# steps: | |
# - name: Checkout code | |
# uses: actions/checkout@v3 | |
# - name: Set up Docker Buildx | |
# uses: docker/setup-buildx-action@v2 | |
# - name: Build Docker image | |
# run: | | |
# docker build -t frontend-build -f frontend/Dockerfile ./frontend | |
# - name: Extract built files | |
# run: | | |
# mkdir -p frontend-build | |
# docker run --rm -v $(pwd)/frontend-build:/output frontend-build cp -r /usr/share/nginx/html/* /output | |
# - name: Configure AWS CLI | |
# 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: ap-south-1 # e.g., us-east-1 | |
# - name: Upload to S3 | |
# run: | | |
# aws s3 sync frontend-build s3://electramart-bucket --delete | |
# env: | |
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
# AWS_REGION: ap-south-1 # e.g., us-east-1 | |
name: Deploy Frontend to S3 | |
on: | |
push: | |
branches: | |
- main | |
- frontend # Adjust this if you want to deploy from a different branch. | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '20.11.1' # Use the Node.js version your project requires | |
- name: Install dependencies | |
run: npm install | |
working-directory: ./frontend # Point to your frontend directory | |
- name: Build the project | |
run: npm run build | |
working-directory: ./frontend # Point to your frontend directory | |
- name: Configure AWS CLI | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ap-south-1 # Specify your AWS region | |
- name: Upload to S3 | |
run: | | |
# aws s3 sync ./frontend/dist s3://electramart-bucket --delete | |
aws s3 sync ./frontend/dist s3://electramart-bucket --delete --cache-control "max-age=0,no-cache,no-store,must-revalidate" | |
- name: Invalidate CloudFront Cache | |
run: | | |
aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} --paths "/*" | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: ap-south-1 # Specify your AWS region | |