kind: pipeline
type: docker
name: tg_autopost_deploy

trigger:
  branch:
    - main
  event:
    - push

steps:
  - name: build
    image: docker:26.1
    environment:
      DOCKER_BUILDKIT: 1
    volumes:
      - name: docker_sock
        path: /var/run/docker.sock
    commands:
      - echo "🔨 Сборка и пуш образов..."
      - docker compose -f docker-compose.yml build

  - name: test
    image: python:3.12-slim
    commands:
      - pip install -r requirements.txt
      - python manage.py test || echo "⚠ Тесты не настроены"

  - name: deploy
    image: appleboy/drone-ssh
    settings:
      host:
        from_secret: ssh_host
      username:
        from_secret: ssh_user
      password:
        from_secret: ssh_pass
      port: 22
      script:
        - cd /home/data/tg_autopost
        - git pull
        - docker compose build
        - docker compose exec django python manage.py migrate
        - docker compose down
        - docker compose up -d

volumes:
  - name: docker_sock
    host:
      path: /var/run/docker.sock
