Skip to content

Commit ea423aa

Browse files
authored
v1.2.3
v1.2.3
2 parents 6141af3 + 2aefde3 commit ea423aa

File tree

18 files changed

+658
-7
lines changed

18 files changed

+658
-7
lines changed
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
name: yappu-world-oci-dev-cd
2+
3+
on:
4+
push:
5+
branches:
6+
- dev
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up JDK 21
17+
uses: actions/setup-java@v4
18+
with:
19+
java-version: '21'
20+
distribution: 'liberica'
21+
cache: gradle
22+
23+
- name: Setup Gradle
24+
uses: gradle/actions/setup-gradle@v3
25+
26+
- name: Copy Secrets
27+
uses: microsoft/variable-substitution@v1
28+
with:
29+
files:
30+
./src/main/resources/application-dev-oci.yaml
31+
env:
32+
server.port: ${{ secrets.DEV_SERVER_PORT }}
33+
spring.datasource.url: ${{ secrets.DEV_OCI_DB_URL }}
34+
spring.datasource.username: ${{ secrets.DEV_OCI_DB_USERNAME }}
35+
spring.datasource.password: ${{ secrets.DEV_OCI_DB_PASSWORD }}
36+
jwt.secret_key: ${{ secrets.DEV_JWT_SECRET_KEY }}
37+
jwt.access_token_expiration_times: ${{ secrets.DEV_ACCESS_TOKEN_EXPIRATION_TIMES }}
38+
jwt.refresh_token_expiration_times: ${{ secrets.DEV_REFRESH_TOKEN_EXPIRATION_TIMES }}
39+
fcm.private_key_id: ${{secrets.FCM_PRIVATE_KEY_ID}}
40+
fcm.private_key: ${{secrets.FCM_PRIVATE_KEY}}
41+
fcm.client_email: ${{secrets.FCM_CLIENT_EMAIL}}
42+
fcm.client_id: ${{secrets.FCM_CLIENT_ID}}
43+
fcm.client_x509_cert_url: ${{secrets.FCM_X509_CERT_URL}}
44+
discord.webhook: ${{secrets.DISCORD_WEBHOOK_URL_IN_DEV}}
45+
sentry.dsn: ${{secrets.SENTRY_DSN}}
46+
admin.domain: ${{ secrets.DEV_ADMIN_DOMAIN }}
47+
kakao.rest_api_key: ${{ secrets.KAKAO_REST_API_KEY }}
48+
49+
- name: Build with Gradle Wrapper
50+
run: ./gradlew clean build -x test -Dspring.profiles.active=dev-oci
51+
52+
- name: Prepare File for Deployment
53+
run: |
54+
mkdir -p deployment/dev/build/libs
55+
cp ./docker/dockerfile-dev-oci ./docker/docker-compose-dev-oci.yaml deployment/dev/
56+
cp -r ./build/libs/yappu-world-dev-oci.jar deployment/dev/build/libs
57+
58+
# Github Action 실행 서버 IP 추출
59+
- name: Get Github Actions IP
60+
id: ip
61+
uses: candidob/[email protected]
62+
63+
# OCI CLI 설정
64+
- name: Setup OCI CLI
65+
run: |
66+
mkdir -p ~/.oci
67+
echo "${{ secrets.OCI_CLI_KEY_CONTENT }}" > ~/.oci/key.pem
68+
chmod 600 ~/.oci/key.pem
69+
70+
cat > ~/.oci/config << EOF
71+
[DEFAULT]
72+
user=${{ secrets.OCI_CLI_USER }}
73+
fingerprint=${{ secrets.OCI_CLI_FINGERPRINT }}
74+
tenancy=${{ secrets.OCI_CLI_TENANCY }}
75+
region=${{ secrets.OCI_CLI_REGION }}
76+
key_file=~/.oci/key.pem
77+
EOF
78+
79+
chmod 600 ~/.oci/config
80+
81+
# OCI CLI 설치
82+
curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh | bash -s -- --accept-all-defaults
83+
echo "$HOME/bin" >> $GITHUB_PATH
84+
~/bin/oci --version
85+
86+
# NSG에 Github Action 서버를 등록
87+
- name: Add Github Actions IP to OCI NSG
88+
run: |
89+
~/bin/oci network nsg rules add \
90+
--nsg-id ${{ secrets.OCI_DEV_NSG_OCID }} \
91+
--security-rules '[{
92+
"direction": "INGRESS",
93+
"protocol": "6",
94+
"source": "${{ steps.ip.outputs.ipv4 }}/32",
95+
"sourceType": "CIDR_BLOCK",
96+
"tcpOptions": {
97+
"destinationPortRange": {
98+
"min": 22,
99+
"max": 22
100+
}
101+
},
102+
"description": "GitHub Actions temporary access",
103+
"isStateless": false
104+
}]'
105+
106+
- name: Wait for NSG rule to propagate
107+
run: sleep 10
108+
109+
- name: Setup SSH Key
110+
run: |
111+
mkdir -p ~/.ssh
112+
echo "${{ secrets.OCI_DEV_SSH_PRIVATE_KEY }}" > ~/.ssh/oci_dev_key
113+
chmod 600 ~/.ssh/oci_dev_key
114+
115+
- name: Upload files to OCI Instance
116+
uses: appleboy/[email protected]
117+
with:
118+
host: ${{ secrets.OCI_DEV_INSTANCE_IP }}
119+
username: ubuntu
120+
key: ${{ secrets.OCI_DEV_SSH_PRIVATE_KEY }}
121+
source: "deployment/dev/*"
122+
target: "/home/ubuntu"
123+
124+
- name: Deploy using Docker Compose
125+
uses: appleboy/[email protected]
126+
with:
127+
host: ${{ secrets.OCI_DEV_INSTANCE_IP }}
128+
username: ubuntu
129+
key: ${{ secrets.OCI_DEV_SSH_PRIVATE_KEY }}
130+
script: |
131+
cd /home/ubuntu/deployment/dev
132+
docker-compose -f docker-compose-dev-oci.yaml down
133+
docker system prune -f
134+
docker-compose -f docker-compose-dev-oci.yaml build --no-cache
135+
docker-compose -f docker-compose-dev-oci.yaml up -d
136+
137+
- name: Remove Github Actions IP from OCI NSG
138+
if: always()
139+
run: |
140+
# NSG 규칙 ID 찾기
141+
RULE_ID=$(~/bin/oci network nsg rules list \
142+
--nsg-id ${{ secrets.OCI_DEV_NSG_OCID }} \
143+
--all \
144+
--query "data[?source=='${{ steps.ip.outputs.ipv4 }}/32' && direction=='INGRESS'].id | [0]" \
145+
--raw-output)
146+
147+
if [ ! -z "$RULE_ID" ] && [ "$RULE_ID" != "null" ]; then
148+
~/bin/oci network nsg rules remove \
149+
--nsg-id ${{ secrets.OCI_DEV_NSG_OCID }} \
150+
--security-rule-ids "[\"$RULE_ID\"]"
151+
fi
152+
153+
- name: Cleanup
154+
if: always()
155+
run: |
156+
rm -f ~/.oci/key.pem
157+
rm -f ~/.ssh/oci_dev_key
158+
159+
# Discord Notification
160+
- name: CD Success Notification
161+
uses: sarisia/actions-status-discord@v1
162+
if: success()
163+
with:
164+
title: ✅ OCI 개발 환경 배포 성공 ✅
165+
webhook: ${{ secrets.DISCORD_WEBHOOK_URL }}
166+
color: 0x00FF00
167+
username: 페페훅
168+
169+
- name: CD Failure Notification
170+
uses: sarisia/actions-status-discord@v1
171+
if: failure()
172+
with:
173+
title: ❗️OCI 개발 환경 배포 실패 ❗️
174+
webhook: ${{ secrets.DISCORD_WEBHOOK_URL }}
175+
color: 0xFF0000
176+
username: 페페훅
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
name: yappu-world-oci-prod-cd
2+
3+
on:
4+
push:
5+
branches:
6+
- prod
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up JDK 21
17+
uses: actions/setup-java@v4
18+
with:
19+
java-version: '21'
20+
distribution: 'liberica'
21+
cache: gradle
22+
23+
- name: Setup Gradle
24+
uses: gradle/actions/setup-gradle@v3
25+
26+
- name: Copy Secrets
27+
uses: microsoft/variable-substitution@v1
28+
with:
29+
files:
30+
./src/main/resources/application-prod-oci.yaml
31+
env:
32+
spring.datasource.url: ${{ secrets.PROD_OCI_DB_URL }}
33+
spring.datasource.username: ${{ secrets.PROD_OCI_DB_USERNAME }}
34+
spring.datasource.password: ${{ secrets.PROD_OCI_DB_PASSWORD }}
35+
jwt.secret_key: ${{ secrets.PROD_JWT_SECRET_KEY }}
36+
jwt.access_token_expiration_times: ${{ secrets.PROD_ACCESS_TOKEN_EXPIRATION_TIMES }}
37+
jwt.refresh_token_expiration_times: ${{ secrets.PROD_REFRESH_TOKEN_EXPIRATION_TIMES }}
38+
fcm.private_key_id: ${{secrets.FCM_PRIVATE_KEY_ID}}
39+
fcm.private_key: ${{secrets.FCM_PRIVATE_KEY}}
40+
fcm.client_email: ${{secrets.FCM_CLIENT_EMAIL}}
41+
fcm.client_id: ${{secrets.FCM_CLIENT_ID}}
42+
fcm.client_x509_cert_url: ${{secrets.FCM_X509_CERT_URL}}
43+
discord.webhook: ${{secrets.DISCORD_WEBHOOK_URL_IN_PROD}}
44+
sentry.dsn: ${{secrets.SENTRY_DSN}}
45+
admin.domain: ${{ secrets.PROD_ADMIN_DOMAIN }}
46+
kakao.rest_api_key: ${{ secrets.KAKAO_REST_API_KEY }}
47+
48+
- name: Build with Gradle Wrapper
49+
run: ./gradlew clean build -x test -Dspring.profiles.active=prod-oci
50+
51+
- name: Prepare File for Deployment
52+
run: |
53+
mkdir -p deployment/prod/build/libs
54+
cp ./docker/dockerfile-prod-oci ./docker/docker-compose-prod-oci.yaml deployment/prod/
55+
cp -r ./build/libs/yappu-world-prod-oci.jar deployment/prod/build/libs
56+
57+
# Github Action 실행 서버 IP 추출
58+
- name: Get Github Actions IP
59+
id: ip
60+
uses: candidob/[email protected]
61+
62+
# OCI CLI 설정
63+
- name: Setup OCI CLI
64+
run: |
65+
mkdir -p ~/.oci
66+
echo "${{ secrets.OCI_CLI_KEY_CONTENT }}" > ~/.oci/key.pem
67+
chmod 600 ~/.oci/key.pem
68+
69+
cat > ~/.oci/config << EOF
70+
[DEFAULT]
71+
user=${{ secrets.OCI_CLI_USER }}
72+
fingerprint=${{ secrets.OCI_CLI_FINGERPRINT }}
73+
tenancy=${{ secrets.OCI_CLI_TENANCY }}
74+
region=${{ secrets.OCI_CLI_REGION }}
75+
key_file=~/.oci/key.pem
76+
EOF
77+
78+
chmod 600 ~/.oci/config
79+
80+
# OCI CLI 설치
81+
curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh | bash -s -- --accept-all-defaults
82+
echo "$HOME/bin" >> $GITHUB_PATH
83+
~/bin/oci --version
84+
85+
# NSG에 Github Action 서버를 등록
86+
- name: Add Github Actions IP to OCI NSG
87+
run: |
88+
~/bin/oci network nsg rules add \
89+
--nsg-id ${{ secrets.OCI_PROD_NSG_OCID }} \
90+
--security-rules '[{
91+
"direction": "INGRESS",
92+
"protocol": "6",
93+
"source": "${{ steps.ip.outputs.ipv4 }}/32",
94+
"sourceType": "CIDR_BLOCK",
95+
"tcpOptions": {
96+
"destinationPortRange": {
97+
"min": 22,
98+
"max": 22
99+
}
100+
},
101+
"description": "GitHub Actions temporary access",
102+
"isStateless": false
103+
}]'
104+
105+
- name: Wait for NSG rule to propagate
106+
run: sleep 10
107+
108+
- name: Setup SSH Key
109+
run: |
110+
mkdir -p ~/.ssh
111+
echo "${{ secrets.OCI_PROD_SSH_PRIVATE_KEY }}" > ~/.ssh/oci_prod_key
112+
chmod 600 ~/.ssh/oci_prod_key
113+
114+
- name: Upload files to OCI Instance
115+
uses: appleboy/[email protected]
116+
with:
117+
host: ${{ secrets.OCI_PROD_INSTANCE_IP }}
118+
username: ubuntu
119+
key: ${{ secrets.OCI_PROD_SSH_PRIVATE_KEY }}
120+
source: "deployment/prod/*"
121+
target: "/home/ubuntu"
122+
123+
- name: Deploy using Docker Compose
124+
uses: appleboy/[email protected]
125+
with:
126+
host: ${{ secrets.OCI_PROD_INSTANCE_IP }}
127+
username: ubuntu
128+
key: ${{ secrets.OCI_PROD_SSH_PRIVATE_KEY }}
129+
script: |
130+
cd /home/ubuntu/deployment/prod
131+
docker-compose -f docker-compose-prod-oci.yaml down
132+
docker system prune -f
133+
docker-compose -f docker-compose-prod-oci.yaml build --no-cache
134+
docker-compose -f docker-compose-prod-oci.yaml up -d
135+
136+
- name: Remove Github Actions IP from OCI NSG
137+
if: always()
138+
run: |
139+
# NSG 규칙 ID 찾기
140+
RULE_ID=$(~/bin/oci network nsg rules list \
141+
--nsg-id ${{ secrets.OCI_PROD_NSG_OCID }} \
142+
--all \
143+
--query "data[?source=='${{ steps.ip.outputs.ipv4 }}/32' && direction=='INGRESS'].id | [0]" \
144+
--raw-output)
145+
146+
if [ ! -z "$RULE_ID" ] && [ "$RULE_ID" != "null" ]; then
147+
~/bin/oci network nsg rules remove \
148+
--nsg-id ${{ secrets.OCI_PROD_NSG_OCID }} \
149+
--security-rule-ids "[\"$RULE_ID\"]"
150+
fi
151+
152+
- name: Cleanup
153+
if: always()
154+
run: |
155+
rm -f ~/.oci/key.pem
156+
rm -f ~/.ssh/oci_prod_key
157+
158+
# Discord Notification
159+
- name: CD Success Notification
160+
uses: sarisia/actions-status-discord@v1
161+
if: success()
162+
with:
163+
title: ✅ OCI 상용 배포 성공 ✅
164+
webhook: ${{ secrets.DISCORD_WEBHOOK_URL }}
165+
color: 0x00FF00
166+
username: 페페훅
167+
168+
- name: CD Failure Notification
169+
uses: sarisia/actions-status-discord@v1
170+
if: failure()
171+
with:
172+
title: ❗️OCI 상용 배포 실패 ❗️
173+
webhook: ${{ secrets.DISCORD_WEBHOOK_URL }}
174+
color: 0xFF0000
175+
username: 페페훅
176+
177+
update_release:
178+
needs: build
179+
permissions:
180+
contents: write
181+
pull-requests: write
182+
runs-on: ubuntu-latest
183+
steps:
184+
- name: Update Release
185+
uses: release-drafter/release-drafter@v6
186+
with:
187+
config-name: release-drafter-config.yaml
188+
env:
189+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ dependencies {
3131
runtimeOnly("org.springframework.boot:spring-boot-docker-compose")
3232

3333
runtimeOnly("com.mysql:mysql-connector-j")
34+
runtimeOnly("com.oracle.database.jdbc:ojdbc11")
35+
runtimeOnly("com.oracle.database.security:oraclepki:23.5.0.24.07")
3436
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
3537
implementation("com.linecorp.kotlin-jdsl:jpql-dsl:3.5.5")
3638
implementation("com.linecorp.kotlin-jdsl:jpql-render:3.5.5")
@@ -52,6 +54,7 @@ dependencies {
5254

5355
// logging
5456
implementation("io.github.oshai:kotlin-logging-jvm:7.0.0")
57+
implementation("com.github.loki4j:loki-logback-appender:2.0.1")
5558

5659
// swagger
5760
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.7.0")

docker/docker-compose-dev-oci.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
services:
2+
app:
3+
image: yappu-world-dev-oci
4+
container_name: yappu-world-dev-oci
5+
build:
6+
context: .
7+
dockerfile: dockerfile-dev-oci
8+
ports:
9+
- '8080:8080'
10+
volumes:
11+
- /opt/oracle/wallet:/wallet:ro

0 commit comments

Comments
 (0)