fix: 세션 오류 해결 #59
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: Spring Boot EC2 Deploy | |
| on: | |
| push: | |
| branches: [ main ] | |
| jobs: | |
| build-and-deploy: | |
| name: Build and Deploy to EC2 | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 1. GitHub에서 코드 체크아웃 | |
| - name: Checkout source code | |
| uses: actions/checkout@v3 | |
| # 2. JDK 17 설치 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| # 3. Gradle Wrapper 권한 부여 및 빌드 | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x ./gradlew | |
| working-directory: was | |
| - name: Build with Gradle | |
| run: ./gradlew clean bootJar --exclude-task test | |
| working-directory: was | |
| # 4. EC2에 SSH 접속하기 위한 키 파일 생성 | |
| - name: Generate SSH key | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.EC2_KEY }}" > ~/.ssh/id_rsa | |
| chmod 600 ~/.ssh/id_rsa | |
| # 5. EC2 known_hosts 등록 | |
| - name: Add EC2 to known hosts | |
| run: | | |
| ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts | |
| # 6. JAR + .env 파일 생성 및 EC2로 전송 | |
| - name: Upload JAR and .env to EC2 | |
| run: | | |
| echo "${{ secrets.ENV_FILE }}" > was/.env | |
| scp -i ~/.ssh/id_rsa was/build/libs/app.jar was/.env ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/home/${{ secrets.EC2_USER }}/senifit/ | |
| # 7. EC2에서 Spring Boot 앱 실행 | |
| - name: Run Spring Boot App on EC2 | |
| run: | | |
| ssh -i ~/.ssh/id_rsa ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << EOF | |
| pkill -f 'java -jar' || true | |
| cd /home/${{ secrets.EC2_USER }}/senifit | |
| nohup java -jar app.jar > logs/console.log 2>&1 & | |
| EOF |