Skip to content

Commit 2d744a7

Browse files
authored
Merge pull request #9 from GTable/feature/#3-ci-cd-pipeline
chore: CI/CD 스크립트 추가
2 parents 0ce2fd7 + c787006 commit 2d744a7

10 files changed

Lines changed: 217 additions & 79 deletions

File tree

.github/workflows/deploy-admin.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Dev Admin CI/CD
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
paths:
8+
- 'application-admin/**'
9+
- 'common/**'
10+
- 'domain-*/**'
11+
- 'application-config/**'
12+
- 'security-admin/**'
13+
- 'build.gradle'
14+
- 'settings.gradle'
15+
- 'gradle/**'
16+
17+
env:
18+
PROJECT_NAME: NoWait
19+
DIVISION: admin
20+
AWS_REGION: ap-northeast-2
21+
AWS_S3_BUCKET: nowait-deploy-github-actions
22+
AWS_CODE_DEPLOY_APPLICATION: nowaiting
23+
AWS_CODE_DEPLOY_GROUP: nowaiting-deploy-dev-admin
24+
25+
jobs:
26+
build-with-gradle:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v3
31+
32+
- name: JDK 17 설치
33+
uses: actions/setup-java@v3
34+
with:
35+
java-version: '17'
36+
distribution: 'zulu'
37+
38+
- name: gradlew에 실행 권한 부여
39+
run: chmod +x ./gradlew
40+
41+
- name: Set YML
42+
run: |
43+
mkdir -p application-admin/src/main/resources
44+
echo "${{ secrets.APPLICATION_DEV_ADMIN_YML }}" | base64 --decode > application-admin/src/main/resources/application-admin.yml
45+
find src
46+
47+
- name: 프로젝트 빌드
48+
run: ./gradlew clean :application-admin:bootJar -x test
49+
50+
- name: Prepare deployment package
51+
run: |
52+
rm -rf deploy && mkdir deploy
53+
cp application-admin/build/libs/application-admin-*.jar deploy/application-admin.jar
54+
cp scripts/start-admin.sh scripts/stop-admin.sh appspec-admin.yml deploy/appspec.yml
55+
cd deploy
56+
zip -r ../${{ env.PROJECT_NAME }}-${{ env.DIVISION }}-${{ github.sha }}.zip .
57+
cd ..
58+
59+
- name: AWS credential 설정
60+
uses: aws-actions/configure-aws-credentials@v1
61+
with:
62+
aws-region: ${{ env.AWS_REGION }}
63+
aws-access-key-id: ${{ secrets.DEVSERVER_CICD_ACCESS_KEY }}
64+
aws-secret-access-key: ${{ secrets.DEVSERVER_CICD_SECRET_KEY }}
65+
66+
- name: S3에 업로드
67+
run: aws deploy push \
68+
--application-name "${{ env.AWS_CODE_DEPLOY_APPLICATION }}" \
69+
--ignore-hidden-files \
70+
--s3-location "s3://${{ env.AWS_S3_BUCKET }}/${{ env.PROJECT_NAME }}/${{ env.DIVISION }}/${{ github.sha }}.zip" \
71+
--source "${{ env.PROJECT_NAME }}-${{ env.DIVISION }}-${{ github.sha }}.zip"
72+
73+
- name: EC2에 배포
74+
run: |
75+
aws deploy create-deployment \
76+
--application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }} \
77+
--deployment-config-name CodeDeployDefault.AllAtOnce \
78+
--deployment-group-name ${{ env.AWS_CODE_DEPLOY_GROUP }} \
79+
--s3-location bucket=${{ env.AWS_S3_BUCKET }},key=${{ env.PROJECT_NAME }}/${{ env.DIVISION }}/${{ github.sha }}.zip,bundleType=zip
80+
81+
82+

.github/workflows/dev.yml

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

appspec-admin.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: 0.0
2+
os: linux
3+
4+
files:
5+
- source: /
6+
destination: /home/ubuntu/spring-github-action
7+
overwrite: yes
8+
9+
permissions:
10+
- object: /
11+
owner: ubuntu
12+
group: ubuntu
13+
14+
hooks:
15+
AfterInstall:
16+
- location: scripts/stop-admin.sh
17+
timeout: 60
18+
ApplicationStart:
19+
- location: scripts/start-admin.sh
20+
timeout: 60

