From dd240b17338088216785c66621d00b3391096b94 Mon Sep 17 00:00:00 2001 From: npmrun <1549469775@qq.com> Date: Wed, 29 Apr 2026 14:54:28 +0800 Subject: [PATCH] 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. --- .drone.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.drone.yml b/.drone.yml index ed92885..c23d0b0 100644 --- a/.drone.yml +++ b/.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 \ No newline at end of file + - '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"' \ No newline at end of file