name: Build Gumbo Agent

on:
  push:
    branches:
      - main
    paths:
      - 'agents/gumbo/**'

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

      - name: Build and push Gumbo Agent (Kaniko)
        run: |
          SHORT_SHA="${GITHUB_SHA::7}"
          IMAGE_TAG="192.168.8.250:5000/agentic-os/gumbo-agent:${SHORT_SHA}"
          IMAGE_LATEST="192.168.8.250:5000/agentic-os/gumbo-agent:latest"

          JOB_CONTAINER=$(docker ps --format '{{.Names}}' | grep 'GITEA-ACTIONS-TASK' | head -1)
          
          docker run --rm \
            --volumes-from "$JOB_CONTAINER" \
            gcr.io/kaniko-project/executor:latest \
              --context=dir:///workspace/deepkoluguri/agentic-os/agents/gumbo \
              --dockerfile=Dockerfile \
              --destination="${IMAGE_TAG}" \
              --destination="${IMAGE_LATEST}" \
              --insecure \
              --skip-tls-verify

      - name: Build and push Gumbo Worker (Kaniko)
        run: |
          SHORT_SHA="${GITHUB_SHA::7}"
          IMAGE_TAG="192.168.8.250:5000/agentic-os/gumbo-worker:${SHORT_SHA}"
          IMAGE_LATEST="192.168.8.250:5000/agentic-os/gumbo-worker:latest"

          JOB_CONTAINER=$(docker ps --format '{{.Names}}' | grep 'GITEA-ACTIONS-TASK' | head -1)
          
          docker run --rm \
            --volumes-from "$JOB_CONTAINER" \
            gcr.io/kaniko-project/executor:latest \
              --context=dir:///workspace/deepkoluguri/agentic-os/agents/gumbo \
              --dockerfile=Dockerfile.worker \
              --destination="${IMAGE_TAG}" \
              --destination="${IMAGE_LATEST}" \
              --insecure \
              --skip-tls-verify