build.gradle

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ subprojects {
1818
group = rootProject.group
1919
version = rootProject.version
2020

21+
// 실행 모듈만 따로 정의
22+
def applicationModules = ['application-admin', 'application-user']
23+
24+
if (applicationModules.contains(project.name)) {
25+
// 실제 Service 실행 모듈
26+
apply plugin: 'org.springframework.boot'
27+
bootJar { enabled = true }
28+
jar { enabled = false }
29+
} else {
30+
// 라이브러리/설정/도메인 전용 모듈
31+
bootJar { enabled = false }
32+
jar { enabled = true }
33+
}
34+
2135
repositories {
2236
mavenCentral()
2337
}
@@ -43,11 +57,4 @@ subprojects {
4357
test {
4458
useJUnitPlatform()
4559
}
46-
47-
bootJar {
48-
enabled = false
49-
}
50-
jar {
51-
enabled = true
52-
}
5360
}

common/build.gradle

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
bootJar { enabled = false }
2-
jar { enabled = true }
1+
jar {
2+
enabled = true
3+
}
4+
bootJar {
5+
enabled = false
6+
}
7+
38

49
dependencies {
510
}

domain-token/src/test/java/com/nowait/token/DomainTokenApplicationTests.java

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

scripts/start-admin.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
REPOSITORY="/home/ubuntu/spring-github-action"
4+
cd $REPOSITORY
5+
6+
APP_NAME=application-admin
7+
JAR_NAME=$(ls $REPOSITORY/build/libs/ | grep '.jar' | tail -n 1)
8+
JAR_PATH=$REPOSITORY/build/libs/$JAR_NAME
9+
10+
START_LOG="$REPOSITORY/start.log"
11+
ERROR_LOG="$REPOSITORY/error.log"
12+
APP_LOG="$REPOSITORY/application.log"
13+
14+
$ chmod 666 "$START_LOG"
15+
$ chmod 666 "$ERROR_LOG"
16+
$ chmod 666 "$APP_LOG"
17+
18+
SERVICE_PID=$(pgrep -f ${APP_NAME}.*.jar) # 실행중인 Spring 서버의 PID
19+
NOW=$(date +%c)
20+
21+
22+
echo "[$NOW] > $JAR_PATH 실행" >> $START_LOG
23+
nohup java -Xms256m -Xmx512m -XX:+UseG1GC -jar $JAR_PATH --spring.profiles.active=admin > $APP_LOG 2> $ERROR_LOG &
24+
25+
echo "[$NOW] > 서비스 PID: $SERVICE_PID" >> $START_LOG

scripts/start-user.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
REPOSITORY="/home/ubuntu/spring-github-action"
4+
cd $REPOSITORY
5+
6+
APP_NAME=application-admin
7+
JAR_NAME=$(ls $REPOSITORY/build/libs/ | grep '.jar' | tail -n 1)
8+
JAR_PATH=$REPOSITORY/build/libs/$JAR_NAME
9+
10+
START_LOG="$REPOSITORY/start.log"
11+
ERROR_LOG="$REPOSITORY/error.log"
12+
APP_LOG="$REPOSITORY/application.log"
13+
14+
$ chmod 666 $START_LOG
15+
$ chmod 666 ERROR_LOG
16+
$ chmod 666 APP_LOG
17+
18+
SERVICE_PID=$(pgrep -f ${APP_NAME}.*.jar) # 실행중인 Spring 서버의 PID
19+
NOW=$(date +%c)
20+
21+
22+
echo "[$NOW] > $JAR_PATH 실행" >> $START_LOG
23+
nohup java -Xms256m -Xmx512m -XX:+UseG1GC -jar $JAR_PATH --spring.profiles.active=user > $APP_LOG 2> $ERROR_LOG &
24+
25+
echo "[$NOW] > 서비스 PID: $SERVICE_PID" >> $START_LOG

scripts/stop-admin.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
REPOSITORY=/home/ubuntu/spring-github-action
4+
cd $REPOSITORY
5+
6+
APP_NAME=application-admin
7+
JAR_NAME=$(ls $REPOSITORY/build/libs/ | grep '.jar' | tail -n 1)
8+
JAR_PATH=$REPOSITORY/build/libs/$JAR_NAME
9+
STOP_LOG="$REPOSITORY/stop.log"
10+
11+
$ chmod 666 "$STOP_LOG"
12+
13+
CURRENT_PID=$(pgrep -f ${APP_NAME}.*.jar)
14+
15+
if [ -z $CURRENT_PID ]
16+
then
17+
echo "서비스 NouFound" >> $STOP_LOG
18+
else
19+
echo "> kill -15 $CURRENT_PID"
20+
kill -15 $CURRENT_PID
21+
sleep 5
22+
fi

scripts/stop-user.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
REPOSITORY=/home/ubuntu/spring-github-action
4+
cd $REPOSITORY
5+
6+
APP_NAME=application-admin
7+
JAR_NAME=$(ls $REPOSITORY/build/libs/ | grep '.jar' | tail -n 1)
8+
JAR_PATH=$REPOSITORY/build/libs/$JAR_NAME
9+
STOP_LOG="$REPOSITORY/stop.log"
10+
11+
$ chmod 666 STOP_LOG
12+
13+
CURRENT_PID=$(pgrep -f ${APP_NAME}.*.jar)
14+
15+
if [ -z $CURRENT_PID ]
16+
then
17+
echo "서비스 NouFound" >> $STOP_LOG
18+
else
19+
echo "> kill -15 $CURRENT_PID"
20+
kill -15 $CURRENT_PID
21+
sleep 5
22+
fi

0 commit comments

Comments
 (0)