fix: 환경변수 파일 수정 (#51) #16
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 CD to EC2 | |
| on: | |
| push: | |
| branches: | |
| - develop | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 1. 코드 체크아웃 | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| # 2. JDK 설정 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| cache: 'gradle' | |
| # 3. Gradle 실행 권한 부여 | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| # 4. 빌드 (테스트 포함) | |
| - name: Build with Gradle | |
| run: ./gradlew bootJar -x test | |
| # 5. JAR 파일명 확인 및 환경변수 설정 | |
| - name: Get JAR file name | |
| id: jar_name | |
| run: | | |
| JAR_FILE=$(ls build/libs/*.jar | grep -v plain | head -n 1) | |
| echo "jar_path=$JAR_FILE" >> $GITHUB_OUTPUT | |
| echo "jar_name=$(basename $JAR_FILE)" >> $GITHUB_OUTPUT | |
| # 6. EC2로 JAR 파일 전송 | |
| - name: Copy JAR to EC2 | |
| uses: appleboy/scp-action@master | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USERNAME }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| port: ${{ secrets.EC2_SSH_PORT }} | |
| source: ${{ steps.jar_name.outputs.jar_path }} | |
| target: "/home/${{ secrets.EC2_USERNAME }}/app" | |
| strip_components: 2 | |
| # 7. 배포 스크립트 실행 | |
| - name: Execute deployment script on EC2 | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USERNAME }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| port: ${{ secrets.EC2_SSH_PORT }} | |
| script: | | |
| cd /home/${{ secrets.EC2_USERNAME }}/app | |
| chmod +x deploy.sh | |
| ./deploy.sh ${{ steps.jar_name.outputs.jar_name }} | |
| # 8. 배포 결과 알림 | |
| - name: Notify deployment status | |
| if: always() | |
| run: | | |
| if [ ${{ job.status }} == 'success' ]; then | |
| echo "✅ 배포 성공!" | |
| else | |
| echo "❌ 배포 실패!" | |
| fi |