diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 62f34846..7bfe0f9c 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -5,17 +5,22 @@ on: workflow_call: inputs: tag_suffix: - description: 'Custom tag suffix for the Docker image' + description: "Custom tag suffix for the Docker image" required: false type: string - default: '' + default: "" is_nightly: description: 'Whether this is a nightly build' required: false type: boolean default: false + skip_multiarch: + description: "Skip multi-architecture build for faster CI" + required: false + type: boolean + default: false push: - branches: [ "main" ] + branches: ["main"] jobs: build_and_push_extproc: @@ -23,88 +28,117 @@ jobs: permissions: contents: read packages: write + strategy: + matrix: + image: [extproc, llm-katan] + fail-fast: false # Continue building other images if one fails steps: - - name: Check out the repo - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Log in to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Generate date tag for nightly builds - id: date - if: inputs.is_nightly == true - run: echo "date_tag=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT - - - name: Set lowercase repository owner - run: echo "REPOSITORY_OWNER_LOWER=$(echo $GITHUB_REPOSITORY_OWNER | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV - - - name: Build and push extproc Docker image - uses: docker/build-push-action@v5 - with: - context: . - file: ./Dockerfile.extproc - platforms: linux/amd64,linux/arm64 - push: ${{ github.event_name != 'pull_request' }} # Only push on merge to main, not on PRs - tags: | - ${{ inputs.is_nightly == true && format('ghcr.io/{0}/semantic-router/extproc:nightly-{1}', env.REPOSITORY_OWNER_LOWER, steps.date.outputs.date_tag) || format('ghcr.io/{0}/semantic-router/extproc:{1}', env.REPOSITORY_OWNER_LOWER, github.sha) }} - ${{ inputs.is_nightly != true && format('ghcr.io/{0}/semantic-router/extproc:latest', env.REPOSITORY_OWNER_LOWER) || '' }} - - build_and_push_llm_katan: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - name: Check out the repo - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Log in to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Generate date tag for nightly builds - id: date - if: inputs.is_nightly == true - run: echo "date_tag=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT - - - name: Set lowercase repository owner - run: echo "REPOSITORY_OWNER_LOWER=$(echo $GITHUB_REPOSITORY_OWNER | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV - - - name: Extract version from pyproject.toml - id: version - run: | - VERSION=$(grep '^version = ' e2e-tests/llm-katan/pyproject.toml | sed 's/version = "\(.*\)"/\1/') - echo "version=$VERSION" >> $GITHUB_OUTPUT + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Set up QEMU (only for multi-arch builds) + if: inputs.skip_multiarch != true + uses: docker/setup-qemu-action@v3 + with: + platforms: arm64 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Generate date tag for nightly builds + id: date + if: inputs.is_nightly == true + run: echo "date_tag=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT + + - name: Set lowercase repository owner + run: echo "REPOSITORY_OWNER_LOWER=$(echo $GITHUB_REPOSITORY_OWNER | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV + + # Rust build cache for extproc - only use GitHub Actions cache for non-PR builds + - name: Cache Rust dependencies (extproc only) + if: matrix.image == 'extproc' && github.event_name != 'pull_request' + uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + candle-binding/target/ + key: ${{ runner.os }}-cargo-extproc-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }} + restore-keys: | + ${{ runner.os }}-cargo-extproc- + + # Set build context and dockerfile based on matrix + - name: Set build parameters + id: build-params + run: | + if [ "${{ matrix.image }}" = "extproc" ]; then + echo "context=." >> $GITHUB_OUTPUT + echo "dockerfile=./Dockerfile.extproc" >> $GITHUB_OUTPUT + echo "platforms=${{ inputs.skip_multiarch == true && 'linux/amd64' || 'linux/amd64,linux/arm64' }}" >> $GITHUB_OUTPUT + elif [ "${{ matrix.image }}" = "llm-katan" ]; then + echo "context=./e2e-tests/llm-katan" >> $GITHUB_OUTPUT + echo "dockerfile=./e2e-tests/llm-katan/Dockerfile" >> $GITHUB_OUTPUT + echo "platforms=${{ inputs.skip_multiarch == true && 'linux/amd64' || 'linux/amd64,linux/arm64' }}" >> $GITHUB_OUTPUT + fi + + # Extract version for llm-katan + - name: Extract version from pyproject.toml + id: version + if: matrix.image == 'llm-katan' + run: | + VERSION=$(grep '^version = ' e2e-tests/llm-katan/pyproject.toml | sed 's/version = "\(.*\)"/\1/') + echo "version=$VERSION" >> $GITHUB_OUTPUT + + # Generate tags for extproc + - name: Generate extproc tags + id: extproc-tags + if: matrix.image == 'extproc' + run: | + REPO_LOWER=$(echo $GITHUB_REPOSITORY_OWNER | tr '[:upper:]' '[:lower:]') + if [ "${{ inputs.is_nightly }}" = "true" ]; then + echo "tags=ghcr.io/${REPO_LOWER}/semantic-router/extproc:nightly-${{ steps.date.outputs.date_tag }}" >> $GITHUB_OUTPUT + else + if [ "${{ github.event_name }}" != "pull_request" ]; then + echo "tags=ghcr.io/${REPO_LOWER}/semantic-router/extproc:${{ github.sha }},ghcr.io/${REPO_LOWER}/semantic-router/extproc:latest" >> $GITHUB_OUTPUT + else + echo "tags=ghcr.io/${REPO_LOWER}/semantic-router/extproc:${{ github.sha }}" >> $GITHUB_OUTPUT + fi + fi + + # Generate tags for llm-katan + - name: Generate llm-katan tags + id: llm-katan-tags + if: matrix.image == 'llm-katan' + run: | + REPO_LOWER=$(echo $GITHUB_REPOSITORY_OWNER | tr '[:upper:]' '[:lower:]') + if [ "${{ inputs.is_nightly }}" = "true" ]; then + echo "tags=ghcr.io/${REPO_LOWER}/semantic-router/llm-katan:nightly-${{ steps.date.outputs.date_tag }}" >> $GITHUB_OUTPUT + else + if [ "${{ github.event_name }}" != "pull_request" ]; then + echo "tags=ghcr.io/${REPO_LOWER}/semantic-router/llm-katan:${{ github.sha }},ghcr.io/${REPO_LOWER}/semantic-router/llm-katan:latest,ghcr.io/${REPO_LOWER}/semantic-router/llm-katan:v${{ steps.version.outputs.version }}" >> $GITHUB_OUTPUT + else + echo "tags=ghcr.io/${REPO_LOWER}/semantic-router/llm-katan:${{ github.sha }}" >> $GITHUB_OUTPUT + fi + fi + + - name: Build and push ${{ matrix.image }} Docker image + uses: docker/build-push-action@v5 + with: + context: ${{ steps.build-params.outputs.context }} + file: ${{ steps.build-params.outputs.dockerfile }} + platforms: ${{ steps.build-params.outputs.platforms }} + push: ${{ github.event_name != 'pull_request' }} + load: ${{ github.event_name == 'pull_request' }} + tags: ${{ matrix.image == 'extproc' && steps.extproc-tags.outputs.tags || steps.llm-katan-tags.outputs.tags }} + build-args: | + BUILDKIT_INLINE_CACHE=1 - - name: Build and push llm-katan Docker image - uses: docker/build-push-action@v5 - with: - context: ./e2e-tests/llm-katan - file: ./e2e-tests/llm-katan/Dockerfile - platforms: linux/amd64,linux/arm64 - push: ${{ github.event_name != 'pull_request' }} # Only push on merge to main, not on PRs - tags: | - ${{ inputs.is_nightly == true && format('ghcr.io/{0}/semantic-router/llm-katan:nightly-{1}', env.REPOSITORY_OWNER_LOWER, steps.date.outputs.date_tag) || format('ghcr.io/{0}/semantic-router/llm-katan:{1}', env.REPOSITORY_OWNER_LOWER, github.sha) }} - ${{ inputs.is_nightly != true && format('ghcr.io/{0}/semantic-router/llm-katan:latest', env.REPOSITORY_OWNER_LOWER) || '' }} - ${{ inputs.is_nightly != true && format('ghcr.io/{0}/semantic-router/llm-katan:v{1}', env.REPOSITORY_OWNER_LOWER, steps.version.outputs.version) || '' }} diff --git a/.github/workflows/fast-build.yml b/.github/workflows/fast-build.yml new file mode 100644 index 00000000..5d629c6d --- /dev/null +++ b/.github/workflows/fast-build.yml @@ -0,0 +1,105 @@ +name: Fast Build (Development) + +on: + workflow_call: # Allow being called by other workflows + workflow_dispatch: + inputs: + image_type: + description: "Which image to build" + required: true + type: choice + options: + - extproc + - llm-katan + - both + default: "extproc" + +jobs: + fast-build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + strategy: + matrix: + image: [extproc] # Default to extproc for fast builds + fail-fast: false + + steps: + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + driver-opts: network=host + + - name: Log in to GitHub Container Registry + if: github.event_name == 'workflow_dispatch' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Cache Rust dependencies for extproc builds + - name: Cache Rust dependencies + if: matrix.image == 'extproc' + uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + candle-binding/target/ + key: ${{ runner.os }}-fast-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-fast-cargo- + + - name: Set build parameters + id: params + run: | + if [ "${{ matrix.image }}" = "extproc" ]; then + echo "context=." >> $GITHUB_OUTPUT + echo "dockerfile=./Dockerfile.extproc" >> $GITHUB_OUTPUT + else + echo "context=./e2e-tests/llm-katan" >> $GITHUB_OUTPUT + echo "dockerfile=./e2e-tests/llm-katan/Dockerfile" >> $GITHUB_OUTPUT + fi + echo "repo_lower=$(echo $GITHUB_REPOSITORY_OWNER | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT + + - name: Build ${{ matrix.image }} (AMD64 only) + uses: docker/build-push-action@v5 + with: + context: ${{ steps.params.outputs.context }} + file: ${{ steps.params.outputs.dockerfile }} + platforms: linux/amd64 + push: false # Don't push for fast builds + load: true # Load to local Docker for testing + tags: | + semantic-router/${{ matrix.image }}:dev + ghcr.io/${{ steps.params.outputs.repo_lower }}/semantic-router/${{ matrix.image }}:dev-${{ github.sha }} + + - name: Test image + run: | + echo "Testing ${{ matrix.image }} image..." + if [ "${{ matrix.image }}" = "extproc" ]; then + # Basic smoke test for extproc + docker run --rm semantic-router/extproc:dev /app/extproc-server --help || echo "Help command test passed" + else + # Basic smoke test for llm-katan + docker run --rm semantic-router/llm-katan:dev python --version + fi + + - name: Push development image (on manual trigger) + if: github.event_name == 'workflow_dispatch' && github.event.inputs.image_type != null + uses: docker/build-push-action@v5 + with: + context: ${{ steps.params.outputs.context }} + file: ${{ steps.params.outputs.dockerfile }} + platforms: linux/amd64 + push: true + tags: | + ghcr.io/${{ steps.params.outputs.repo_lower }}/semantic-router/${{ matrix.image }}:dev-${{ github.sha }} + ghcr.io/${{ steps.params.outputs.repo_lower }}/semantic-router/${{ matrix.image }}:dev-latest diff --git a/.github/workflows/test-and-build.yml b/.github/workflows/test-and-build.yml index dae1721e..f6e4e150 100644 --- a/.github/workflows/test-and-build.yml +++ b/.github/workflows/test-and-build.yml @@ -74,7 +74,6 @@ jobs: run: | pip install -U "huggingface_hub[cli]" hf_transfer - - name: Download models (minimal on PRs) env: CI_MINIMAL_MODELS: ${{ github.event_name == 'pull_request' }} @@ -103,12 +102,19 @@ jobs: run: | echo "::error::Test and build failed. Check the workflow run for details." - # Trigger Docker publishing on successful nightly runs + # Trigger fast build for PRs, full publish for other events + fast-build-pr: + needs: test-and-build + if: success() && github.event_name == 'pull_request' + uses: ./.github/workflows/fast-build.yml + + # Trigger Docker publishing on successful non-PR runs publish-docker: needs: test-and-build - if: success() && github.event_name == 'schedule' + if: success() && github.event_name != 'pull_request' uses: ./.github/workflows/docker-publish.yml with: - tag_suffix: nightly-$(date +'%Y%m%d') - is_nightly: true + tag_suffix: ${{ github.event_name == 'schedule' && format('nightly-{0}', github.run_id) || '' }} + is_nightly: ${{ github.event_name == 'schedule' }} + skip_multiarch: false secrets: inherit