chore: 배포 스크립트 수정 #21
Workflow file for this run
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: Build and Deploy | |
on: | |
push: | |
branches: | |
- '**' | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v2 | |
with: | |
java-version: '17' | |
distribution: 'adopt' | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Create application-secret.yml | |
run: echo "${{ secrets.SECRET }}" > src/main/resources/application-secret.yml | |
- name: Build with Gradle | |
run: ./gradlew build -x test | |
- name: Copy jar to EC2 | |
env: | |
PRIVATE_KEY: ${{ secrets.KEY }} | |
HOST: ${{ secrets.HOST }} | |
USER: ${{ secrets.USER }} | |
run: | | |
echo "$PRIVATE_KEY" > private_key && chmod 600 private_key | |
scp -o StrictHostKeyChecking=no -i private_key build/libs/*.jar ${USER}@${HOST}:${{ secrets.PATH }} | |
- name: Deploy to EC2 | |
env: | |
PRIVATE_KEY: ${{ secrets.KEY }} | |
HOST: ${{ secrets.HOST }} | |
USER: ${{ secrets.USER }} | |
run: | | |
ssh -o StrictHostKeyChecking=no -i private_key ${USER}@${HOST} << EOF | |
cd ${{ secrets.PATH }} | |
pkill -f *.jar || true | |
nohup java -jar *.jar > app.log 2>&1 & | |
EOF |