|
9 | 9 | FRONTEND_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/mern-chat-app-frontend |
10 | 10 |
|
11 | 11 | jobs: |
12 | | - build-and-deploy: |
| 12 | + build: |
13 | 13 | runs-on: ubuntu-latest |
14 | | - |
15 | 14 | steps: |
16 | 15 | - name: Checkout code |
17 | 16 | uses: actions/checkout@v4 |
18 | | - |
| 17 | + - name: Set up Docker Buildx |
| 18 | + uses: docker/setup-buildx-action@v3 |
19 | 19 | - name: Log in to Docker Hub |
20 | 20 | uses: docker/login-action@v3 |
21 | 21 | with: |
22 | 22 | username: ${{ secrets.DOCKERHUB_USERNAME }} |
23 | 23 | password: ${{ secrets.DOCKERHUB_TOKEN }} |
24 | | - |
25 | | - - name: Build and push backend image |
| 24 | + - name: Build and push backend |
26 | 25 | uses: docker/build-push-action@v5 |
27 | 26 | with: |
28 | 27 | context: ./Back-end |
29 | 28 | push: true |
30 | 29 | tags: ${{ env.BACKEND_IMAGE }}:latest |
31 | | - |
32 | | - - name: Build and push frontend image |
| 30 | + cache-from: type=gha |
| 31 | + cache-to: type=gha,mode=max |
| 32 | + - name: Build and push frontend |
33 | 33 | uses: docker/build-push-action@v5 |
34 | 34 | with: |
35 | 35 | context: ./Front-end |
36 | 36 | push: true |
37 | 37 | tags: ${{ env.FRONTEND_IMAGE }}:latest |
| 38 | + cache-from: type=gha |
| 39 | + cache-to: type=gha,mode=max |
| 40 | + |
| 41 | + deploy-staging: |
| 42 | + needs: build |
| 43 | + runs-on: ubuntu-latest |
| 44 | + environment: staging |
| 45 | + steps: |
| 46 | + - name: Deploy to Staging EC2 |
| 47 | + uses: appleboy/ssh-action@v1 |
| 48 | + with: |
| 49 | + host: ${{ secrets.STG_EC2_HOST }} |
| 50 | + username: ${{ secrets.STG_EC2_USER }} |
| 51 | + key: ${{ secrets.STG_EC2_SSH_KEY }} |
| 52 | + timeout: 60s |
| 53 | + script: | |
| 54 | + cd ~/MERN-CHAT-APP |
| 55 | + docker-compose pull |
| 56 | + sleep 5 |
| 57 | + docker-compose up -d --remove-orphans |
| 58 | + docker image prune -f |
| 59 | + echo "✅ Staging deployed" |
38 | 60 |
|
39 | | - - name: Deploy to EC2 |
| 61 | + deploy-production: |
| 62 | + needs: deploy-staging |
| 63 | + runs-on: ubuntu-latest |
| 64 | + environment: production |
| 65 | + steps: |
| 66 | + - name: Deploy to Production EC2 |
40 | 67 | uses: appleboy/ssh-action@v1 |
41 | 68 | with: |
42 | 69 | host: ${{ secrets.EC2_HOST }} |
|
49 | 76 | sleep 5 |
50 | 77 | docker-compose up -d --remove-orphans |
51 | 78 | docker image prune -f |
| 79 | + echo "✅ Production deployed" |
0 commit comments