Skip to content

Commit

Permalink
Update Deploy.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
jinseohyun1228 authored Nov 7, 2024
1 parent e4cf9ff commit 01366eb
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions .github/workflows/Deploy.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,40 @@
name: Main CI
name: Deploy Spring Project

on:
push:
branches:
- deploy
- deploy # 배포를 원하는 브랜치 이름

jobs:
build-and-deploy:
runs-on: ubuntu-18.04
deploy:
runs-on: ubuntu-latest

steps:
- name: git clone
- name: Check out the repository
uses: actions/checkout@v2

- name: Set up JDK 21
- name: Set up JDK
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '21'
java-version: '21' # JDK 버전

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

- name: Install AWS CLI
run: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
cd boomerang # boomerang 디렉터리로 이동
./gradlew build -x test # Gradle 빌드
- name: Create a deployment package
- name: Copy files to server
run: |
mkdir deployment
cp -r boomerang/build/libs/* deployment/
echo "${{ secrets.application }}" > deployment/application.properties # GitHub Actions 변수로부터 파일 생성
cp appspec.yml deployment/
cd deployment
zip -r deployment-package.zip .
- name: deploy
ssh -i "kwy-root.pem" ubuntu@ec2-52-79-80-3.ap-northeast-2.compute.amazonaws.com << EOF
# 서버에서 실행할 명령어
cd ~/Team11_BE # 프로젝트 디렉터리로 이동
git pull origin deploy # 배포 브랜치에서 업데이트
ps -ef | grep java | awk '{print $2}' | xargs kill -9 # 이전 Java 프로세스 종료
nohup java -jar build/libs/boomerang-0.0.1-SNAPSHOT.jar > log.txt 2>&1 & # 애플리케이션 실행
EOF
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} # SSH 비공개 키를 GitHub Secrets에 저장해두세요.

- name: Check log file
run: |
aws s3 cp deployment/deployment-package.zip s3://home.manual
ssh -i "kwy-root.pem" ubuntu@ec2-52-79-80-3.ap-northeast-2.compute.amazonaws.com "tail -f ~/Team11_BE/log.txt" # 로그 파일 확인

0 comments on commit 01366eb

Please sign in to comment.