Build and Push Docker Images (Matrix Strategy) #15
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 Push Docker Images (Matrix Strategy) | |
| on: | |
| repository_dispatch: | |
| types: [custom-release-trigger] | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false # This is the key - builds continue even if one fails | |
| matrix: | |
| include: | |
| - dockerfile: Dockerfile.mod | |
| tag: latest | |
| build_type: standard | |
| cache_scope: standard | |
| - dockerfile: Dockerfile.multi | |
| tag: multi | |
| build_type: multistage | |
| cache_scope: multistage | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Get latest release | |
| id: get_release | |
| uses: pozetroninc/github-action-get-latest-release@master | |
| with: | |
| repository: 42mgr/OO_CommunityServer | |
| token: ${{ secrets.PAT_TOKEN }} | |
| - name: Download .deb from latest release | |
| run: | | |
| echo "📦 Downloading .deb for ${{ matrix.build_type }} build..." | |
| curl -L -o onlyoffice-communityserver-custom.deb \ | |
| -H "Authorization: Bearer ${{ secrets.PAT_TOKEN }}" \ | |
| https://github.com/42mgr/OO_CommunityServer/releases/download/${{ steps.get_release.outputs.release }}/onlyoffice-communityserver-custom.deb | |
| echo "✅ Downloaded and renamed .deb file:" | |
| ls -lh onlyoffice-communityserver-custom.deb | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ${{ matrix.dockerfile }} | |
| push: true | |
| target: ${{ matrix.build_type == 'multistage' && 'final' || '' }} | |
| tags: | | |
| mgr42/oo_crm:${{ matrix.tag }} | |
| mgr42/oo_crm:${{ matrix.tag }}-${{ steps.get_release.outputs.release }} | |
| cache-from: | | |
| type=gha,scope=${{ matrix.cache_scope }} | |
| type=registry,ref=mgr42/oo_crm:cache-${{ matrix.tag }} | |
| cache-to: | | |
| type=gha,mode=max,scope=${{ matrix.cache_scope }} | |
| type=registry,ref=mgr42/oo_crm:cache-${{ matrix.tag }},mode=max | |
| labels: | | |
| org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
| org.opencontainers.image.created=$(date -u +'%Y-%m-%dT%H:%M:%SZ') | |
| org.opencontainers.image.revision=${{ github.sha }} | |
| build.type=${{ matrix.build_type }} | |
| build.dockerfile=${{ matrix.dockerfile }} | |
| - name: Build success notification | |
| if: success() | |
| run: | | |
| echo "✅ ${{ matrix.build_type }} build completed successfully!" | |
| echo "🏷️ Tags: mgr42/oo_crm:${{ matrix.tag }}, mgr42/oo_crm:${{ matrix.tag }}-${{ steps.get_release.outputs.release }}" | |
| echo "📁 Dockerfile: ${{ matrix.dockerfile }}" | |
| - name: Build failure notification | |
| if: failure() | |
| run: | | |
| echo "❌ ${{ matrix.build_type }} build failed!" | |
| echo "📁 Dockerfile: ${{ matrix.dockerfile }}" | |
| echo "ℹ️ Other builds will continue due to fail-fast: false" | |
| # Summary job that always runs | |
| summary: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: always() | |
| steps: | |
| - name: Build Results Summary | |
| run: | | |
| echo "## 📊 Build Results Summary" | |
| echo "" | |
| # Check results from the matrix | |
| STANDARD_RESULT="${{ needs.build.result }}" | |
| # Note: In matrix builds, you get the overall result | |
| # Individual matrix job results aren't directly accessible | |
| # But the build will show individual status in the UI | |
| echo "**Overall Matrix Build Result:** $STANDARD_RESULT" | |
| echo "" | |
| if [ "$STANDARD_RESULT" == "success" ]; then | |
| echo "🎉 All builds completed successfully!" | |
| elif [ "$STANDARD_RESULT" == "failure" ]; then | |
| echo "⚠️ Some builds failed, but others may have succeeded." | |
| echo "Check individual matrix job results above." | |
| else | |
| echo "❓ Unexpected build result: $STANDARD_RESULT" | |
| fi |