Skip to content

[Setting] CI/CD 구축을 위한 gradle.yml 생성 및 수정 #73

[Setting] CI/CD 구축을 위한 gradle.yml 생성 및 수정

[Setting] CI/CD 구축을 위한 gradle.yml 생성 및 수정 #73

Workflow file for this run

name : SpotServer CI/CD
on:
push:
branches:
- dev
pull_request:
branches:
- dev
jobs:
build:
runs-on : ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: permission
run: chmod +wrx gradlew
- name: Build with Gradle
uses: gradle/[email protected]
with:
arguments: build
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: spotserver
path: build/libs/spotserver-0.0.1-SNAPSHOT.jar
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: spotserver
path: build/libs/
- name: Deploy to EC2
run: |
echo "${{ secrets.SECRET_KEY }}" > secret-key.pem
chmod 600 secret-key.pem
scp -i secret-key.pem -o StrictHostKeyChecking=no build/libs/spotserver-0.0.1-SNAPSHOT.jar ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/home/${{ secrets.EC2_USER }}/
ssh -i secret-key.pem -T -o StrictHostKeyChecking=no ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << EOF
pgrep java | xargs kill -9 || true
nohup java -jar spotserver-0.0.1-SNAPSHOT.jar > nohup.out 2>&1 &
EOF
rm -f secret-key.pem