Skip to content

Commit

Permalink
Create cicd.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongmin39 authored Nov 17, 2024
1 parent c49559a commit 3fbab5c
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Java CI/CD with Gradle

on:
push:
branches: [ "dev" ]
pull_request:
branches: [ "dev" ]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- name: Set up SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.EC2_KEY }}" > ~/.ssh/id_rsa
chmod 400 ~/.ssh/id_rsa
ssh-keyscan ${{ secrets.HOST }} >> ~/.ssh/known_hosts
chmod 600 ~/.ssh/known_hosts
- name: Build & Deploy
run: |
ssh ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} '
cd /home/ubuntu &&
git pull &&
./gradlew clean build &&
sudo cp build/libs/spotserver-0.0.1-SNAPSHOT.jar /home/ubuntu/spotserver-0.0.1-SNAPSHOT.jar
'
- name: Restart Service
run: |
ssh ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} '
# 기존 spotserver 프로세스 종료
pkill -f "spotserver-0.0.1-SNAPSHOT.jar" || true &&
# 새로운 spotserver 실행
nohup java -jar /home/ubuntu/spotserver-0.0.1-SNAPSHOT.jar > /home/ubuntu/nohup.out 2>&1 &
'

0 comments on commit 3fbab5c

Please sign in to comment.