From a4037da6aee192d9e12d2caaa53e61e127340ea5 Mon Sep 17 00:00:00 2001 From: Puneet NJ Date: Sun, 5 Jan 2025 06:50:42 +0530 Subject: [PATCH] deploy workflow updated to have deploy to ec2 and s3 jobs --- .github/workflows/deploy.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9b8fd7d..c584efe 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -59,3 +59,34 @@ jobs: 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 "/*"