Skip to content

Commit

Permalink
feat: 배포 자동화 with SCP
Browse files Browse the repository at this point in the history
  • Loading branch information
lsc713 committed Jun 21, 2024
1 parent fed0c1c commit e57aa0a
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,49 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Github Repository에 올린 파일들을 불러오기
uses: actions/checkout@v4

- name: JDK 17버전 설치
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17

- name: application.yml 파일 만들기
run: echo "${{ secrets.APPLICATION_PROPERTIES }}" > ./src/main/resources/application.yml

- name: 테스트 및 빌드
run: ./gradlew clean build

- name: 빌드된 파일 이름 변경
run: mv ./build/libs/*SNAPSHOT.jar ./project.jar

- name: SCP로 EC2에 빌드된 파일 전송
uses: applyboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
source: project.jar
target: /home/ubuntu/concurrencyPrac/tobe



- name: SSH 접속
uses: appleboy/[email protected]
env:
APPLICATION_PROPERTIES: ${{ secrets.APPLICATION_DEV_PROPERTIES }}
with:
host: ${{ secrets.EC2_HOST}}
username: ${{ secrets.EC2_USERNAME}}
key: ${{ secrets.EC2_PRIVATE_KEY}}
envs: APPLICATION_DEV_PROPERTIES
script_stop: true
script: |
cd /home/ubuntu/concurrencyPrac
rm -rf scr/main/resources/application.yml
git pull origin master
echo "APPLICATION_DEV_PROPERTIES" > src/main/resources/application-dev.yml
./gradlew clean build
rm -rf /home/ubuntu/concurrencyPrac/current
mkdir /home/ubuntu/concurrencyPrac/current
mv /home/ubuntu/concurrencyPrac/tobe/project.jar /home/ubuntu/concurrencyPrac/current/project.jar
cd /home/ubuntu/concurrencyPrac/current
sudo fuser -k -n tcp 8080 || true
nohup java -jar build/libs/*SNAPSHOT.jar > ./output.log 2>&1 &
nohup java -jar project.jar > ./output.log 2>&1 &
rm -rf /home/ubuntu/concurrencyPrac/tobe

0 comments on commit e57aa0a

Please sign in to comment.