# image docker for deploy to main
build_image_prod:
  stage: build-prod
  image: docker:latest
  services:
    - docker:dind
  script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker build -t $CI_REGISTRY_IMAGE:prod -f Dockerfile.prod .
    - docker push $CI_REGISTRY_IMAGE:prod
  rules:
    - changes:
      - Dockerfile.prod



deploy to OVH prod:
  image: $CI_REGISTRY_IMAGE:prod
  stage: deploy
  only:
    - main #pas oublier de changer ça quand tu va merge tu met main et pas prod
  before_script:
    - mkdir -p ~/.ssh
    - ssh-keyscan -H $ssh_host >> ~/.ssh/known_hosts
  script:
    - |
      sshpass -p "$ssh_password" ssh $ssh_user@$ssh_host bash << EOF
        cd $path_push
        git fetch --all
        git checkout main
        git pull
        
        # Mise à jour Composer
        php composer.phar self-update
        php composer.phar update phpmailer/phpmailer --no-dev --optimize-autoloader
        
        # Créer le dossier upload pour les PDFs
        echo "📁 Configuration du dossier upload..."
        mkdir -p www/crm-olcv/upload
        chmod -R 777 www/crm-olcv/upload
        echo "✅ Dossier upload configuré !"
        
        exit
      EOF
  after_script:
    - rm -rf ~/.ssh