Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -1 +1,58 @@

name: CI/CD process

on:
push:
branches:
- "main"
pull_request:
branches: "main"

# 환경변수 설정
env:
S3_BUCKET_NAME: enwise-bucket
AWS_REGION: ap-northeast-2
CODEDEPLOY_NAME: plz-CodeDeploy
CODEDEPLOY_GROUP: plz-CodeDeploy-group

jobs:
build:
runs-on: ubuntu-latest

steps:
# JDK setting - github actions에서 사용할 JDK 설정 (프로젝트나 AWS의 java 버전과 달라도 무방)
- name: Checkout
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash

- name: Build with Gradle
run: ./gradlew build
shell: bash

# S3 설정
- name: Make zip file
run: zip -r ./$GITHUB_SHA.zip .
shell: bash

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Upload to S3
run: aws s3 cp --region $AWS_REGION ./$GITHUB_SHA.zip s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip

# CodeDeploy 설정
- name: Code Deploy
run: aws deploy create-deployment --application-name $CODEDEPLOY_NAME --deployment-config-name CodeDeployDefault.AllAtOnce --deployment-group-name $CODEDEPLOY_GROUP --s3-location bucket=$S3_BUCKET_NAME,bundleType=zip,key=$GITHUB_SHA.zip
19 changes: 19 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 0.0
os: linux
files:
# 서버의 destination 에 source 파일 배포
- source: /
destination: /home/ec2-user/plz/
overwrite: yes
runas: ec2-user

permissions:
- object: /home/ec2-user/plz/
pattern: "**"
owner: ec2-user
group: ec2-user

hooks:
# 배포 후 실행될 스크립트(start.sh)
ApplicationStart:
- location: ./scripts/start.sh
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ dependencies {
implementation'org.springframework.boot:spring-boot-starter-mail'
}

tasks.named('test') {
useJUnitPlatform()
test {
useJUnitPlatform()
}
32 changes: 32 additions & 0 deletions scripts/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# JAR 파일명을 deploy.log에 기록.
JAR_DIR_PATH=/home/ec2-user/plz/build/libs/
BUILD_JAR=$(ls $JAR_DIR_PATH*.jar | grep -nv 'plain')
JAR_NAME=$(basename $BUILD_JAR)
echo "> build 경로: $BUILD_JAR" >> /home/ec2-user/plz/deploy.log
echo "> build 파일명: $JAR_NAME" >> /home/ec2-user/plz/deploy.log

# 빌드된 JAR 파일을 /home/ec2-user/ 디렉토리로 복사
echo "> build 파일 복사" >> /home/ec2-user/plz/deploy.log
DEPLOY_PATH=/home/ec2-user/plz/
#cp $BUILD_JAR $DEPLOY_PATH
cp $JAR_DIR_PATH$JAR_NAME $DEPLOY_PATH

echo "> 현재 실행중인 애플리케이션 pid 확인" >> /home/ec2-user/plz/deploy.log
CURRENT_PID=$(pgrep -f $JAR_NAME)

# 현재 실행 중인 애플리케이션 종료
if [ -z $CURRENT_PID ]
then
echo "> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." >> /home/ec2-user/plz/deploy.log
else
echo "> kill -15 $CURRENT_PID"
kill -15 $CURRENT_PID
sleep 5
fi

# 새로운 JAR 파일 배포 및 실행
DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME
echo "> DEPLOY_JAR 배포" >> /home/ec2-user/plz/deploy.log
nohup java -jar $DEPLOY_JAR >> /home/ec2-user/plz/deploy.log 2>/home/ec2-user/plz/deploy_err.log &
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
// @SpringBootTest
class PlzdrawingApplicationTests {

@Test
Expand Down
Loading