Skip to content

Commit 7952d48

Browse files
authored
merge: pull request #99 from feat/ci-cd/1
feat: CI/CD 추가 작업 #98
2 parents d77a798 + 35c9510 commit 7952d48

File tree

16 files changed

+184
-679
lines changed

16 files changed

+184
-679
lines changed

.github/workflows/cd-develop.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Java CI with Gradle
2+
3+
on:
4+
push:
5+
branches: [ "develop" ]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Set up JDK 17 (JDK 17 설정)
15+
uses: actions/setup-java@v2
16+
with:
17+
distribution: 'temurin'
18+
java-version: '17'
19+
20+
- name: Create application.properties from git secret (application.properties 파일 생성)
21+
run: |
22+
mkdir -p default/src/main/resources
23+
mkdir -p chat/src/main/resources
24+
echo "$APPLICATION_DEFAULT" > default/src/main/resources/application.properties
25+
echo "$APPLICATION_CHAT" > chat/src/main/resources/application.properties
26+
env:
27+
APPLICATION_DEFAULT: ${{ secrets.APPLICATION_DEFAULT }}
28+
APPLICATION_CHAT: ${{ secrets.APPLICATION_CHAT }}
29+
30+
- name: Grant execute permission to Gradle (Gradle 실행 권한 부여)
31+
run: |
32+
chmod +x ./default/gradlew
33+
chmod +x ./chat/gradlew
34+
35+
# - name: Detect Changes (변경된 파일 감지)
36+
# id: changed-files
37+
# run: |
38+
# git fetch origin develop --depth=1
39+
# CHANGED_FILES=$(git diff --name-only origin/develop HEAD)
40+
#
41+
# echo "Changed files: $CHANGED_FILES"
42+
#
43+
# if echo "$CHANGED_FILES" | grep -q '^default/'; then
44+
# echo "DEFAULT_CHANGED=true" >> $GITHUB_ENV
45+
# fi
46+
#
47+
# if echo "$CHANGED_FILES" | grep -q '^chat/'; then
48+
# echo "CHAT_CHANGED=true" >> $GITHUB_ENV
49+
# fi
50+
51+
- name: Build JAR (JAR 빌드)
52+
run: |
53+
./default/gradlew bootJar
54+
./chat/gradlew bootJar
55+
56+
# CR_PAT: Container Registry - Personal Access Token
57+
- name: GitHub Container Registry login (GitHub Container Registry 로그인)
58+
run: |
59+
export CR_PAT=${{ secrets.SOUNDLINK_TOKEN }}
60+
echo $CR_PAT | docker login ghcr.io -u ${{ secrets.GIT_ID }} --password-stdin
61+
62+
- name: Docker build & push (Default)
63+
run: |
64+
TAG=$(git rev-parse --short HEAD)
65+
DOCKER_IMAGE_DEFAULT=ghcr.io/${{ secrets.GIT_ID }}/soundlink_default:$TAG
66+
docker build -t soundlink_default -f ./docker/default.Dockerfile .
67+
docker tag soundlink_default $DOCKER_IMAGE_DEFAULT
68+
docker push $DOCKER_IMAGE_DEFAULT
69+
70+
- name: Docker build & push (Chat)
71+
run: |
72+
TAG=$(git rev-parse --short HEAD)
73+
DOCKER_IMAGE_CHAT=ghcr.io/${{ secrets.GIT_ID }}/soundlink_chat:$TAG
74+
docker build -t soundlink_chat -f ./docker//chat.Dockerfile .
75+
docker tag soundlink_chat $DOCKER_IMAGE_CHAT
76+
docker push $DOCKER_IMAGE_CHAT
77+
78+
- name: Deploy to Linux Server (리눅스 서버 배포)
79+
uses: appleboy/[email protected]
80+
with:
81+
host: ${{ secrets.HOST }}
82+
username: ${{ secrets.USERNAME }}
83+
key: ${{ secrets.PRIVATE_KEY }}
84+
port: ${{ secrets.PORT }}
85+
script: |
86+
cd /home/ubuntu/docker
87+
sudo docker-compose down spring
88+
sudo docker-compose pull spring
89+
sudo docker-compose up -d spring
90+
sudo docker-compose down spring_chat
91+
sudo docker-compose pull spring_chat
92+
sudo docker-compose up -d spring_chat

.github/workflows/test.yml renamed to .github/workflows/ci-test.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ jobs:
3838
chmod +x ./default/gradlew
3939
chmod +x ./chat/gradlew
4040
41-
- name: Run tests (테스트 실행)
41+
- name: Run tests - default server (디폴트 서버 테스트 실행)
4242
run: |
43-
./default/gradlew test
44-
./chat/gradlew test
43+
cd default
44+
./gradlew test
45+
cd ..
46+
47+
- name: Run tests - chat server (채팅 서버 테스트 실행)
48+
run: |
49+
cd chat
50+
./gradlew test

.github/workflows/gradle.yml

Lines changed: 0 additions & 54 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 0 additions & 54 deletions
This file was deleted.

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ out/
3737
.vscode/
3838

3939
### yml & properties ###
40-
*.yml
41-
*.properties
40+
chat/**/*.yml
41+
default/**/*.yml
42+
chat/src/main/resources/application.properties
43+
default/src/main/resources/application.properties
4244

4345
### 폴더 추가
4446
default/src/main/generated
File renamed without changes.
122 Bytes
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

chat/gradlew

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ done
8686
# shellcheck disable=SC2034
8787
APP_BASE_NAME=${0##*/}
8888
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
89-
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
90-
' "$PWD" ) || exit
89+
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
9190

9291
# Use the maximum available, or set MAX_FD != -1 to use that value.
9392
MAX_FD=maximum
@@ -206,7 +205,7 @@ fi
206205
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
207206

208207
# Collect all arguments for the java command:
209-
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
208+
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
210209
# and any embedded shellness will be escaped.
211210
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
212211
# treated as '${Hostname}' itself on the command line.

0 commit comments

Comments
 (0)