image: ubuntu:20.04

pipelines:
  branches:
    devmaster:
      - step:
          name: Deploy to Server
          script:
            - apt-get update && apt-get install -y openssh-client  # Ensure SSH client is installed
            - mkdir -p ~/.ssh
            - echo "$SSH_KEY_1" | base64 --decode > ~/.ssh/id_rsa
            - chmod 600 ~/.ssh/id_rsa
            - ssh-keyscan -H 209.59.138.122 >> ~/.ssh/known_hosts  # Add the remote server to known_hosts
            
            # Debugging SSH Key Setup
            - ls -lah ~/.ssh
            - cat ~/.ssh/id_rsa | wc -l
            - cat ~/.ssh/known_hosts
            
            # Test SSH connection
            - ssh -o StrictHostKeyChecking=no archesdevelopmen@209.59.138.122 "echo SSH Connection Successful"

            # Execute Git Pull inside the Remote Server
            - |
              ssh -o StrictHostKeyChecking=no archesdevelopmen@209.59.138.122 <<EOF
              set -e  # Exit if any command fails
              cd /home/archesdevelopmen/public_html/ets-saas
              git reset --hard  # Ensure a clean working directory
              git pull origin devmaster
              EOF