name: Deploy

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Keyscan
        run: |
          ssh-keyscan git.koptilnya.xyz >> ~/.ssh/known_hosts

      - name: Checkout
        uses: actions/checkout@v4
        with:
          ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
          ssh-strict: false
          persist-credentials: false

      #      - name: Backup DB
      #        run: cp /home/koptilnya/services/chad/data/database.db /home/koptilnya/services/chad/database-$(date+"%d-%m-%Y").db

      - name: Build
        run: docker build -t hh-auto-reply .


      - name: Stop old container
        run: docker rm -f hh-auto-reply || true

#docker run --rm --env-file .env.docker -v $(pwd)/data:/data oscr-test-bot

      - name: Run
        run: |
          docker run -d \
            --name hh-auto-reply \
            --network traefik \
            --volume /home/koptilnya/services/hh-auto-reply/data:/app/data \
            --env OPENROUTER_API_KEY=${{secrets.OPENROUTER_API_KEY}} \
            --env DATABASE_URL=${{secrets.DATABASE_URL}} \
            --env GROQ_API_KEY=${{secrets.GROQ_API_KEY}} \
            --env TG_BOT_TOKEN=${{secrets.TG_BOT_TOKEN}} \
            hh-auto-reply:latest
