diff --git a/control-plane/Dockerfile.dev b/control-plane/Dockerfile.dev deleted file mode 100644 index 53f6f68c..00000000 --- a/control-plane/Dockerfile.dev +++ /dev/null @@ -1,34 +0,0 @@ -# Development Dockerfile with hot-reload support -# Uses Air (https://github.com/air-verse/air) for automatic rebuild on file changes - -FROM golang:1.24-bookworm - -# Install build dependencies for CGO (required for SQLite) -RUN apt-get update && apt-get install -y --no-install-recommends \ - build-essential \ - pkg-config \ - && rm -rf /var/lib/apt/lists/* - -# Install Air for hot-reload (v1.61.7 is compatible with Go 1.24) -RUN go install github.com/air-verse/air@v1.61.7 - -WORKDIR /app - -# Copy go.mod and go.sum first for better layer caching -COPY go.mod go.sum ./ -RUN go mod download - -# Copy Air configuration -COPY .air.toml ./ - -# The rest of the source code will be mounted as a volume -# This allows hot-reload to detect changes - -# Create tmp directory for Air builds -RUN mkdir -p tmp - -# Expose the default port -EXPOSE 8080 - -# Run Air for hot-reload development -CMD ["air", "-c", ".air.toml"] diff --git a/control-plane/README.md b/control-plane/README.md index 943edac2..f196f552 100644 --- a/control-plane/README.md +++ b/control-plane/README.md @@ -29,23 +29,20 @@ go run ./cmd/server Visit `http://localhost:8080/ui/` to access the embedded admin UI. -## Local Docker Development +## Local Development with Hot-Reload For development with hot-reload, use the `dev.sh` script. This automatically rebuilds and restarts the server when Go files change. ```bash cd control-plane ./dev.sh # SQLite mode (default, no dependencies) -./dev.sh postgres # PostgreSQL mode -./dev.sh down # Stop containers -./dev.sh clean # Stop and remove volumes +./dev.sh postgres # PostgreSQL mode (set AGENTFIELD_DATABASE_URL first) ``` The server runs at `http://localhost:8080` and will automatically reload when you modify `.go`, `.yaml`, or `.yml` files. **Notes:** -- Uses [Air](https://github.com/air-verse/air) for hot-reload -- Go build cache is persisted in Docker volumes for faster rebuilds +- Uses [Air](https://github.com/air-verse/air) for hot-reload (auto-installed if missing) - Web UI is not included in dev mode; run `npm run dev` separately in `web/client/` if needed ## Configuration diff --git a/control-plane/dev.sh b/control-plane/dev.sh index 9e5e3ff7..4d3c6833 100755 --- a/control-plane/dev.sh +++ b/control-plane/dev.sh @@ -1,30 +1,31 @@ #!/bin/bash -# Start control plane in Docker with hot-reload +# Start control plane with hot-reload using Air # # Usage: -# ./dev.sh # SQLite mode (default) -# ./dev.sh postgres # PostgreSQL mode -# ./dev.sh down # Stop containers -# ./dev.sh clean # Stop and remove volumes +# ./dev.sh # Start with hot-reload (SQLite mode) +# ./dev.sh postgres # Start with PostgreSQL (set AGENTFIELD_DATABASE_URL first) +# +# Prerequisites: +# go install github.com/air-verse/air@v1.61.7 set -e cd "$(dirname "$0")" +# Check if air is installed +if ! command -v air &> /dev/null; then + echo "Air not found. Installing..." + go install github.com/air-verse/air@v1.61.7 +fi + case "${1:-}" in postgres|pg) - echo "Starting control plane with PostgreSQL..." - docker compose -f docker-compose.dev.yml --profile postgres up - ;; - down|stop) - echo "Stopping containers..." - docker compose -f docker-compose.dev.yml --profile postgres down - ;; - clean) - echo "Stopping and removing volumes..." - docker compose -f docker-compose.dev.yml --profile postgres down -v + echo "Starting control plane with PostgreSQL (hot-reload)..." + export AGENTFIELD_STORAGE_MODE=postgresql + air -c .air.toml ;; *) - echo "Starting control plane with SQLite..." - docker compose -f docker-compose.dev.yml up + echo "Starting control plane with SQLite (hot-reload)..." + export AGENTFIELD_STORAGE_MODE=local + air -c .air.toml ;; esac diff --git a/control-plane/docker-compose.dev.yml b/control-plane/docker-compose.dev.yml deleted file mode 100644 index 4ef52ac2..00000000 --- a/control-plane/docker-compose.dev.yml +++ /dev/null @@ -1,87 +0,0 @@ -# Docker Compose for local development with hot-reload -# -# Usage: -# docker compose -f docker-compose.dev.yml up # SQLite mode (default) -# docker compose -f docker-compose.dev.yml --profile postgres up # PostgreSQL mode -# -# The control plane will automatically rebuild and restart when Go files change. - -services: - control-plane: - build: - context: . - dockerfile: Dockerfile.dev - ports: - - "8080:8080" - environment: - # SQLite/local mode (no external dependencies) - AGENTFIELD_STORAGE_MODE: local - AGENTFIELD_HOME: /data - AGENTFIELD_HTTP_ADDR: 0.0.0.0:8080 - AGENTFIELD_LOG_LEVEL: debug - GIN_MODE: debug - CGO_ENABLED: "1" - volumes: - # Mount source code for hot-reload - - .:/app - # Persist data directory - - dev-data:/data - # Use named volume for Go build cache (faster rebuilds) - - go-build-cache:/root/.cache/go-build - - go-mod-cache:/go/pkg/mod - # Keep container running and show logs - tty: true - stdin_open: true - - # PostgreSQL mode - use with: docker compose --profile postgres up - control-plane-pg: - profiles: ["postgres"] - build: - context: . - dockerfile: Dockerfile.dev - ports: - - "8080:8080" - environment: - AGENTFIELD_STORAGE_MODE: postgres - AGENTFIELD_HOME: /data - AGENTFIELD_HTTP_ADDR: 0.0.0.0:8080 - AGENTFIELD_LOG_LEVEL: debug - AGENTFIELD_DATABASE_URL: postgres://agentfield:agentfield@postgres:5432/agentfield?sslmode=disable - AGENTFIELD_POSTGRES_URL: postgres://agentfield:agentfield@postgres:5432/agentfield?sslmode=disable - AGENTFIELD_STORAGE_POSTGRES_URL: postgres://agentfield:agentfield@postgres:5432/agentfield?sslmode=disable - GIN_MODE: debug - CGO_ENABLED: "1" - volumes: - - .:/app - - dev-data-pg:/data - - go-build-cache:/root/.cache/go-build - - go-mod-cache:/go/pkg/mod - depends_on: - postgres: - condition: service_healthy - tty: true - stdin_open: true - - postgres: - profiles: ["postgres"] - image: pgvector/pgvector:pg16 - environment: - POSTGRES_USER: agentfield - POSTGRES_PASSWORD: agentfield - POSTGRES_DB: agentfield - volumes: - - pgdata-dev:/var/lib/postgresql/data - healthcheck: - test: ["CMD-SHELL", "pg_isready -U agentfield"] - interval: 5s - timeout: 3s - retries: 10 - ports: - - "5432:5432" - -volumes: - dev-data: - dev-data-pg: - pgdata-dev: - go-build-cache: - go-mod-cache: