kind: pipeline
type: docker
name: deploy-polisplexity

clone:
  depth: 1
  submodules: false  # <- ya no hay submódulos

steps:
  - name: install dependencies and run Django checks
    image: python:3.10
    environment:
      DATABASE_URL:
        from_secret: DATABASE_URL
      SECRET_KEY:
        from_secret: SECRET_KEY
      DEBUG: "False"
      NEO4J_URI:
        from_secret: NEO4J_URI
      NEO4J_USERNAME:
        from_secret: NEO4J_USERNAME
      NEO4J_PASSWORD:
        from_secret: NEO4J_PASSWORD
      OPENAI_API_KEY:
        from_secret: OPENAI_API_KEY
      PAGE_ACCESS_TOKEN:
        from_secret: PAGE_ACCESS_TOKEN
      VERIFY_TOKEN:
        from_secret: VERIFY_TOKEN
    commands:
      - python -m pip install --upgrade pip
      - pip install -r requirements.txt
      - python manage.py check --deploy --fail-level ERROR
      - echo "✅ Django deploy checks passed"

  - name: deploy to production server
    image: appleboy/drone-ssh
    settings:
      host:
        from_secret: PROD_HOST
      username:
        from_secret: PROD_USER
      port: 22
      key:
        from_secret: PROD_SSH_KEY
      script:
        - cd /home/polisplexity/app.polisplexity.tech
        - git pull origin main
        - docker compose down
        - docker compose up -d --build
        - docker compose exec web python manage.py migrate --noinput
        - docker compose exec web python manage.py collectstatic --noinput
        - echo "🚀 Production deployment complete"
