name: Build MCP Services

on:
  push:
    branches:
      - main
    paths:
      - 'tools-mcp/**'

jobs:
  build-mcp-filesystem:
    runs-on: ubuntu-latest
    env:
      DOCKER_HOST: tcp://172.17.0.1:2375
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Build and push MCP Filesystem (Kaniko)
        run: |
          # Use short SHA for reproducible, auditable image tags. Never push :latest in GitOps.
          SHORT_SHA="${GITHUB_SHA::7}"
          IMAGE_TAG="192.168.8.250:5000/agentic-os/mcp-filesystem:${SHORT_SHA}"
          IMAGE_LATEST="192.168.8.250:5000/agentic-os/mcp-filesystem:latest"

          JOB_CONTAINER=$(docker ps --format '{{.Names}}' | grep 'GITEA-ACTIONS-TASK' | head -1)
          echo "Using volumes from: $JOB_CONTAINER"
          echo "Building image: $IMAGE_TAG"

          docker run --rm \
            --volumes-from "$JOB_CONTAINER" \
            gcr.io/kaniko-project/executor:latest \
              --context=dir:///workspace/deepkoluguri/agentic-os/tools-mcp/mcp-filesystem \
              --dockerfile=Dockerfile \
              --destination="${IMAGE_TAG}" \
              --destination="${IMAGE_LATEST}" \
              --insecure \
              --skip-tls-verify

          echo "Built and pushed: ${IMAGE_TAG}"