File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Deploy to EC2
2+
3+ on :
4+ push :
5+ branches :
6+ - ci-cd
7+
8+ jobs :
9+ build-and-deploy :
10+ runs-on : ubuntu-latest
11+
12+ steps :
13+ - name : Checkout source
14+ uses : actions/checkout@v3
15+
16+ - name : Set up JDK 21
17+ uses : actions/setup-java@v3
18+ with :
19+ java-version : ' 21'
20+ distribution : ' temurin'
21+
22+ - name : Grant execute permission to gradlew
23+ run : chmod +x ./gradlew
24+
25+ - name : Build with Gradle (skip test)
26+ run : ./gradlew clean build -x test
27+
28+ - name : Set up SSH key
29+ run : |
30+ mkdir -p ~/.ssh
31+ echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_rsa
32+ chmod 600 ~/.ssh/id_rsa
33+
34+ - name : Add EC2 host to known_hosts
35+ run : ssh-keyscan -p ${{ secrets.EC2_PORT }} ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts
36+
37+ - name : Upload JAR to EC2
38+ run : |
39+ scp -i ~/.ssh/id_rsa -P ${{ secrets.EC2_PORT }} build/libs/noonsongmaker-0.0.1-SNAPSHOT.jar ${{ secrets.EC2_HOST }}:/home/ec2-user/build/libs/
40+
41+ - name : Restart docker-compose on EC2
42+ run : |
43+ ssh -i ~/.ssh/id_rsa -p ${{ secrets.EC2_PORT }} ${{ secrets.EC2_HOST }} << 'EOF'
44+ cd /home/ec2-user
45+ docker-compose down
46+ docker-compose up -d
47+ EOF
You can’t perform that action at this time.
0 commit comments