1+ name : GOGO Betting stage CD Workflow
2+
3+ on :
4+ push :
5+ branches :
6+ - ' develop'
7+ workflow_dispatch :
8+
9+ jobs :
10+ CI :
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+ cache : gradle
23+
24+ - name : Setup Gradle
25+ uses : gradle/gradle-build-action@v2
26+
27+ - name : Setup Gradle's permission
28+ run : chmod +x gradlew
29+
30+ - name : Build with Gradle
31+ run : ./gradlew clean build
32+
33+ deploy :
34+ needs : CI
35+ runs-on : ubuntu-latest
36+ steps :
37+ - name : Checkout code
38+ uses : actions/checkout@v3
39+
40+ - name : Install sshpass and OpenSSH
41+ run : |
42+ sudo apt-get update && sudo apt-get install -y sshpass openssh-client
43+
44+ - name : Create SSH key for Bastion and Target
45+ run : |
46+ echo "${{ secrets.STAGE_BASTION_SSH_KEY }}" > $HOME/bastion_key.pem
47+ chmod 600 $HOME/bastion_key.pem
48+
49+ - name : SSH Command to Deploy using Bastion and Target Instance
50+ run : |
51+ ssh -i "$HOME/bastion_key.pem" -o StrictHostKeyChecking=no ubuntu@${{ secrets.STAGE_BASTION_HOST }} << 'EOF'
52+ ssh -i gogo-stage.pem -o StrictHostKeyChecking=no ubuntu@${{ secrets.STAGE_TARGET_HOST }} << 'EOF2'
53+ mkdir -p /home/ubuntu/gogo-betting
54+ cd /home/ubuntu/gogo-betting
55+
56+ if [ ! -d ".git" ]; then
57+ git clone -b develop https://github.com/team-gogo/gogo-betting.git .
58+ else
59+ git pull origin develop
60+ fi
61+
62+ ./gradlew clean build
63+
64+ docker build -f DockerFileStage -t gogo-betting-stage .
65+
66+ docker stop gogo-betting-stage || true
67+ docker rm gogo-betting-stage || true
68+
69+ docker run -d -p 8083:8083 --add-host host.docker.internal:host-gateway --name gogo-betting-stage gogo-betting-stage
70+
71+ - name : SSH Success Notification
72+ if : success()
73+ uses : sarisia/actions-status-discord@v1
74+ with :
75+ webhook : ${{ secrets.DISCORD_WEBHOOK }}
76+ color : 0x4CAF50
77+ title : " 배포 성공"
78+ message : " GOGO User stage deployment completed successfully."
79+
80+ - name : SSH Failure Notification
81+ if : failure()
82+ uses : sarisia/actions-status-discord@v1
83+ with :
84+ webhook : ${{ secrets.DISCORD_WEBHOOK }}
85+ color : 0xFF4C4C
86+ title : " 배포 실패"
87+ message : " GOGO User stage deployment failed. Check the logs for details."
0 commit comments