version: '3.8'

# Development overrides for docker-compose.yml
# Usage: docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml up

services:
  # Override server configuration for development
  certctl-server:
    build:
      context: ..
      dockerfile: Dockerfile
      # Proxy propagation (M-4, Issue #9) — forwards host shell's proxy env
      # vars into the Docker build so the Node frontend stage and Go module
      # download can reach the public registries behind corporate proxies.
      # Defaults to empty; omit the variables from the host environment for
      # un-proxied builds and the behaviour is byte-identical to the pre-fix
      # tree.
      args:
        HTTP_PROXY: ${HTTP_PROXY:-}
        HTTPS_PROXY: ${HTTPS_PROXY:-}
        NO_PROXY: ${NO_PROXY:-}
    environment:
      # Verbose logging for development
      CERTCTL_LOG_LEVEL: debug
      CERTCTL_SERVER_HOST: 0.0.0.0
      CERTCTL_SERVER_PORT: "8443"
    volumes:
      # Mount local source for hot reload (requires air or similar)
      # Uncomment if using air or similar for hot reload:
      # - ../cmd:/app/cmd
      # - ../internal:/app/internal
      # - ../api:/app/api
    ports:
      - "8443:8443"
      - "40000:40000"  # Delve debugger port (if debugging)

  # Override agent configuration for development
  certctl-agent:
    build:
      context: ..
      dockerfile: Dockerfile.agent
      # Proxy propagation (M-4, Issue #9) — forwards host shell's proxy env
      # vars into the Docker build so the Go module download stage can reach
      # the public Go module proxy behind corporate proxies. Defaults to
      # empty; omit the variables from the host environment for un-proxied
      # builds and the behaviour is byte-identical to the pre-fix tree.
      args:
        HTTP_PROXY: ${HTTP_PROXY:-}
        HTTPS_PROXY: ${HTTPS_PROXY:-}
        NO_PROXY: ${NO_PROXY:-}
    environment:
      CERTCTL_LOG_LEVEL: debug

  # PgAdmin for database exploration
  pgadmin:
    image: dpage/pgadmin4:latest
    container_name: certctl-pgadmin
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL:-admin@example.com}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD:-admin}
      PGADMIN_CONFIG_SERVER_MODE: 'False'
      PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED: 'False'
    ports:
      - "${PGADMIN_PORT:-5050}:80"
    networks:
      - certctl-network
    depends_on:
      - postgres
    restart: unless-stopped

# Notes for development:
# 1. Enable hot reload by installing air: go install github.com/cosmtrek/air@latest
#    Then in cmd/server and cmd/agent, create .air.toml for watch configuration
# 2. Debug the server by attaching Delve to port 40000
# 3. Access PgAdmin at http://localhost:5050 to browse the database
# 4. View server logs: docker-compose logs -f certctl-server
# 5. View agent logs: docker-compose logs -f certctl-agent
