File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Build and Deploy
2+
3+ on :
4+ push :
5+ branches : [main]
6+
7+ env :
8+ BACKEND_IMAGE : ${{ secrets.DOCKERHUB_USERNAME }}/my-app-backend
9+ FRONTEND_IMAGE : ${{ secrets.DOCKERHUB_USERNAME }}/my-app-frontend
10+
11+ jobs :
12+ build-and-deploy :
13+ runs-on : ubuntu-latest
14+
15+ steps :
16+ - name : Checkout code
17+ uses : actions/checkout@v4
18+
19+ - name : Log in to Docker Hub
20+ uses : docker/login-action@v3
21+ with :
22+ username : ${{ secrets.DOCKERHUB_USERNAME }}
23+ password : ${{ secrets.DOCKERHUB_TOKEN }}
24+
25+ - name : Build and push backend image
26+ uses : docker/build-push-action@v5
27+ with :
28+ context : ./Back-end
29+ push : true
30+ tags : ${{ env.BACKEND_IMAGE }}:latest
31+
32+ - name : Build and push frontend image
33+ uses : docker/build-push-action@v5
34+ with :
35+ context : ./Front-end
36+ push : true
37+ tags : ${{ env.FRONTEND_IMAGE }}:latest
38+
39+ - name : Deploy to EC2
40+ uses : appleboy/ssh-action@v1
41+ with :
42+ host : ${{ secrets.EC2_HOST }}
43+ username : ${{ secrets.EC2_USER }}
44+ key : ${{ secrets.EC2_SSH_KEY }}
45+ script : |
46+ cd ~/MERN-CHAT-APP
47+ docker compose pull
48+ docker compose up -d --remove-orphans
49+ docker image prune -f
Original file line number Diff line number Diff line change 1+ version : " 3.9"
12services :
23 backend :
3- build :
4- context : ./Back-end
5- dockerfile : Dockerfile
4+ image : waseemmalik547/mern-chat-app-backend:latest
65 container_name : mern-backend
76 restart : always
8- env_file :
9- - ./Back-end/.env
7+ env_file : ./Back-end/.env
108 ports :
119 - " 3000:3000"
1210 networks :
1311 - mern-network
1412
1513 frontend :
16- build :
17- context : ./Front-end
18- dockerfile : Dockerfile
14+ image : waseemmalik547/mern-chat-app-frontend:latest
1915 container_name : mern-frontend
2016 restart : always
2117 ports :
You can’t perform that action at this time.
0 commit comments