Merge pull request #92 from yyoonngg/chore/change-server #108
This file contains hidden or 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 CD (Gradle + Spring Boot) | |
| on: | |
| push: | |
| branches: [ main ] | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout source code | |
| uses: actions/checkout@v3 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Create application-prod.yml from secrets | |
| run: | | |
| mkdir -p src/main/resources | |
| echo "${{ secrets.APPLICATION_PROD_YML }}" > src/main/resources/application-prod.yml | |
| - name: Grant execute permission to Gradle | |
| run: chmod +x ./gradlew | |
| - name: Build JAR with Gradle (exclude test) | |
| run: ./gradlew clean bootJar -x test | |
| - name: Fix jar name (hidaddy.jar로 고정) | |
| run: | | |
| JAR=$(ls build/libs/*.jar | head -n1) | |
| mv "$JAR" build/libs/hidaddy.jar | |
| ls -al build/libs | |
| - name: Upload JAR and Service File to server (root) | |
| uses: appleboy/scp-action@v0.1.6 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_KEY }} | |
| source: "build/libs/hidaddy.jar, deploy/hidaddy.service" | |
| target: "/root" | |
| strip_components: 0 | |
| - name: Deploy on server (systemd, root) | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_KEY }} | |
| script: | | |
| # SSH 연결 테스트 | |
| echo "SSH connection successful" | |
| # JDK 17 보장 (이미 설치되어 있으면 건너뜀) | |
| if ! command -v java >/dev/null 2>&1; then | |
| apt-get update -y && apt-get install -y openjdk-17-jre | |
| fi | |
| # 서비스 파일 배치 | |
| mv -f /root/deploy/hidaddy.service /etc/systemd/system/hidaddy.service | |
| ls -al /etc/systemd/system/hidaddy.service | |
| # JAR를 /root 하위로 고정(필요 시 소유권 조정) | |
| ls -al /root/build/libs/hidaddy.jar | |
| # 시스템 재시작 | |
| sudo systemctl daemon-reload | |
| sudo systemctl enable hidaddy | |
| sudo systemctl restart hidaddy | |
| sudo systemctl status hidaddy --no-pager |