-
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.
Browse files
Browse the repository at this point in the history
[Nunu] Chapter 11. 무중단 CI/CD (GitHub Actions + AWS EC2)
- Loading branch information
Showing
2 changed files
with
85 additions
and
8 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,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 # 민감한 정보 삭제 |
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