-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/auth
- Loading branch information
Showing
10 changed files
with
177 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: haemil CICD | ||
run-name: Running | ||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
env: | ||
AWS_REGION: ap-northeast-2 | ||
AWS_S3_BUCKET: haemil-deploy | ||
AWS_CODE_DEPLOY_APPLICATION: haemil-cicd | ||
AWS_CODE_DEPLOY_GROUP: haemil-cicd-deploy-group | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
deploy: | ||
name: Deploy | ||
runs-on: ubuntu-latest | ||
environment: production | ||
|
||
steps: | ||
# (1) 기본 체크아웃 | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
# (2) JDK 11 세팅 | ||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '11' | ||
- name: Copy application-secret | ||
env: | ||
APPLICATION_SECRET: ${{ secrets.APPLICATION_SECRET }} | ||
run: echo "$APPLICATION_SECRET" > src/main/resources/application-secret.yml | ||
|
||
# (3) Gradle build (Test 제외) | ||
- name: Build with Gradle | ||
uses: gradle/gradle-build-action@0d13054264b0bb894ded474f08ebb30921341cee | ||
with: | ||
arguments: clean build -x test | ||
|
||
# (4) AWS 인증 (IAM 사용자 Access Key, Secret Key 활용) | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.IAM_ACCESS_KEY }} | ||
aws-secret-access-key: ${{ secrets.IAM_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
|
||
# (5) 빌드 결과물을 S3 버킷에 업로드 | ||
- name: Upload to AWS S3 | ||
run: | | ||
aws deploy push \ | ||
--application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }} \ | ||
--ignore-hidden-files \ | ||
--s3-location s3://$AWS_S3_BUCKET/$GITHUB_SHA.zip \ | ||
--source . | ||
# (6) S3 버킷에 있는 파일을 대상으로 CodeDeploy 실행 | ||
- name: Deploy to AWS EC2 from S3 | ||
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=$GITHUB_SHA.zip,bundleType=zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ build/ | |
!**/src/test/**/build/ | ||
|
||
### CUSTOM ### | ||
application.yml | ||
application-secret.yml | ||
|
||
### STS ### | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,23 @@ | ||
version: 0.0 | ||
os: linux | ||
# 배포 파일 설정 | ||
## source: 인스턴스에 복사할 디렉터리 경로 | ||
## destination: 인스턴스에서 파일이 복사되는 위치 | ||
## overwrite: 복사할 위치에 파일이 있는 경우 대체 | ||
|
||
files: | ||
- source: / | ||
- source: / | ||
destination: /home/ubuntu/app | ||
overwrite: yes | ||
|
||
# files 섹션에서 복사한 파일에 대한 권한 설정 | ||
## object: 권한이 지정되는 파일 또는 디렉터리 | ||
## pattern (optional): 매칭되는 패턴에만 권한 부여 | ||
## owner (optional): object 의 소유자 | ||
## group (optional): object 의 그룹 이름 | ||
permissions: | ||
- object: / | ||
pattern: "**" | ||
owner: ubuntu | ||
group: ubuntu | ||
mode: 755 | ||
# 배포 이후에 실행할 일련의 라이프사이클 | ||
# 파일을 설치한 후 `AfterInstall` 에서 기존에 실행중이던 애플리케이션을 종료 | ||
# `ApplicationStart` 에서 새로운 애플리케이션을 실행 | ||
## location: hooks 에서 실행할 스크립트 위치 | ||
## timeout (optional): 스크립트 실행에 허용되는 최대 시간이며, 넘으면 배포 실패로 간주됨 | ||
## runas (optional): 스크립트를 실행하는 사용자 | ||
|
||
hooks: | ||
AfterInstall: | ||
# location은 프로젝트의 root경로를 기준 | ||
- location: scripts/deploy.sh | ||
- location: scripts/stop.sh | ||
timeout: 60 | ||
runas: ubuntu | ||
ApplicationStart: | ||
- location: scripts/start.sh | ||
timeout: 60 | ||
runas: ubuntu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,6 @@ dependencies { | |
|
||
} | ||
|
||
tasks.named('test') { | ||
useJUnitPlatform() | ||
jar { | ||
enabled = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
PROJECT_ROOT="/home/ubuntu/app" | ||
JAR_FILE="$PROJECT_ROOT/spring-webapp.jar" | ||
|
||
APP_LOG="$PROJECT_ROOT/application.log" | ||
ERROR_LOG="$PROJECT_ROOT/error.log" | ||
DEPLOY_LOG="$PROJECT_ROOT/deploy.log" | ||
|
||
TIME_NOW=$(date +%c) | ||
|
||
# build 파일 복사 | ||
echo "$TIME_NOW > $JAR_FILE 파일 복사" >> $DEPLOY_LOG | ||
cp $PROJECT_ROOT/build/libs/*.jar $JAR_FILE | ||
|
||
# jar 파일 실행 | ||
echo "$TIME_NOW > $JAR_FILE 파일 실행" >> $DEPLOY_LOG | ||
nohup java -jar $JAR_FILE > $APP_LOG 2> $ERROR_LOG & | ||
|
||
CURRENT_PID=$(pgrep -f $JAR_FILE) | ||
echo "$TIME_NOW > 실행된 프로세스 아이디 $CURRENT_PID 입니다." >> $DEPLOY_LOG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
PROJECT_ROOT="/home/ubuntu/app" | ||
JAR_FILE="$PROJECT_ROOT/spring-webapp.jar" | ||
|
||
DEPLOY_LOG="$PROJECT_ROOT/deploy.log" | ||
|
||
TIME_NOW=$(date +%c) | ||
|
||
# 현재 구동 중인 애플리케이션 pid 확인 | ||
CURRENT_PID=$(pgrep -f $JAR_FILE) | ||
|
||
# 프로세스가 켜져 있으면 종료 | ||
if [ -z $CURRENT_PID ]; then | ||
echo "$TIME_NOW > 현재 실행중인 애플리케이션이 없습니다" >> $DEPLOY_LOG | ||
else | ||
echo "$TIME_NOW > 실행중인 $CURRENT_PID 애플리케이션 종료 " >> $DEPLOY_LOG | ||
kill -15 $CURRENT_PID | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# RDS Config | ||
spring: | ||
profiles: | ||
include: secret | ||
output: | ||
ansi: | ||
enabled: always | ||
|
||
# Redis Config | ||
redis: | ||
host: 127.0.0.1 | ||
port: 6379 | ||
|
||
# logging | ||
logging: | ||
level: | ||
com.haemil.backend: DEBUG |