services:
  postgres:
    image: postgres:15-alpine
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-containr}
      POSTGRES_USER: ${POSTGRES_USER:-containr_user}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-dev_password_123}
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-containr_user} -d ${POSTGRES_DB:-containr}"]
      interval: 10s
      timeout: 5s
      retries: 10
    restart: unless-stopped

  redis:
    image: redis:7-alpine
    command: redis-server --requirepass ${REDIS_PASSWORD:-dev_redis_123}
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD-SHELL", "redis-cli -a ${REDIS_PASSWORD:-dev_redis_123} ping | grep PONG"]
      interval: 10s
      timeout: 5s
      retries: 10
    restart: unless-stopped

  backend:
    build:
      context: ./app/backend
      dockerfile: Dockerfile
    ports:
      - "8082:8080"
    environment:
      DATABASE_URL: postgres://${POSTGRES_USER:-containr_user}:${POSTGRES_PASSWORD:-dev_password_123}@postgres:5432/${POSTGRES_DB:-containr}?sslmode=disable
      REDIS_URL: redis://:${REDIS_PASSWORD:-dev_redis_123}@redis:6379/0
      PORT: 8080
      HOST: 0.0.0.0
      ENVIRONMENT: ${ENVIRONMENT:-development}
      JWT_SECRET: ${JWT_SECRET:-dev_jwt_secret_key_change_in_production}
      COOKIE_SECURE: ${COOKIE_SECURE:-false}
      CORS_ORIGINS: ${CORS_ORIGINS:-http://localhost:3000,http://localhost:8082}
      BETTER_AUTH_URL: ${BETTER_AUTH_URL:-http://localhost:8082}
      BETTER_AUTH_PROXY_URL: ${BETTER_AUTH_PROXY_URL:-http://127.0.0.1:3001}
      BETTER_AUTH_INTERNAL_URL: ${BETTER_AUTH_INTERNAL_URL:-http://127.0.0.1:3001/internal/session}
      BETTER_AUTH_INTERNAL_TOKEN: ${BETTER_AUTH_INTERNAL_TOKEN:-PLACEHOLDER_INTERNAL_AUTH_TOKEN}
      BETTER_AUTH_SECRET: ${BETTER_AUTH_SECRET:-PLACEHOLDER_BETTER_AUTH_SECRET_CHANGE_ME_32CHARS_MIN}
      BETTER_AUTH_AUTO_MIGRATE: ${BETTER_AUTH_AUTO_MIGRATE:-true}
      BETTER_AUTH_TRUSTED_ORIGINS: ${BETTER_AUTH_TRUSTED_ORIGINS:-http://localhost:3000,http://localhost:8082}
      FRONTEND_URL: ${FRONTEND_URL:-http://localhost:3000}
      BACKEND_URL: ${BACKEND_URL:-http://localhost:8082}
      AUTH_PORT: ${AUTH_PORT:-3001}
      DB_HOST: postgres
      DB_PORT: 5432
      DB_NAME: ${POSTGRES_DB:-containr}
      DB_USER: ${POSTGRES_USER:-containr_user}
      DB_PASSWORD: ${POSTGRES_PASSWORD:-dev_password_123}
      CONTAINR_AGENT_AUTH_TOKEN: ${CONTAINR_AGENT_AUTH_TOKEN:-}
      CONTAINR_AGENT_AUTH_TOKENS: ${CONTAINR_AGENT_AUTH_TOKENS:-}
      GITHUB_CLIENT_ID: ${GITHUB_CLIENT_ID:-}
      GITHUB_CLIENT_SECRET: ${GITHUB_CLIENT_SECRET:-}
      GITLAB_CLIENT_ID: ${GITLAB_CLIENT_ID:-PLACEHOLDER_GITLAB_CLIENT_ID}
      GITLAB_CLIENT_SECRET: ${GITLAB_CLIENT_SECRET:-PLACEHOLDER_GITLAB_CLIENT_SECRET}
      GITLAB_OAUTH_AUTHORIZE_URL: ${GITLAB_OAUTH_AUTHORIZE_URL:-https://gitlab.com/oauth/authorize}
      GITLAB_OAUTH_TOKEN_URL: ${GITLAB_OAUTH_TOKEN_URL:-https://gitlab.com/oauth/token}
      GITLAB_OAUTH_USERINFO_URL: ${GITLAB_OAUTH_USERINFO_URL:-https://gitlab.com/api/v4/user}
      BITBUCKET_CLIENT_ID: ${BITBUCKET_CLIENT_ID:-PLACEHOLDER_BITBUCKET_CLIENT_ID}
      BITBUCKET_CLIENT_SECRET: ${BITBUCKET_CLIENT_SECRET:-PLACEHOLDER_BITBUCKET_CLIENT_SECRET}
      BITBUCKET_OAUTH_AUTHORIZE_URL: ${BITBUCKET_OAUTH_AUTHORIZE_URL:-https://bitbucket.org/site/oauth2/authorize}
      BITBUCKET_OAUTH_TOKEN_URL: ${BITBUCKET_OAUTH_TOKEN_URL:-https://bitbucket.org/site/oauth2/access_token}
      BITBUCKET_OAUTH_USERINFO_URL: ${BITBUCKET_OAUTH_USERINFO_URL:-https://api.bitbucket.org/2.0/user}
      BITBUCKET_OAUTH_EMAILS_URL: ${BITBUCKET_OAUTH_EMAILS_URL:-https://api.bitbucket.org/2.0/user/emails}
      GITEA_CLIENT_ID: ${GITEA_CLIENT_ID:-PLACEHOLDER_GITEA_CLIENT_ID}
      GITEA_CLIENT_SECRET: ${GITEA_CLIENT_SECRET:-PLACEHOLDER_GITEA_CLIENT_SECRET}
      GITEA_OAUTH_AUTHORIZE_URL: ${GITEA_OAUTH_AUTHORIZE_URL:-https://gitea.example.com/login/oauth/authorize}
      GITEA_OAUTH_TOKEN_URL: ${GITEA_OAUTH_TOKEN_URL:-https://gitea.example.com/login/oauth/access_token}
      GITEA_OAUTH_USERINFO_URL: ${GITEA_OAUTH_USERINFO_URL:-https://gitea.example.com/api/v1/user}
      GITHUB_APP_ID: ${GITHUB_APP_ID:-}
      GITHUB_APP_SLUG: ${GITHUB_APP_SLUG:-}
      GITHUB_APP_PRIVATE_KEY: ${GITHUB_APP_PRIVATE_KEY:-}
      GITHUB_APP_BASE_URL: ${GITHUB_APP_BASE_URL:-https://api.github.com}
      GITLAB_API_URL: ${GITLAB_API_URL:-https://gitlab.com/api/v4}
      GITLAB_BASE_URL: ${GITLAB_BASE_URL:-https://gitlab.com}
      BITBUCKET_API_URL: ${BITBUCKET_API_URL:-https://api.bitbucket.org/2.0}
      BITBUCKET_BASE_URL: ${BITBUCKET_BASE_URL:-https://bitbucket.org}
      GITEA_BASE_URL: ${GITEA_BASE_URL:-https://gitea.example.com}
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    restart: unless-stopped

  frontend:
    build:
      context: ./app/frontend
      dockerfile: Dockerfile
      args:
        VITE_API_URL: ${VITE_API_URL:-http://localhost:8082}
        VITE_AUTH_URL: ${VITE_AUTH_URL:-http://localhost:8082/api/auth}
    ports:
      - "3000:80"
    depends_on:
      backend:
        condition: service_started
    restart: unless-stopped

volumes:
  postgres_data:
  redis_data:
