name: Docker Build and Publish on: push: branches: - main - develop tags: - 'v*' workflow_dispatch: env: REGISTRY: docker.io IMAGE_NAME_PREFIX: ruvnet/agentic-flow jobs: # ============================================================================= # Registry credentials: push only when Docker Hub secrets are configured. # Without them the images are still built (amd64 only) so Dockerfile breakage # stays visible, but nothing is logged in to or pushed. # ============================================================================= credentials: runs-on: ubuntu-latest outputs: push: ${{ steps.check.outputs.push }} steps: - id: check env: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} EVENT_NAME: ${{ github.event_name }} run: | if [ -n "$DOCKERHUB_USERNAME" ] && [ -n "$DOCKERHUB_TOKEN" ] && [ "$EVENT_NAME" != "pull_request" ]; then echo "push=true" >> "$GITHUB_OUTPUT" else echo "push=false" >> "$GITHUB_OUTPUT" echo "::notice::DOCKERHUB_USERNAME/DOCKERHUB_TOKEN not configured (or pull_request): building linux/amd64 without pushing" fi # ============================================================================= # Build and Push Docker Images # ============================================================================= build-and-push: runs-on: ubuntu-latest needs: credentials strategy: fail-fast: false matrix: include: - name: "" image: agentic-flow dockerfile: docker/Dockerfile.agentic-flow context: . platforms: linux/amd64,linux/arm64 - name: "-agentdb" image: agentic-flow-agentdb dockerfile: docker/Dockerfile.agentdb context: . platforms: linux/amd64,linux/arm64 - name: "-mcp" image: agentic-flow-mcp dockerfile: docker/Dockerfile.mcp-server context: . platforms: linux/amd64,linux/arm64 - name: "-swarm" image: agentic-flow-swarm dockerfile: docker/Dockerfile.swarm context: . platforms: linux/amd64,linux/arm64 permissions: contents: read packages: write id-token: write steps: - name: Checkout repository uses: actions/checkout@v4 with: submodules: true # docker/Dockerfile.agentdb builds packages/agentdb (a submodule) - name: Set up QEMU if: needs.credentials.outputs.push == 'true' uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to Docker Hub if: needs.credentials.outputs.push == 'true' uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Extract metadata id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/ruvnet/${{ matrix.image }} tags: | type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=sha,prefix=sha- type=raw,value=latest,enable={{is_default_branch}} - name: Build and push Docker image uses: docker/build-push-action@v5 with: context: ${{ matrix.context }} file: ${{ matrix.dockerfile }} platforms: ${{ needs.credentials.outputs.push == 'true' && matrix.platforms || 'linux/amd64' }} push: ${{ needs.credentials.outputs.push == 'true' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max build-args: | VERSION=${{ github.ref_name }} BUILD_DATE=${{ github.event.head_commit.timestamp }} VCS_REF=${{ github.sha }} # ============================================================================= # Security Scanning # ============================================================================= security-scan: runs-on: ubuntu-latest needs: [credentials, build-and-push] if: needs.credentials.outputs.push == 'true' strategy: matrix: image: - agentic-flow - agentic-flow-agentdb - agentic-flow-mcp - agentic-flow-swarm steps: - name: Run Trivy vulnerability scanner uses: aquasecurity/trivy-action@master with: image-ref: ${{ env.REGISTRY }}/ruvnet/${{ matrix.image }}:latest format: 'sarif' output: 'trivy-results-${{ matrix.image }}.sarif' - name: Upload Trivy results to GitHub Security uses: github/codeql-action/upload-sarif@v2 with: sarif_file: 'trivy-results-${{ matrix.image }}.sarif' # ============================================================================= # Integration Tests # ============================================================================= integration-test: runs-on: ubuntu-latest needs: [credentials, build-and-push] if: needs.credentials.outputs.push == 'true' steps: - name: Checkout repository uses: actions/checkout@v4 - name: Create test environment file run: | cat > docker/.env.test < integration-test-logs.txt - name: Upload logs if: failure() uses: actions/upload-artifact@v4 with: name: integration-test-logs path: docker/integration-test-logs.txt - name: Cleanup if: always() run: | cd docker docker-compose down -v # ============================================================================= # Update Docker Hub Description # ============================================================================= update-description: runs-on: ubuntu-latest needs: [credentials, build-and-push] if: needs.credentials.outputs.push == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main' steps: - name: Checkout repository uses: actions/checkout@v4 - name: Update Docker Hub description uses: peter-evans/dockerhub-description@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} repository: ruvnet/agentic-flow readme-filepath: ./docker/README.md short-description: "Production-ready AI agent orchestration platform with 66 specialized agents and 213 MCP tools" # ============================================================================= # Notify on Success # ============================================================================= notify: runs-on: ubuntu-latest needs: [build-and-push, security-scan, integration-test] if: success() && github.event_name == 'push' && github.ref == 'refs/heads/main' steps: - name: Send success notification run: | echo "Docker images successfully built and published!" echo "Images available at: https://hub.docker.com/u/${{ env.IMAGE_NAME_PREFIX }}"