Update gradle.yml #37
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: Java CI with Gradle | |
on: | |
push: | |
branches: [ "develop" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- uses: actions/checkout@v4 | |
- run: touch ./backend/src/main/resources/application-api.properties | |
- run: echo "${{ secrets.API_PROPERTIES }}" > ./backend/src/main/resources/application-api.properties | |
- run: cat ./backend/src/main/resources/application-api.properties | |
- run: touch ./backend/src/main/resources/application-security.properties | |
- run: echo "${{ secrets.SECURITY_PROPERTIES }}" > ./backend/src/main/resources/application-security.properties | |
- run: cat ./backend/src/main/resources/application-security.properties | |
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies. | |
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 | |
- name: Set Gradle Wrapper executable permission | |
run: chmod +x ./backend/gradlew | |
- name: Build with Gradle Wrapper | |
run: cd backend/ && ./gradlew build | |
- name: Upload build artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: backend | |
path: ./backend/build/libs/backend-0.0.1-SNAPSHOT.jar | |
# 배포 ** | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download build artifact | |
uses: actions/download-artifact@v2 | |
with: | |
name: backend | |
path: ./backend/build/libs/ | |
- name: Deploy to EC2 | |
run: | | |
echo "${{ secrets.EC2_SSH_KEY }}" > middle-point-search.pem | |
chmod 600 middle-point-search.pem | |
scp -i middle-point-search.pem -o StrictHostKeyChecking=no ./backend/build/libs/backend-0.0.1-SNAPSHOT.jar ${{ secrets.EC2_USERNAME }}@${{ secrets.EC2_HOST }}:/home/${{ secrets.EC2_USERNAME }}/backend-0.0.1-SNAPSHOT.jar | |
ssh -i middle-point-search.pem -o StrictHostKeyChecking=no ${{ secrets.EC2_USERNAME }}@${{ secrets.EC2_HOST }} "pgrep java | xargs kill -9; nohup java -jar /home/${{ secrets.EC2_USERNAME }}/backend-0.0.1-SNAPSHOT.jar &" | |
rm -f middle_point.pem | |