diff --git a/.drone.yml b/.drone.yml index 59bca69..5350a60 100644 --- a/.drone.yml +++ b/.drone.yml @@ -15,7 +15,8 @@ steps: environment: DEPLOY_BRANCH: deploy REPO_DIR: /root/projects/nuxt4-demo/nuxt4-demo-origin - GIT_REMOTE: ssh://root@git.xieyaxin.top:8892/topuser/nuxt4-demo.git + # Gitea 必须用 git 用户拉代码;用 root@ 可能 SSH 能过但 git 会话卡住 + GIT_REMOTE: ssh://git@git.xieyaxin.top:8892/topuser/nuxt4-demo.git GIT_SSH_HOST: git.xieyaxin.top GIT_SSH_PORT: "8892" UNZIP_DIR: /root/projects/nuxt4-demo/nuxt4-demo @@ -41,23 +42,24 @@ steps: # 须与 GIT_REMOTE 主机一致,否则 StrictHostKeyChecking 会因缺少 [host]:port 的密钥失败 - 'ssh-keyscan -p "$GIT_SSH_PORT" -H -T 15 "$GIT_SSH_HOST" > "/root/.ssh/known_hosts" && chmod 644 "/root/.ssh/known_hosts"' - 'export SSH_OPTS="-i /root/.ssh/id_rsa -p $GIT_SSH_PORT -o IdentitiesOnly=yes -o UserKnownHostsFile=/root/.ssh/known_hosts -o StrictHostKeyChecking=yes -o BatchMode=yes -o ConnectTimeout=10 -o ServerAliveInterval=15 -o ServerAliveCountMax=3"' - # 自托管 Gitea 等在认证成功时仍可能返回非 0,故忽略退出码 - - 'ssh $SSH_OPTS -T root@"$GIT_SSH_HOST" || true' + # 与 GIT_REMOTE 用户一致(deploy key 挂在 Gitea 的 git 访问上) + - 'ssh $SSH_OPTS -T git@"$GIT_SSH_HOST" || true' - 'export GIT_SSH_COMMAND="ssh $SSH_OPTS"' - | set -e + export GIT_TERMINAL_PROMPT=0 BRANCH="$DEPLOY_BRANCH" REPO_DIR="$REPO_DIR" GIT_REMOTE="$GIT_REMOTE" if [ -d "$REPO_DIR/.git" ]; then - git -C "$REPO_DIR" fetch --depth 1 origin "$BRANCH" + git -C "$REPO_DIR" fetch --progress --depth 1 origin "$BRANCH" git -C "$REPO_DIR" checkout -B "$BRANCH" "origin/$BRANCH" git -C "$REPO_DIR" reset --hard "origin/$BRANCH" git -C "$REPO_DIR" clean -fdx else rm -rf "$REPO_DIR" mkdir -p "$(dirname "$REPO_DIR")" - git clone --depth 1 -b "$BRANCH" "$GIT_REMOTE" "$REPO_DIR" + git clone --progress --depth 1 -b "$BRANCH" "$GIT_REMOTE" "$REPO_DIR" fi - | set -e diff --git a/build-files/.drone.prod.yml b/build-files/.drone.prod.yml deleted file mode 100644 index 130e2b0..0000000 --- a/build-files/.drone.prod.yml +++ /dev/null @@ -1,63 +0,0 @@ -kind: pipeline -type: exec -name: deploy -clone: - disable: true - -# 触发分支须包含下方 DEPLOY_BRANCH(或在 Drone 仓库变量里覆盖 DEPLOY_BRANCH) -trigger: - branch: - - deploy - event: - - push - -steps: - - name: deploy - environment: - DEPLOY_BRANCH: deploy - DEPLOY_SSH_KEY: - from_secret: DEPLOY_SSH_KEY - DATABASE_URL: - from_secret: DATABASE_URL - STATIC_DIR: - from_secret: STATIC_DIR - TMP_DIR: - from_secret: TMP_DIR - NUXT_PUBLIC_SITE_URL: - from_secret: NUXT_PUBLIC_SITE_URL - BOOTSTRAP_ADMIN_USERNAME: - from_secret: BOOTSTRAP_ADMIN_USERNAME - BOOTSTRAP_ADMIN_PASSWORD: - from_secret: BOOTSTRAP_ADMIN_PASSWORD - commands: - - export HOME=/root - - mkdir -p "$HOME/.ssh" - - chmod 700 "$HOME/.ssh" - - 'printf "%s\n" "$DEPLOY_SSH_KEY" > "$HOME/.ssh/id_rsa"' - - chmod 600 "$HOME/.ssh/id_rsa" - - 'ssh-keyscan -H gitee.com > "$HOME/.ssh/known_hosts"' - - chmod 644 "$HOME/.ssh/known_hosts" - - '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 gitee.com || true' - - 'export GIT_SSH_COMMAND="ssh $SSH_OPTS"' - - 'export REPO_DIR="$HOME/projects/nuxt4-demo/nuxt4-demo" PROD_DIR="$HOME/projects/nuxt4-demo/production-dist"' - - | - set -e - BRANCH="$DEPLOY_BRANCH" - GIT_REMOTE="git@gitee.com:xieyaxin/nuxt4-demo.git" - if [ -d "$REPO_DIR/.git" ]; then - git -C "$REPO_DIR" fetch --depth 1 origin "$BRANCH" - git -C "$REPO_DIR" checkout -B "$BRANCH" "origin/$BRANCH" - git -C "$REPO_DIR" reset --hard "origin/$BRANCH" - git -C "$REPO_DIR" clean -fdx - else - rm -rf "$REPO_DIR" - mkdir -p "$(dirname "$REPO_DIR")" - git clone --depth 1 -b "$BRANCH" "$GIT_REMOTE" "$REPO_DIR" - fi - - '[ -f "$REPO_DIR/build-output.tar.gz" ] || { echo "build-output.tar.gz not found in $REPO_DIR"; exit 1; }' - - 'rm -rf "$PROD_DIR" && mkdir -p "$PROD_DIR"' - - 'tar -xzf "$REPO_DIR/build-output.tar.gz" -C "$PROD_DIR"' - - 'bash -lc "cd $HOME/projects/nuxt4-demo/production-dist && pm2 stop nuxt4-demo || true"' - - 'bash -lc "cd $HOME/projects/nuxt4-demo/production-dist && pm2 delete nuxt4-demo || true"' - - 'bash -lc "cd $HOME/projects/nuxt4-demo/production-dist && pm2 start ./run.sh --name nuxt4-demo"' \ No newline at end of file diff --git a/build-files/.drone.yml b/build-files/.drone.yml deleted file mode 100644 index 9655802..0000000 --- a/build-files/.drone.yml +++ /dev/null @@ -1,52 +0,0 @@ -kind: pipeline -type: exec -name: deploy -clone: - disable: true - -# 触发分支须包含下方 DEPLOY_BRANCH(或在 Drone 仓库变量里覆盖 DEPLOY_BRANCH) -trigger: - branch: - - deploy - event: - - push - -steps: - - name: deploy - environment: - DEPLOY_BRANCH: deploy - REPO_DIR: /root/projects/nuxt4-demo/nuxt4-demo-origin - GIT_REMOTE: git@gitee.com:xieyaxin/nuxt4-demo.git - UNZIP_DIR: /root/projects/nuxt4-demo/nuxt4-demo - DEPLOY_SSH_KEY: - from_secret: DEPLOY_SSH_KEY - commands: - - export HOME=/root - - mkdir -p -m 700 "$HOME/.ssh" - - umask 077 && printf '%s\n' "$DEPLOY_SSH_KEY" > "$HOME/.ssh/id_rsa" - - 'ssh-keyscan -H -T 15 gitee.com > "$HOME/.ssh/known_hosts" && chmod 644 "$HOME/.ssh/known_hosts"' - - 'export SSH_OPTS="-i $HOME/.ssh/id_rsa -o IdentitiesOnly=yes -o UserKnownHostsFile=$HOME/.ssh/known_hosts -o StrictHostKeyChecking=yes -o BatchMode=yes -o ConnectTimeout=10 -o ServerAliveInterval=15 -o ServerAliveCountMax=3"' - # Gitee 等在认证成功时仍可能返回非 0,故忽略退出码 - - 'ssh $SSH_OPTS -T git@gitee.com || true' - - 'export GIT_SSH_COMMAND="ssh $SSH_OPTS"' - - | - set -e - BRANCH="$DEPLOY_BRANCH" - REPO_DIR="$REPO_DIR" - GIT_REMOTE="$GIT_REMOTE" - if [ -d "$REPO_DIR/.git" ]; then - git -C "$REPO_DIR" fetch --depth 1 origin "$BRANCH" - git -C "$REPO_DIR" checkout -B "$BRANCH" "origin/$BRANCH" - git -C "$REPO_DIR" reset --hard "origin/$BRANCH" - git -C "$REPO_DIR" clean -fdx - else - rm -rf "$REPO_DIR" - mkdir -p "$(dirname "$REPO_DIR")" - git clone --depth 1 -b "$BRANCH" "$GIT_REMOTE" "$REPO_DIR" - fi - - | - set -e - [ -f "$REPO_DIR/build-output.tar.gz" ] || { echo "build-output.tar.gz not found in $REPO_DIR"; exit 1; } - rm -rf "$UNZIP_DIR" - mkdir -p "$UNZIP_DIR" - tar -xzf "$REPO_DIR/build-output.tar.gz" -C "$UNZIP_DIR" \ No newline at end of file