name: Docker Build & Push on: push: branches: [ main ] tags: - 'v*.*.*' pull_request: branches: [ main ] workflow_dispatch: env: REGISTRY: docker.io IMAGE_NAME_MCP: sanjibdevnath/mcp-excalidraw-local IMAGE_NAME_CANVAS: sanjibdevnath/mcp-excalidraw-local-canvas jobs: build-and-push-mcp: name: Build and Push MCP Server Image runs-on: ubuntu-latest permissions: contents: read steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to Docker Hub if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Extract metadata for MCP Server id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_MCP }} tags: | type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}} type=sha,prefix=sha- type=raw,value=latest,enable={{is_default_branch}} - name: Build and push MCP Server image uses: docker/build-push-action@v5 with: context: . file: ./Dockerfile push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max platforms: ${{ github.event_name == 'pull_request' && 'linux/amd64' || 'linux/amd64,linux/arm64' }} build-and-push-canvas: name: Build and Push Canvas Server Image runs-on: ubuntu-latest permissions: contents: read steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to Docker Hub if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Extract metadata for Canvas Server id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_CANVAS }} tags: | type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}} type=sha,prefix=sha- type=raw,value=latest,enable={{is_default_branch}} - name: Build and push Canvas Server image uses: docker/build-push-action@v5 with: context: . file: ./Dockerfile.canvas push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max platforms: ${{ github.event_name == 'pull_request' && 'linux/amd64' || 'linux/amd64,linux/arm64' }} test-docker-images: name: Test Docker Images needs: [build-and-push-mcp, build-and-push-canvas] if: github.event_name != 'pull_request' runs-on: ubuntu-latest steps: - name: Log in to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Test Canvas Server image run: | docker pull ${{ env.IMAGE_NAME_CANVAS }}:latest docker run -d -p 3000:3000 --name test-canvas ${{ env.IMAGE_NAME_CANVAS }}:latest sleep 10 curl -f http://localhost:3000/health || exit 1 docker logs test-canvas docker stop test-canvas - name: Test MCP Server image run: | docker pull ${{ env.IMAGE_NAME_MCP }}:latest echo "MCP Server image pulled successfully" docker-status: runs-on: ubuntu-latest continue-on-error: false name: Docker Build Status Check needs: [build-and-push-mcp, build-and-push-canvas] if: always() permissions: statuses: write steps: - name: Failed id: failed if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') run: | curl -X POST -H "Content-Type: application/json" -H "Authorization: token ${{ github.token }}" \ -d '{ "state" : "failure" , "context" : "github/docker-build-check" , "description" : "Docker build failed", "target_url" : "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" }' \ https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} exit 1 - name: Success if: steps.failed.conclusion == 'skipped' run: | curl -X POST -H "Content-Type: application/json" -H "Authorization: token ${{ github.token }}" \ -d '{ "state" : "success" , "context" : "github/docker-build-check" , "description" : "Docker build passed", "target_url" : "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" }' \ https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }}