Skip to content

cookie error test3

cookie error test3 #9

Workflow file for this run

name: Build and Deploy to Docker Hub
on:
push:
branches:
- main
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Check Out Repo
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 # Added for better build performance
- name: Log in to Docker Hub
uses: docker/login-action@v3 # Updated to v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and Push Backend Docker image
uses: docker/build-push-action@v5 # Updated to v5
with:
context: .
file: ./Dockerfile.backend
push: true
tags: puneetnj/course-app-be:latest
platforms: linux/amd64,linux/arm64
cache-from: type=registry,ref=puneetnj/course-app-be:latest
cache-to: type=inline
build-args: |
DATABASE_URL=${{ secrets.DATABASE_URL }}
USER_JWT_PASSWORD=${{ secrets.USER_JWT_PASSWORD }}
ADMIN_JWT_PASSWORD=${{ secrets.ADMIN_JWT_PASSWORD }}
AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}
CDN_LINK=${{ secrets.CDN_LINK }}
- name: Build and Push Frontend Docker image
uses: docker/build-push-action@v5 # Updated to v5
with:
context: .
file: ./Dockerfile.frontend
push: true
tags: puneetnj/course-app-fe:latest
platforms: linux/amd64,linux/arm64
cache-from: type=registry,ref=puneetnj/course-app-fe:latest
cache-to: type=inline
- name: Verify Backend Image
run: |
docker pull puneetnj/course-app-be:latest
docker image inspect puneetnj/course-app-be:latest
- name: Verify Frontend Image
run: |
docker pull puneetnj/course-app-fe:latest
docker image inspect puneetnj/course-app-fe:latest
- name: Deploy to EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
sudo docker pull puneetnj/course-app-be:latest
sudo docker stop course-app-be || true
sudo docker rm course-app-be || true
sudo docker run -d --name course-app-be -p 4000:4000 puneetnj/course-app-be:latest
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Pull and Extract Frontend Assets
run: |
docker pull puneetnj/course-app-fe:latest
docker create --name temp_container puneetnj/course-app-fe:latest
docker cp temp_container:/usr/share/nginx/html/. ./dist
docker rm temp_container
- name: Deploy to S3
run: |
aws s3 sync dist s3://${{ secrets.S3_BUCKET }} --delete
aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} --paths "/*"