Browse Source

refactor(drone): improve PM2 command handling in deployment script

- Replaced direct PM2 commands with a function to check for PM2 or npx availability, enhancing error handling and flexibility.
- Updated the deployment script in .drone.yml to set the PATH correctly, ensuring that npm global binaries are accessible.
- This refactor streamlines the application lifecycle management for the nuxt4-demo, improving the robustness of the deployment process.
main
npmrun 1 week ago
parent
commit
d434011ff1
  1. 25
      .drone.yml

25
.drone.yml

@ -67,6 +67,25 @@ steps:
rm -rf "$UNZIP_DIR"
mkdir -p "$UNZIP_DIR"
tar -xzf "$REPO_DIR/build-output.tar.gz" -C "$UNZIP_DIR"
- 'bash -lc "cd $UNZIP_DIR && pm2 stop nuxt4-demo || true"'
- 'bash -lc "cd $UNZIP_DIR && pm2 delete nuxt4-demo || true"'
- 'bash -lc "cd $UNZIP_DIR && pm2 start ./run.sh --name nuxt4-demo"'
- |
set -e
cd "$UNZIP_DIR"
# exec runner 常缺登录 PATH,补 npm 全局 bin(pm2 多装在这里)
if command -v npm >/dev/null 2>&1; then
_pfx="$(npm config get prefix 2>/dev/null || true)"
case "$_pfx" in /*) export PATH="${_pfx}/bin:${PATH}" ;; esac
fi
export PATH="${HOME}/.bun/bin:/usr/local/bin:/usr/bin:${PATH}"
run_pm2() {
if command -v pm2 >/dev/null 2>&1; then
command pm2 "$@"
elif command -v npx >/dev/null 2>&1; then
npx --yes pm2 "$@"
else
echo "未找到 pm2 且没有 npx,请在 Runner 上执行: npm i -g pm2"
exit 1
fi
}
run_pm2 stop nuxt4-demo || true
run_pm2 delete nuxt4-demo || true
run_pm2 start ./run.sh --name nuxt4-demo
Loading…
Cancel
Save