Skip to content

Commit 1d77dd9

Browse files
authored
Merge pull request #18 from team-gogo/feature/deploy-prod-script
[global] 상용 환경 ci/cd 구성
2 parents b6879e5 + 3e14eed commit 1d77dd9

File tree

4 files changed

+157
-1
lines changed

4 files changed

+157
-1
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: GOGO Betting prod CD Workflow
2+
3+
on:
4+
push:
5+
branches:
6+
- 'master'
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.PROD_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.PROD_BASTION_HOST }} << 'EOF'
52+
ssh -i gogo-prod-ms.pem -o StrictHostKeyChecking=no ubuntu@${{ secrets.PROD_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 master https://github.com/team-gogo/gogo-betting.git .
58+
else
59+
git pull origin master
60+
fi
61+
62+
./gradlew clean build
63+
64+
docker build -f DockerFileProd -t gogo-betting-prod .
65+
66+
docker stop gogo-betting-prod || true
67+
docker rm gogo-betting-prod || true
68+
69+
docker run -d -p 8083:8083 --add-host host.docker.internal:host-gateway --name gogo-betting-prod gogo-betting-prod
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 Betting prod 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 Betting prod deployment failed. Check the logs for details."
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: GOGO Betting prod CI Workflow
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- 'master'
7+
push:
8+
branches:
9+
- 'master'
10+
workflow_dispatch:
11+
12+
jobs:
13+
CI:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v3
19+
20+
- name: Set up JDK 17
21+
uses: actions/setup-java@v3
22+
with:
23+
java-version: '17'
24+
distribution: 'temurin'
25+
cache: gradle
26+
27+
- name: Setup Gradle
28+
uses: gradle/gradle-build-action@v2
29+
30+
- name: Setup Gradle's permission
31+
run: chmod +x gradlew
32+
33+
- name: Build with Gradle
34+
run: ./gradlew clean build
35+
36+
- name: CI Success Notification
37+
uses: sarisia/actions-status-discord@v1
38+
if: success()
39+
with:
40+
webhook: ${{ secrets.DISCORD_WEBHOOK }}
41+
color: 0x4CAF50
42+
43+
- name: CI Failure Notification
44+
uses: sarisia/actions-status-discord@v1
45+
if: failure()
46+
with:
47+
webhook: ${{ secrets.DISCORD_WEBHOOK }}
48+
color: 0xFF4C4C

DockerFileProd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM openjdk:17-jdk
2+
3+
EXPOSE 8083
4+
5+
WORKDIR /home/ubuntu/gogo-betting
6+
7+
COPY build/libs/gogo-betting-0.0.1-SNAPSHOT.jar prod-betting.jar
8+
9+
RUN ln -snf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
10+
11+
ENTRYPOINT ["java", "-jar", "prod-betting.jar", "--spring.profiles.active=prod"]

src/main/resources/application.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,14 @@ spring:
1616
config:
1717
activate:
1818
on-profile: stage
19-
import: "optional:configserver:http://172.17.0.3:8888/"
19+
import: "optional:configserver:http://host.docker.internal:8888/"
20+
21+
---
22+
23+
spring:
24+
application:
25+
name: betting-service
26+
config:
27+
activate:
28+
on-profile: prod
29+
import: "optional:configserver:http://10.0.143.204:8888/"

0 commit comments

Comments
 (0)