name: Deploy-Agent-V15-Stdin
on:
  push:
    branches:
      - main

jobs:
  JOB-V15-STDIN:
    runs-on: debian-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v3

      - name: Install Docker CLI
        run: |
          echo "Installing Docker CLI..."
          apt-get update
          apt-get install -y docker.io docker-compose

      - name: Deploy via Host Docker Socket (Stdin Method)
        run: |
          echo "Piping local compose file to host Docker daemon..."
          
          # We read the compose file from the checked-out code in the runner,
          # but we tell the host Docker daemon that the "project directory" is /memex/projects/opencortex.
          # The host daemon will use its own /memex files to build the image.
          
          cat deploy/docker/docker-compose.yml | docker-compose \
            -p opencortex \
            --project-directory /memex/projects/opencortex \
            -f - \
            down
            
          cat deploy/docker/docker-compose.yml | docker-compose \
            -p opencortex \
            --project-directory /memex/projects/opencortex \
            -f - \
            build --no-cache opencortex
            
          cat deploy/docker/docker-compose.yml | docker-compose \
            -p opencortex \
            --project-directory /memex/projects/opencortex \
            -f - \
            up -d --force-recreate opencortex
