fix: CD pipeline 에서 문제가 생기지 않도록 수정 (#157) #11
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
name: Deploy | |
on: | |
push: | |
branches: [ "main" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
token: ${{secrets.PRIVATE_TOKEN}} | |
submodules: true | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Make directory for deliver | |
run: mkdir deploy | |
- name: Build with Gradle | |
run: ./gradlew clean build | |
- name: Deploy Prod use SCP | |
uses: appleboy/scp-action@master | |
with: | |
username: ubuntu | |
host: ${{ secrets.TICKETING_HOST }} | |
key: ${{ secrets.PRIVATE_KEY }} | |
source: "./build/libs/*.jar" | |
target: "/home/ubuntu/deploy" | |
strip_components: 2 | |
- name: Run jar on EC2 using SSH | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.TICKETING_HOST }} | |
username: ubuntu | |
key: ${{ secrets.PRIVATE_KEY }} | |
script: | | |
PID=$(pgrep -f 'java -jar /home/ubuntu/deploy/*.jar') | |
if [ -n "$PID" ]; then | |
echo "Stopping existing application with PID $PID" | |
kill -9 $PID | |
fi | |
nohup java -jar -Dspring.profiles.active=prod /home/ubuntu/deploy/*.jar & | |
- name: Deploy Prod use SCP | |
uses: appleboy/scp-action@master | |
with: | |
username: ubuntu | |
host: ${{ secrets.WAITING_HOST }} | |
key: ${{ secrets.PRIVATE_KEY }} | |
source: "./build/libs/*.jar" | |
target: "/home/ubuntu/deploy" | |
strip_components: 2 | |
- name: Run jar on EC2 using SSH | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.WAITING_HOST }} | |
username: ubuntu | |
key: ${{ secrets.PRIVATE_KEY }} | |
script: | | |
PID=$(pgrep -f 'java -jar /home/ubuntu/deploy/*.jar') | |
if [ -n "$PID" ]; then | |
echo "Stopping existing application with PID $PID" | |
kill -9 $PID | |
fi | |
nohup java -jar -Dspring.profiles.active=prod /home/ubuntu/deploy/*.jar & |