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 : Deploy to EC2
2+
3+ on :
4+ push :
5+ branches :
6+ - deployment
7+
8+ jobs :
9+ deploy :
10+ runs-on : ubuntu-latest
11+
12+ steps :
13+ - name : Checkout code
14+ uses : actions/checkout@v3
15+
16+ - name : Setup SSH key
17+ run : |
18+ mkdir -p ~/.ssh
19+ echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_rsa
20+ chmod 600 ~/.ssh/id_rsa
21+ ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts
22+
23+ - name : Test SSH connection
24+ run : |
25+ ssh -i ~/.ssh/id_rsa ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} "echo 'Connection successful'"
26+
27+ - name : Deploy Backend
28+ run : |
29+ ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} "
30+ cd ~/business-management/backend &&
31+ git fetch origin deployment &&
32+ git reset --hard origin/deployment &&
33+ npm install &&
34+ sudo systemctl restart node-service
35+ "
36+
37+ - name : Deploy Frontend
38+ run : |
39+ ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} "
40+ export NVM_DIR=\"\$HOME/.nvm\" &&
41+ [ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" &&
42+ cd ~/business-management/frontend &&
43+ git fetch origin deployment &&
44+ git reset --hard origin/deployment &&
45+ npm install &&
46+ npm run build &&
47+ sudo rm -rf /var/www/html/* &&
48+ sudo cp -r .next public package.json /var/www/html/ &&
49+ sudo chown -R www-data:www-data /var/www/html
50+ "
You can’t perform that action at this time.
0 commit comments