Skip to content

Commit

Permalink
Merge pull request #106 from SSUMC-7th/nunu/#11
Browse files Browse the repository at this point in the history
[Nunu] Chapter 11. 무중단 CI/CD (GitHub Actions + AWS EC2)
  • Loading branch information
Ssamssamukja authored Dec 20, 2024
2 parents d83332e + fc73771 commit fc469d7
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 8 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/dev_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: CI/CD Pipeline

on:
push:
branches: [ nunu/develop ] # develop 브랜치에 push가 일어날 때 실행

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3 # 저장소 코드 체크아웃

- name: Set up JDK 17 # Java 개발 킷 설정
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

- name: Make application.yml # application.yml 파일 생성
run: |
cd ./src/main/resources
echo "${{ secrets.APPLICATION_YML }}" > ./application.yml
shell: bash

- name: Grant execute permission for gradlew # gradlew 실행 권한 부여
run: chmod +x gradlew

- name: Build with Gradle # Gradle을 사용하여 프로젝트 빌드
uses: gradle/gradle-build-action@v2
with:
arguments: build

- name: Upload build artifact # 빌드된 아티팩트 업로드
uses: actions/upload-artifact@v3
with:
name: umc7thServer
path: build/libs/*.jar

deploy:
needs: build # build 작업이 성공적으로 완료된 후 실행
runs-on: ubuntu-latest

steps:
- name: Download build artifact # 이전 단계에서 업로드한 아티팩트 다운로드
uses: actions/download-artifact@v3
with:
name: umc7thServer
path: build/libs/

- name: Deploy to EC2 # EC2에 배포
env:
EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }}
EC2_USERNAME: ${{ secrets.EC2_USERNAME }}
EC2_HOST: ${{ secrets.EC2_HOST }}
run: |
echo "$EC2_SSH_KEY" > private_key.pem
chmod 600 private_key.pem
jar_file=$(find build/libs -name '*.jar' ! -name '*plain.jar' | head -n 1)
scp -i private_key.pem -o StrictHostKeyChecking=no "$jar_file" $EC2_USERNAME@$EC2_HOST:/home/$EC2_USERNAME/umc7thServer.jar
ssh -i private_key.pem -o StrictHostKeyChecking=no $EC2_USERNAME@$EC2_HOST "
pgrep java | xargs -r kill -15 # 기존에 실행 중인 Java 프로세스 종료
sleep 10
nohup java -jar /home/$EC2_USERNAME/umc7thServer.jar > app.log 2>&1 & # 새 버전 애플리케이션 실행
"
rm -f private_key.pem # 민감한 정보 삭제
27 changes: 19 additions & 8 deletions spring/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,28 @@ querydsl {
querydslSourcesDir = generated
}

def querydslDir = "src/main/generated"

sourceSets {
main.java.srcDir generated
main.java.srcDirs += [ querydslDir ]
}

compileQuerydsl{
options.annotationProcessorPath = configurations.querydsl
tasks.withType(JavaCompile) {
options.annotationProcessorGeneratedSourcesDirectory = file(querydslDir)
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
querydsl.extendsFrom compileClasspath
clean.doLast {
file(querydslDir).deleteDir()
}

clean {
delete fileTree(dir: 'src/main/generated', include: '**/*.java')
}
tasks.withType(JavaCompile) {
options.compilerArgs += [
'--add-opens',
'java.base/java.lang=ALL-UNNAMED',
'--add-opens',
'java.base/java.util=ALL-UNNAMED'
]
}

0 comments on commit fc469d7

Please sign in to comment.