services:
  # Service Astro existant
  app:
    image: node:lts
    ports:
      - 4321:4321
    working_dir: /app
    command: npm run dev -- --host 0.0.0.0
    volumes:
      - ./:/app
    networks:
      - tina-network

  # PostgreSQL pour Tina
  postgres:
    image: postgres:16-alpine
    container_name: tina-postgres
    restart: unless-stopped
    environment:
      POSTGRES_DB: tina
      POSTGRES_USER: tina
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./tina-backend/migrations:/docker-entrypoint-initdb.d:ro
    networks:
      - tina-network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U tina"]
      interval: 5s
      timeout: 5s
      retries: 5

  # Backend TinaCMS
  tina-backend:
    build:
      context: .
      dockerfile: tina-backend/Dockerfile
    container_name: tina-backend
    restart: unless-stopped
    environment:
      NODE_ENV: production
      PORT: 3000
      DATABASE_URL: postgresql://tina:${POSTGRES_PASSWORD}@postgres:5432/tina
      OIDC_ISSUER: ${OIDC_ISSUER}
      OIDC_CLIENT_ID: ${OIDC_CLIENT_ID}
      OIDC_CLIENT_SECRET: ${OIDC_CLIENT_SECRET}
      OIDC_CALLBACK_URL: ${OIDC_CALLBACK_URL}
      OIDC_SCOPE: ${OIDC_SCOPE}
      SESSION_SECRET: ${SESSION_SECRET}
      GITHUB_TOKEN: ${GITHUB_TOKEN}
      GITHUB_REPO: ${GITHUB_REPO}
      GITHUB_OWNER: ${GITHUB_OWNER}
      GITHUB_BRANCH: main
    depends_on:
      postgres:
        condition: service_healthy
    networks:
      - tina-network
    ports:
      - "3000:3000"

volumes:
  postgres_data:

networks:
  tina-network:
    driver: bridge
