Browse Source

fix(drone): refactor SSH command and deployment logic for improved reliability

- Refactored the SSH command in the Drone configuration to use a variable for options, enhancing readability and maintainability.
- Updated the cloning and pulling logic to ensure the correct branch is used and added error handling for stopping and starting the PM2 process.

These changes streamline the deployment process and improve the robustness of the CI/CD pipeline.
main
npmrun 1 week ago
parent
commit
dd240b1733
  1. 10
      .drone.yml

10
.drone.yml

@ -36,7 +36,9 @@ steps:
- chmod 600 "$HOME/.ssh/id_rsa"
- 'ssh-keyscan -p 8892 -H git.xieyaxin.top >> "$HOME/.ssh/known_hosts"'
- chmod 644 "$HOME/.ssh/known_hosts"
- 'GIT_SSH_COMMAND="ssh -i $HOME/.ssh/id_rsa -o IdentitiesOnly=yes -o UserKnownHostsFile=$HOME/.ssh/known_hosts -o StrictHostKeyChecking=accept-new -o BatchMode=yes -o ConnectTimeout=10 -o ServerAliveInterval=15 -o ServerAliveCountMax=3" ssh -T -p 8892 root@git.xieyaxin.top || true'
- 'if [ ! -d "$HOME/projects/nuxt4-demo/nuxt4-demo" ]; then mkdir -p "$HOME/projects/nuxt4-demo" && GIT_SSH_COMMAND="ssh -i $HOME/.ssh/id_rsa -o IdentitiesOnly=yes -o UserKnownHostsFile=$HOME/.ssh/known_hosts -o StrictHostKeyChecking=accept-new -o BatchMode=yes -o ConnectTimeout=10 -o ServerAliveInterval=15 -o ServerAliveCountMax=3" git clone --depth 1 -b main "ssh://root@git.xieyaxin.top:8892/topuser/nuxt4-demo.git" "$HOME/projects/nuxt4-demo/nuxt4-demo"; else cd "$HOME/projects/nuxt4-demo/nuxt4-demo" && GIT_SSH_COMMAND="ssh -i $HOME/.ssh/id_rsa -o IdentitiesOnly=yes -o UserKnownHostsFile=$HOME/.ssh/known_hosts -o StrictHostKeyChecking=accept-new -o BatchMode=yes -o ConnectTimeout=10 -o ServerAliveInterval=15 -o ServerAliveCountMax=3" git pull origin main; fi'
- pm2 stop nuxt4-demo
- pm2 start nuxt4-demo
- 'export SSH_OPTS="-i $HOME/.ssh/id_rsa -o IdentitiesOnly=yes -o UserKnownHostsFile=$HOME/.ssh/known_hosts -o StrictHostKeyChecking=accept-new -o BatchMode=yes -o ConnectTimeout=10 -o ServerAliveInterval=15 -o ServerAliveCountMax=3"'
- 'ssh $SSH_OPTS -T -p 8892 root@git.xieyaxin.top || true'
- 'if [ ! -d "$HOME/projects/nuxt4-demo/nuxt4-demo" ]; then mkdir -p "$HOME/projects/nuxt4-demo" && GIT_SSH_COMMAND="ssh $SSH_OPTS" git clone --depth 1 -b deploy-branch "ssh://root@git.xieyaxin.top:8892/topuser/nuxt4-demo.git" "$HOME/projects/nuxt4-demo/nuxt4-demo"; else cd "$HOME/projects/nuxt4-demo/nuxt4-demo" && GIT_SSH_COMMAND="ssh $SSH_OPTS" git pull origin deploy-branch; fi'
- 'bash -lc "pm2 stop nuxt4-demo || true"'
- 'bash -lc "pm2 delete nuxt4-demo || true"'
- 'bash -lc "pm2 start ./run.sh --name nuxt4-demo"'
Loading…
Cancel
Save