Skip to content

Commit 2f83936

Browse files
committed
2 parents a796c8b + 1feacfa commit 2f83936

File tree

5 files changed

+95
-1
lines changed

5 files changed

+95
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: CICD Test for Reminixcence
2+
run-name: Running
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- 'releases/**'
8+
9+
env:
10+
AWS_REGION: ap-southeast-2
11+
AWS_S3_BUCKET: app-release-files
12+
AWS_CODE_DEPLOY_APPLICATION: Zero100_CICD
13+
AWS_CODE_DEPLOY_GROUP: zero100_CICD_Group
14+
15+
jobs:
16+
build-with-gradle:
17+
runs-on: ubuntu-22.04
18+
steps:
19+
- name: main ๋ธŒ๋žœ์น˜๋กœ ์ด๋™
20+
uses: actions/checkout@v3
21+
with:
22+
ref: main
23+
- name: JDK 11 ์„ค์น˜
24+
uses: actions/setup-java@v3
25+
with:
26+
java-version: '11'
27+
distribution: 'corretto'
28+
- name: gradlew์— ์‹คํ–‰ ๊ถŒํ•œ ๋ถ€์—ฌ
29+
run: chmod +x ./gradlew
30+
- name: ํ”„๋กœ์ ํŠธ ๋นŒ๋“œ
31+
run: ./gradlew clean build -x test
32+
- name: AWS credential ์„ค์ •
33+
uses: aws-actions/configure-aws-credentials@v1
34+
with:
35+
aws-region: ${{ env.AWS_REGION }}
36+
aws-access-key-id: ${{ secrets.CICD_ACCESS_KEY }}
37+
aws-secret-access-key: ${{ secrets.CICD_SECRET_KEY }}
38+
- name: S3์— ์—…๋กœ๋“œ
39+
run: aws deploy push --application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }} --ignore-hidden-files --s3-location s3://$AWS_S3_BUCKET/cicdtest/$GITHUB_SHA.zip --source .
40+
- name: EC2์— ๋ฐฐํฌ
41+
run: aws deploy create-deployment --application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }} --deployment-config-name CodeDeployDefault.AllAtOnce --deployment-group-name ${{ env.AWS_CODE_DEPLOY_GROUP }} --s3-location bucket=$AWS_S3_BUCKET,key=cicdtest/$GITHUB_SHA.zip,bundleType=zip

โ€Žappspec.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/Reminiscence-BE
7+
overwrite: yes
8+
9+
permissions:
10+
- object: /
11+
owner: ubuntu
12+
group: ubuntu
13+
14+
hooks:
15+
AfterInstall:
16+
- location: scripts/stop.sh
17+
timeout: 60
18+
ApplicationStart:
19+
- location: scripts/start.sh
20+
timeout: 60

โ€Žscripts/start.shโ€Ž

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
ROOT_PATH="/home/ubuntu/Reminiscence-BE"
4+
JAR="$ROOT_PATH/application.jar"
5+
6+
APP_LOG="$ROOT_PATH/application.log"
7+
ERROR_LOG="$ROOT_PATH/error.log"
8+
START_LOG="$ROOT_PATH/start.log"
9+
10+
NOW=$(date +%c)
11+
12+
echo "[$NOW] $JAR ๋ณต์‚ฌ" >> $START_LOG
13+
cp $ROOT_PATH/build/libs/reminiscence-1.0.0.jar $JAR
14+
15+
echo "[$NOW] > $JAR ์‹คํ–‰" >> $START_LOG
16+
nohup java -jar $JAR > $APP_LOG 2> $ERROR_LOG &
17+
18+
SERVICE_PID=$(pgrep -f $JAR)
19+
echo "[$NOW] > ์„œ๋น„์Šค PID: $SERVICE_PID" >> $START_LOG

โ€Žscripts/stop.shโ€Ž

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
ROOT_PATH="/home/ubuntu/Reminiscence-BE"
4+
JAR="$ROOT_PATH/application.jar"
5+
STOP_LOG="$ROOT_PATH/stop.log"
6+
SERVICE_PID=$(pgrep -f $JAR) # ์‹คํ–‰์ค‘์ธ Spring ์„œ๋ฒ„์˜ PID
7+
8+
if [ -z "$SERVICE_PID" ]; then
9+
echo "์„œ๋น„์Šค NouFound" >> $STOP_LOG
10+
else
11+
echo "์„œ๋น„์Šค ์ข…๋ฃŒ " >> $STOP_LOG
12+
kill "$SERVICE_PID"
13+
# kill -9 $SERVICE_PID # ๊ฐ•์ œ ์ข…๋ฃŒ๋ฅผ ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์ด ๋ช…๋ น์–ด ์‚ฌ์šฉ
14+
fi

โ€Žsrc/main/java/leets/reminiscence/global/config/WebConfig.javaโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class WebConfig implements WebMvcConfigurer {
1010
public void addCorsMappings(final CorsRegistry registry) {
1111
registry.addMapping("/**")
1212
.allowedOrigins("http://localhost:3000", "http://localhost:8080")
13-
.allowedMethods("GET", "POST", "PUT", "DELETE")
13+
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
1414
.allowCredentials(true)
1515
.exposedHeaders("Authorization", "Authorization-refresh")
1616
.maxAge(3600);

0 commit comments

Comments
ย (0)