Skip to content

Commit 3ce7b3f

Browse files
committed
feat: AWS CodeDeploy 설정
1 parent a13edb2 commit 3ce7b3f

File tree

7 files changed

+105
-22
lines changed

7 files changed

+105
-22
lines changed

.github/workflows/cicd.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Deploy to AWS CodeDeploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
16+
- name: Set up JDK 17
17+
uses: actions/setup-java@v3
18+
with:
19+
distribution: 'zulu'
20+
java-version: '17'
21+
22+
- name: Grant execute permission for gradlew
23+
run: chmod +x gradlew
24+
25+
- name: Build Spring Boot application
26+
run: ./gradlew clean build -x test
27+
28+
- name: Configure AWS credentials
29+
uses: aws-actions/configure-aws-credentials@v1
30+
with:
31+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
32+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
33+
aws-region: ap-northeast-2
34+
35+
- name: Upload S3
36+
run: aws deploy push
37+
--application-name LikeKNU-Job
38+
--ignore-hidden-files
39+
--s3-location s3://like-knu-job-bucket/job-archive/$GITHUB_SHA.zip
40+
--source .
41+
42+
- name: Deploy EC2
43+
run: aws deploy create-deployment
44+
--application-name LikeKNU-Job
45+
--deployment-config-name CodeDeployDefault.AllAtOnce
46+
--deployment-group-name LikeKNU-Job-Deployment-group
47+
--s3-location bucket=like-knu-job-bucket,key=job-archive/$GITHUB_SHA.zip,bundleType=zip

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ out/
3737
.vscode/
3838

3939
/src/main/resources/application-dev.properties
40+
/src/main/resources/application-prod.properties
4041

4142
/src/main/resources/static/firebase/likeknu-2023-firebase-adminsdk-ehw5i-31d25209d8.json
4243

appspec.yml

+20
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/job-deploy
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

build.gradle

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group = 'ac.knu'
8-
version = '0.0.1-SNAPSHOT'
8+
version = '1.0.0'
99

1010
java {
1111
sourceCompatibility = '17'
@@ -21,6 +21,10 @@ repositories {
2121
mavenCentral()
2222
}
2323

24+
jar {
25+
enabled = false
26+
}
27+
2428
dependencies {
2529
implementation 'org.springframework.boot:spring-boot-starter-amqp'
2630
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

scripts/start.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
ROOT_PATH="/home/ubuntu/job-deploy"
4+
JAR="$ROOT_PATH/job-application.jar"
5+
6+
APP_LOG="$ROOT_PATH/job-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/LikeKNU-JobServer-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

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
ROOT_PATH="/home/ubuntu/job-deploy"
4+
JAR="$ROOT_PATH/job-application.jar"
5+
STOP_LOG="$ROOT_PATH/stop.log"
6+
SERVICE_PID=$(pgrep -f $JAR)
7+
8+
if [ -z "$SERVICE_PID" ]; then
9+
echo "서비스 NotFound" >> $STOP_LOG
10+
else
11+
echo "서비스 종료 " >> $STOP_LOG
12+
kill -9 "$SERVICE_PID"
13+
fi

src/main/resources/application-prod.properties

-21
This file was deleted.

0 commit comments

Comments
 (0)