refactor: docker-compose-prod.yml #203
Workflow file for this run
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: deploy | |
| on: | |
| push: | |
| paths: | |
| - '.github/workflows/**' | |
| - 'backend/**' | |
| branches: [ "main", "develop" ] | |
| pull_request: | |
| paths: | |
| - 'backend/**' | |
| branches: [ "main", "develop" ] | |
| jobs: | |
| backend-ci: | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: ./backend | |
| env: | |
| APPLICATION_SECRET: ${{ secrets.APPLICATION_SECRET }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| # Gradle 캐싱 제거 -> 처음부터 빌드 | |
| - name: Cache Gradle packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}-v2 | |
| restore-keys: | | |
| ${{ runner.os }}-gradle- | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x ./gradlew | |
| - name: application-secret.yml 생성 | |
| run: | | |
| echo "$APPLICATION_SECRET" > src/main/resources/application-secret.yml | |
| - name: Docker Login | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Docker Buildx 설치 | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Start services for test | |
| run: docker compose up -d | |
| - name: Run tests with Gradle | |
| run: ./gradlew test | |
| - name: Stop services after test | |
| if: always() | |
| run: docker compose down | |
| # 테스트 실패 시 리포트를 아티팩트로 업로드하여 디버깅을 돕습니다. | |
| - name: Upload test reports | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-reports | |
| path: backend/build/reports/tests/test/ | |
| # 2. 릴리스 : main/develop 브랜치로 Push될 때만 실행 | |
| makeTagAndRelease: | |
| name: Create Tag and Release | |
| # if: github.event_name == 'push' | |
| needs: backend-ci | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| outputs: | |
| tag_name: ${{ steps.create_tag.outputs.new_tag }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Create Tag | |
| id: create_tag | |
| uses: mathieudutour/github-tag-action@v6.2 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create Release | |
| id: create_release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ steps.create_tag.outputs.new_tag }} | |
| release_name: Release ${{ steps.create_tag.outputs.new_tag }} | |
| body: ${{ steps.create_tag.outputs.changelog }} | |
| draft: false | |
| prerelease: false | |
| # 3. 빌드 및 배포: main/develop 브랜치로 Push될 때만 실행 | |
| buildImageAndPush: | |
| name: 도커 이미지 빌드와 푸시 (디버깅 모드) | |
| needs: makeTagAndRelease | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 1. 소스 코드 체크아웃 | |
| uses: actions/checkout@v4 | |
| - name: 2. JDK 21 설치 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| - name: 3. 체크아웃된 파일 목록 확인 (prod.yml 존재 여부) | |
| run: | | |
| echo "--- 전체 파일 목록 ---" | |
| ls -laR ./backend | |
| echo "--- prod.yml 파일 검색 ---" | |
| find ./backend -name "application-prod.yml" | |
| - name: 4. Gradle 실행 권한 부여 | |
| working-directory: ./backend | |
| run: chmod +x ./gradlew | |
| - name: 5. CI 환경에서 직접 Gradle 빌드 실행 | |
| working-directory: ./backend | |
| run: ./gradlew clean build -x test | |
| - name: 6. 생성된 JAR 파일 내용물 확인 (가장 중요) | |
| run: | | |
| echo "--- 생성된 JAR 파일 내부 목록 확인 ---" | |
| jar -tf ./backend/build/libs/*.jar | grep prod | |
| - name: 7. application-secret.yml 생성 (Docker 빌드용) | |
| env: | |
| APPLICATION_SECRET: ${{ secrets.APPLICATION_SECRET }} | |
| run: | | |
| mkdir -p ./backend/src/main/resources | |
| echo "$APPLICATION_SECRET" > ./backend/src/main/resources/application-secret.yml | |
| - name: 8. Docker 빌드 및 푸시 | |
| uses: docker/build-push-action@v3 | |
| with: | |
| context: ./backend | |
| push: true | |
| no-cache: true | |
| tags: | | |
| ghcr.io/${{ github.repository_owner }}/catch-course:${{ needs.makeTagAndRelease.outputs.tag_name }} | |
| ghcr.io/${{ github.repository_owner }}/catch-course:latest |