Build Images #10
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 Images | |
| on: | |
| pull_request: | |
| branches: | |
| - master | |
| types: [opened] | |
| workflow_dispatch: | |
| jobs: | |
| setup_build: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| backend_changed: ${{ steps.changed_files.outputs.backend == 'true' || github.event_name == 'workflow_dispatch' }} | |
| frontend_changed: ${{ steps.changed_files.outputs.frontend == 'true' || github.event_name == 'workflow_dispatch' }} | |
| repo_lc: ${{ steps.lowercase_repo.outputs.REPO_LC }} | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v5 | |
| - name: Get changes | |
| uses: tj-actions/changed-files@90a06d6ba9543371ab4df8eeca0be07ca6054959 | |
| id: changed_files | |
| with: | |
| files_yaml: | | |
| backend: | |
| - 'backend/**' | |
| - '!backend/**/*.md' | |
| frontend: | |
| - 'frontend/**' | |
| - '!frontend/**/*.md' | |
| base_sha: ${{ github.event.pull_request.base.sha || github.sha }} | |
| - name: Set lowercase repository variable | |
| id: lowercase_repo | |
| run: | | |
| REPO_LC=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]') | |
| echo "REPO_LC=$REPO_LC" >> $GITHUB_OUTPUT | |
| build-and-push-backend: | |
| needs: setup_build | |
| runs-on: ubuntu-latest | |
| environment: production | |
| permissions: | |
| packages: write | |
| contents: read | |
| attestations: write | |
| id-token: write | |
| if: ${{ needs.setup_build.outputs.backend_changed == 'true' }} | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v5 | |
| - name: Login to Github Container Registry | |
| uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata (tags, labels) for backend image | |
| id: meta_backend | |
| uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 | |
| with: | |
| images: | | |
| ghcr.io/${{ github.repository }}-backend | |
| - name: Build and push Backend | |
| uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 | |
| with: | |
| context: backend | |
| push: true | |
| tags: | | |
| ${{ steps.meta_backend.outputs.tags }} | |
| ghcr.io/${{ needs.setup_build.outputs.repo_lc }}-backend:latest | |
| labels: ${{ steps.meta_backend.outputs.labels }} | |
| build-and-push-frontend: | |
| needs: setup_build | |
| runs-on: ubuntu-latest | |
| environment: production | |
| permissions: | |
| packages: write | |
| contents: read | |
| attestations: write | |
| id-token: write | |
| if: ${{ needs.setup_build.outputs.frontend_changed == 'true' }} | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v5 | |
| - name: Login to Github Container Registry | |
| uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata (tags, labels) for frontend image | |
| id: meta_frontend | |
| uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 | |
| with: | |
| images: | | |
| ghcr.io/${{ github.repository }}-frontend | |
| - name: Build and push Frontend | |
| uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 | |
| with: | |
| context: frontend | |
| push: true | |
| tags: | | |
| ${{ steps.meta_frontend.outputs.tags }} | |
| ghcr.io/${{ needs.setup_build.outputs.repo_lc }}-frontend:latest | |
| labels: ${{ steps.meta_frontend.outputs.labels }} |