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 Backend to EC2
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+ workflow_dispatch :
8+
9+ jobs :
10+ build-and-deploy :
11+ runs-on : ubuntu-latest
12+
13+ steps :
14+ - name : Checkout code
15+ uses : actions/checkout@v3
16+
17+ - name : Set up JDK 17
18+ uses : actions/setup-java@v3
19+ with :
20+ java-version : ' 17'
21+ distribution : ' temurin'
22+
23+ - name : Grant execute permission for gradlew
24+ run : chmod +x gradlew
25+
26+ - name : Build with Gradle
27+ run : ./gradlew clean build -x test
28+
29+ - name : Create SSH key file
30+ run : |
31+ echo "${{ secrets.EC2_SSH_KEY }}" > private_key.pem
32+ chmod 600 private_key.pem
33+
34+ - name : Deploy to EC2
35+ run : |
36+ scp -i private_key.pem -o StrictHostKeyChecking=no \
37+ build/libs/*.jar ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/home/ubuntu/app.jar
38+
39+ ssh -i private_key.pem -o StrictHostKeyChecking=no \
40+ ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
41+ sudo systemctl restart studylink
42+ sudo systemctl status studylink
43+ EOF
44+
45+ - name : Clean up
46+ if : always()
47+ run : rm -f private_key.pem
48+
49+ - name : Send deployment notification
50+ if : success()
51+ run : echo "Deployment successful!"
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments