File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed
Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Secure Backend CD
2+
3+ on :
4+ push :
5+ branches :
6+ - develop
7+ paths :
8+ - " backend/**"
9+
10+ jobs :
11+ deploy :
12+ runs-on : ubuntu-latest
13+ environment : secretconfig
14+ steps :
15+ - name : Checkout repository
16+ uses : actions/checkout@v4
17+
18+ - name : Set up JDK 21
19+ uses : actions/setup-java@v4
20+ with :
21+ java-version : ' 21'
22+ distribution : ' temurin'
23+
24+ - name : Grant execute permission for gradlew
25+ run : chmod +x ./backend/gradlew
26+
27+ - name : Build backend application
28+ working-directory : ./backend
29+ run : ./gradlew build -x test
30+
31+ - name : Prepare SSH key
32+ run : |
33+ echo "${{ secrets.SSH_PRIVATE_KEY }}" > key.pem
34+ chmod 600 key.pem
35+
36+ - name : Add remote host to known_hosts
37+ run : |
38+ mkdir -p ~/.ssh
39+ ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
40+
41+ - name : Copy JAR to EC2 server
42+ run : |
43+ scp -i key.pem ./backend/build/libs/backend-0.0.1-SNAPSHOT.jar ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:~/capstone-2025-24/backend/build/libs/
44+
45+ - name : Deploy on EC2 via SSH
46+ run : |
47+ ssh -i key.pem ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << 'EOF'
48+ cd ~/capstone-2025-24
49+ git pull
50+ docker-compose down
51+ docker-compose build
52+ docker-compose up -d
53+ EOF
You can’t perform that action at this time.
0 commit comments