Build and Deploy #20
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: Build and Deploy | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| inputs: | |
| no_cache: | |
| description: '빌드 캐시 무시 (secret 변경 시 체크)' | |
| type: boolean | |
| default: false | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| resolve: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| frontend: ${{ steps.out.outputs.frontend }} | |
| backend: ${{ steps.out.outputs.backend }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - id: filter | |
| if: github.event_name == 'push' | |
| uses: dorny/paths-filter@v4 | |
| with: | |
| filters: | | |
| frontend_only: | |
| - 'frontend/**' | |
| backend_only: | |
| - 'backend/**' | |
| - id: out | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| echo "frontend=true" >> "$GITHUB_OUTPUT" | |
| echo "backend=true" >> "$GITHUB_OUTPUT" | |
| else | |
| # 역필터: backend만 변경되면 frontend 스킵, frontend만 변경되면 backend 스킵 | |
| FE_ONLY="${{ steps.filter.outputs.frontend_only }}" | |
| BE_ONLY="${{ steps.filter.outputs.backend_only }}" | |
| echo "frontend=$( [ "$BE_ONLY" = 'true' ] && [ "$FE_ONLY" = 'false' ] && echo false || echo true )" >> "$GITHUB_OUTPUT" | |
| echo "backend=$( [ "$FE_ONLY" = 'true' ] && [ "$BE_ONLY" = 'false' ] && echo false || echo true )" >> "$GITHUB_OUTPUT" | |
| fi | |
| build-frontend: | |
| needs: resolve | |
| if: needs.resolve.outputs.frontend == 'true' | |
| uses: ./.github/workflows/_build-image.yml | |
| with: | |
| component: frontend | |
| dockerfile: ./frontend/Dockerfile | |
| image: ${{ github.repository_owner }}/greedyreader-fe | |
| version: ${{ github.run_number }} | |
| no_cache: ${{ inputs.no_cache || false }} | |
| secrets: | |
| BUILD_ENV: ${{ secrets.FRONTEND_ENV }} | |
| build-backend: | |
| needs: resolve | |
| if: needs.resolve.outputs.backend == 'true' | |
| uses: ./.github/workflows/_build-image.yml | |
| with: | |
| component: backend | |
| dockerfile: ./backend/Dockerfile | |
| image: ${{ github.repository_owner }}/greedyreader-be | |
| version: ${{ github.run_number }} | |
| no_cache: ${{ inputs.no_cache || false }} | |
| deploy: | |
| needs: [resolve, build-frontend, build-backend] | |
| if: | | |
| always() && | |
| !cancelled() && | |
| needs.resolve.result == 'success' && | |
| needs.build-frontend.result != 'failure' && | |
| needs.build-backend.result != 'failure' && | |
| (needs.resolve.outputs.frontend == 'true' || needs.resolve.outputs.backend == 'true') | |
| uses: ./.github/workflows/_deploy-compose.yml | |
| with: | |
| frontend_tag: ${{ needs.resolve.outputs.frontend == 'true' && github.run_number || 'latest' }} | |
| backend_tag: ${{ needs.resolve.outputs.backend == 'true' && github.run_number || 'latest' }} | |
| secrets: | |
| BACKEND_ENV: ${{ secrets.BACKEND_ENV }} |