From 6562963018c613c5439c1253374cef83e088d15d Mon Sep 17 00:00:00 2001 From: Sabiha Khan Date: Mon, 29 Sep 2025 13:19:43 +0530 Subject: [PATCH] refactor: change pipecat to submodule & add github alerts --- .github/workflows/check-pipecat-sync.yml | 23 +++++ .github/workflows/docker-image.yml | 106 +++++++++++++++++++++++ .gitmodules | 3 + api/logging_config.py | 3 +- api/requirements.txt | 1 - pipecat | 1 + scripts/check-pipecat-sync.sh | 90 +++++++++++++++++++ scripts/setup_pipecat.sh | 25 ++++++ 8 files changed, 249 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/check-pipecat-sync.yml create mode 100644 .gitmodules create mode 160000 pipecat create mode 100755 scripts/check-pipecat-sync.sh create mode 100755 scripts/setup_pipecat.sh diff --git a/.github/workflows/check-pipecat-sync.yml b/.github/workflows/check-pipecat-sync.yml new file mode 100644 index 0000000..490d230 --- /dev/null +++ b/.github/workflows/check-pipecat-sync.yml @@ -0,0 +1,23 @@ +name: Check Pipecat Version Sync + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + check-sync: + name: Verify Pipecat Versions Match + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + submodules: true + fetch-depth: 0 + + - name: Make scripts executable + run: chmod +x scripts/*.sh + + - name: Check pipecat version synchronization + run: ./scripts/check-pipecat-sync.sh \ No newline at end of file diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 1babe5a..db2aef1 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -25,6 +25,26 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + with: + submodules: true # Only for version check, not used in build + + - name: Check pipecat version sync + id: version-check + run: | + chmod +x scripts/check-pipecat-sync.sh + + # Capture the output for version details + if OUTPUT=$(./scripts/check-pipecat-sync.sh 2>&1); then + echo "version_mismatch=false" >> $GITHUB_OUTPUT + else + echo "version_mismatch=true" >> $GITHUB_OUTPUT + # Extract version info from the output + SUBMODULE_VERSION=$(echo "$OUTPUT" | grep "Submodule commit:" | awk '{print $3}') + DOCKERFILE_VERSION=$(echo "$OUTPUT" | grep "Dockerfile commit:" | awk '{print $3}') + echo "submodule_version=${SUBMODULE_VERSION}" >> $GITHUB_OUTPUT + echo "dockerfile_version=${DOCKERFILE_VERSION}" >> $GITHUB_OUTPUT + # Don't fail the build, just note the mismatch + fi - name: Set up QEMU # Enables cross-platform builds (e.g., arm64) uses: docker/setup-qemu-action@v3 @@ -46,6 +66,7 @@ jobs: password: ${{ secrets.GHCR_TOKEN }} - name: Build and Push ${{ matrix.service }} + id: docker-build run: | # Parse matrix entry into individual variables SERVICE="${{ matrix.service }}" @@ -58,6 +79,12 @@ jobs: echo "Dockerfile: $DOCKERFILE" echo "Context: $CONTEXT" echo "Commit SHA: $SHORT_SHA" + + # Export tags for Slack notification + echo "image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT + echo "dockerhub_tag=${{ secrets.DOCKERHUB_USERNAME }}/${IMAGE_NAME}:${SHORT_SHA}" >> $GITHUB_OUTPUT + echo "ghcr_tag=ghcr.io/${{ secrets.GHCR_USERNAME }}/${IMAGE_NAME}:${SHORT_SHA}" >> $GITHUB_OUTPUT + echo "short_sha=${SHORT_SHA}" >> $GITHUB_OUTPUT # Build and push multi-arch Docker image to DockerHub and GHCR docker buildx build \ @@ -68,3 +95,82 @@ jobs: --tag ghcr.io/${{ secrets.GHCR_USERNAME }}/$IMAGE_NAME:$SHORT_SHA \ --tag ghcr.io/${{ secrets.GHCR_USERNAME }}/$IMAGE_NAME:latest \ --push "$CONTEXT" + + # Success notification + - name: Send Slack notification - Success + if: success() + uses: slackapi/slack-github-action@v1.26.0 + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + with: + payload: | + { + "text": "āœ… Docker Build Successful", + "blocks": [ + { + "type": "header", + "text": { + "type": "plain_text", + "text": "āœ… Docker Build & Push Successful" + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*Service:* `${{ steps.docker-build.outputs.image_name }}`\n*Commit:* `${{ steps.docker-build.outputs.short_sha }}`\n*Branch:* `${{ github.ref_name }}`\n*Author:* ${{ github.actor }}" + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*šŸ“¦ Published Tags:*\n• DockerHub: `${{ steps.docker-build.outputs.dockerhub_tag }}`\n• DockerHub: `${{ secrets.DOCKERHUB_USERNAME }}/${{ steps.docker-build.outputs.image_name }}:latest`\n• GHCR: `${{ steps.docker-build.outputs.ghcr_tag }}`\n• GHCR: `ghcr.io/${{ secrets.GHCR_USERNAME }}/${{ steps.docker-build.outputs.image_name }}:latest`" + } + }, + { + "type": "context", + "elements": [ + { + "type": "mrkdwn", + "text": "${{ steps.version-check.outputs.version_mismatch == 'true' && format('āš ļø Warning: Pipecat version mismatch detected - <@{0}> <@{1}> please sync versions', secrets.SLACK_DEV1_ID, secrets.SLACK_DEV2_ID) || 'āœ… Pipecat versions in sync' }}" + } + ] + } + ] + } + + # Failure notification + - name: Send Slack notification - Failure + if: failure() + uses: slackapi/slack-github-action@v1.26.0 + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + with: + payload: | + { + "text": "āŒ Docker Build Failed", + "blocks": [ + { + "type": "header", + "text": { + "type": "plain_text", + "text": "āŒ Docker Build Failed" + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*Service:* `${{ steps.docker-build.outputs.image_name || matrix.service }}`\n*Branch:* `${{ github.ref_name }}`\n*Author:* ${{ github.actor }}\n*Workflow:* <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Details>" + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "${{ steps.version-check.outputs.version_mismatch == 'true' && format('*šŸ”“ Pipecat Version Mismatch:*\n• Submodule: `{0}`\n• Dockerfile: `{1}`\n\n_This may have caused the build failure._\n\n<@{2}> <@{3}> Please update api/Dockerfile to use commit {0}', steps.version-check.outputs.submodule_version, steps.version-check.outputs.dockerfile_version, secrets.SLACK_DEV1_ID, secrets.SLACK_DEV2_ID) || '*Failure Reason:* Check workflow logs for details' }}" + } + } + ] + } diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ed6944c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "pipecat"] + path = pipecat + url = https://github.com/dograh-hq/pipecat.git diff --git a/api/logging_config.py b/api/logging_config.py index a07f37b..d1e3a6d 100644 --- a/api/logging_config.py +++ b/api/logging_config.py @@ -1,5 +1,4 @@ -import os -import sys +import os, sys import loguru from pipecat.utils.context import run_id_var, turn_var diff --git a/api/requirements.txt b/api/requirements.txt index d92d3e1..9c3f1d4 100644 --- a/api/requirements.txt +++ b/api/requirements.txt @@ -1,4 +1,3 @@ -pipecat-ai[cartesia,deepgram,openai,elevenlabs,groq,google,azure,soundfile,silero,webrtc] @ git+https://github.com/dograh-hq/pipecat.git@f88c8a0 langfuse==3.4.0 fastapi==0.116.2 asyncpg==0.30.0 diff --git a/pipecat b/pipecat new file mode 160000 index 0000000..f88c8a0 --- /dev/null +++ b/pipecat @@ -0,0 +1 @@ +Subproject commit f88c8a00de00beb93429c86d6353dc2673b6eb77 diff --git a/scripts/check-pipecat-sync.sh b/scripts/check-pipecat-sync.sh new file mode 100755 index 0000000..1dacd4f --- /dev/null +++ b/scripts/check-pipecat-sync.sh @@ -0,0 +1,90 @@ +#!/usr/bin/env bash +# +# check-pipecat-sync.sh +# +# Verifies that the pipecat submodule commit SHA matches the one in Dockerfile. +# Used by CI/CD to ensure versions are synchronized before merging. +# Exit code 0 = versions match, 1 = mismatch or error +# + +set -euo pipefail + +# Colors for output (work in both terminal and CI) +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Get the directory where this script is located +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" + +echo "šŸ” Checking pipecat version synchronization..." + +# Check if pipecat submodule exists +if [ ! -d "$PROJECT_ROOT/pipecat" ]; then + echo -e "${RED}āŒ ERROR: pipecat submodule not found at $PROJECT_ROOT/pipecat${NC}" + echo "Please run: git submodule update --init --recursive" + exit 1 +fi + +# Get the commit from the submodule (use short form - 7 chars) +cd "$PROJECT_ROOT/pipecat" +SUBMODULE_COMMIT=$(git rev-parse HEAD) +SUBMODULE_SHORT=$(git rev-parse --short=7 HEAD) + +echo "šŸ“¦ Submodule commit: $SUBMODULE_SHORT" + +# Check if Dockerfile exists +DOCKERFILE="$PROJECT_ROOT/api/Dockerfile" +if [ ! -f "$DOCKERFILE" ]; then + echo -e "${RED}āŒ ERROR: Dockerfile not found at $DOCKERFILE${NC}" + exit 1 +fi + +# Check if pipecat is installed in Dockerfile +if ! grep -q 'pipecat\.git@' "$DOCKERFILE"; then + echo -e "${RED}āŒ ERROR: No pipecat installation found in api/Dockerfile${NC}" + echo "Expected to find a line like: RUN pip install 'git+https://github.com/dograh-hq/pipecat.git@'" + exit 1 +fi + +# Get the commit from the Dockerfile (extract whatever length is there) +DOCKERFILE_COMMIT=$(grep -oE 'pipecat\.git@[a-f0-9]+' "$DOCKERFILE" | cut -d'@' -f2) +# Normalize to 7 chars for comparison +DOCKERFILE_SHORT=$(echo "$DOCKERFILE_COMMIT" | cut -c1-7) + +echo "🐳 Dockerfile commit: $DOCKERFILE_SHORT" + +# Compare the short commits (7 chars) +if [ "$SUBMODULE_SHORT" != "$DOCKERFILE_SHORT" ]; then + echo "" + echo -e "${RED}āŒ ERROR: Version mismatch detected!${NC}" + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + echo -e "${YELLOW}Submodule:${NC} $SUBMODULE_SHORT" + echo -e "${YELLOW}Dockerfile:${NC} $DOCKERFILE_SHORT" + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + echo "" + echo -e "${BLUE}šŸ‘‰ TO FIX: Update the pipecat commit in api/Dockerfile to match the submodule${NC}" + echo "" + echo "Update api/Dockerfile line with pipecat installation to use commit: $SUBMODULE_SHORT" + echo "Then commit and push the updated api/Dockerfile" + echo "" + + # For GitHub Actions, output in annotation format for PR checks + if [ "${GITHUB_ACTIONS:-false}" == "true" ]; then + echo "::error file=api/Dockerfile,title=Pipecat Version Mismatch::Dockerfile has pipecat@$DOCKERFILE_SHORT but submodule is at $SUBMODULE_SHORT. Please update api/Dockerfile to use commit $SUBMODULE_SHORT" + fi + + exit 1 +fi + +# Success! +echo "" +echo -e "${GREEN}āœ… SUCCESS: Pipecat versions are synchronized!${NC}" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" +echo -e "${GREEN}Both using commit: $SUBMODULE_SHORT${NC}" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + +exit 0 \ No newline at end of file diff --git a/scripts/setup_pipecat.sh b/scripts/setup_pipecat.sh new file mode 100755 index 0000000..d86c25c --- /dev/null +++ b/scripts/setup_pipecat.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Setup script for using pipecat as a git submodule + +# Get the project root directory (parent of scripts) +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +DOGRAH_DIR="$(dirname "$SCRIPT_DIR")" + +cd "$DOGRAH_DIR" + +echo "Setting up pipecat as a git submodule..." + +# Initialize and update submodules +echo "Initializing git submodules..." +git submodule update --init --recursive + +# Install pipecat in editable mode with all extras +echo "Installing pipecat dependencies..." +pip install -e ./pipecat[cartesia,deepgram,openai,elevenlabs,groq,google,azure,soundfile,silero,webrtc] + +# Install other requirements +echo "Installing dograh API requirements..." +pip install -r api/requirements.txt + +echo "Setup complete! Pipecat is now available as a git submodule." \ No newline at end of file