stages:
  - deploy

deploy_django_app:
  stage: deploy
  image: ubuntu:latest  # Ubuntu tasvirini ishlatish
  only:
    - main
  before_script:
    - apt-get update && apt-get install -y openssh-client  # Ubuntu/Debian uchun to'g'ri paket o'rnatish buyruqlari
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh
    - echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts
  script:
    - ssh $SSH_USER@$SSH_HOST -p $SSH_PORT "
        cd $DEPLOY_PATH &&
        git pull origin main &&
        docker compose up --build -d &&
        docker image prune -f &&
        echo 'Deploy jarayoni muvaffaqiyatli yakunlandi!'"

