-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (89 loc) · 2.86 KB
/
Copy pathdeploy.yml
File metadata and controls
99 lines (89 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Build and Deploy
on:
push:
branches: [main]
env:
BACKEND_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/mern-chat-app-backend
FRONTEND_STAGING_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/mern-chat-app-frontend-staging
FRONTEND_PROD_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/mern-chat-app-frontend-prod
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push backend
uses: docker/build-push-action@v6
with:
context: ./Back-end
push: true
tags: ${{ env.BACKEND_IMAGE }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push frontend (staging)
uses: docker/build-push-action@v6
with:
context: ./Front-end
push: true
tags: ${{ env.FRONTEND_STAGING_IMAGE }}:latest
build-args: |
VITE_SERVER=${{ secrets.STG_VITE_SERVER }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push frontend (prod)
uses: docker/build-push-action@v6
with:
context: ./Front-end
push: true
tags: ${{ env.FRONTEND_PROD_IMAGE }}:latest
build-args: |
VITE_SERVER=${{ secrets.PROD_VITE_SERVER }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy-staging:
needs: build
runs-on: ubuntu-latest
environment: staging
steps:
- name: Deploy to Staging EC2
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.STG_EC2_HOST }}
username: ${{ secrets.STG_EC2_USER }}
key: ${{ secrets.STG_EC2_SSH_KEY }}
timeout: 60s
script: |
cd ~/MERN-CHAT-APP
docker compose pull
sleep 5
docker compose down --remove-orphans
docker compose up -d --remove-orphans
docker image prune -f
echo "Staging deployed"
deploy-production:
needs: deploy-staging
runs-on: ubuntu-latest
environment: production
steps:
- name: Deploy to Production EC2
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
timeout: 60s
script: |
cd ~/MERN-CHAT-APP
docker compose pull
sleep 5
docker compose down --remove-orphans
docker compose up -d --remove-orphans
docker image prune -f
echo "Production deployed"