Browse Source
- Introduced a new .drone.yml file to define the deployment pipeline, enhancing the CI/CD process. - Updated the deployment script in package.json to reference the correct script for Gitea. - Refined the deployment logic in the existing .drone.prod.yml and .drone.yml files to improve repository management and SSH handling. - Enhanced environment variable management for better security and reliability during deployment. These changes establish a more structured and efficient deployment pipeline, improving automation and security in the CI/CD workflow.main
4 changed files with 102 additions and 11 deletions
@ -0,0 +1,50 @@ |
|||
kind: pipeline |
|||
type: exec |
|||
name: deploy |
|||
clone: |
|||
disable: true |
|||
|
|||
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: |
|||
- mkdir -p -m 700 "/root/.ssh" |
|||
- umask 077 && printf '%s\n' "$DEPLOY_SSH_KEY" > "/root/.ssh/id_rsa" |
|||
- 'ssh-keyscan -H -T 15 gitee.com > "/root/.ssh/known_hosts" && chmod 644 "/root/.ssh/known_hosts"' |
|||
- 'export SSH_OPTS="-i /root/.ssh/id_rsa -o IdentitiesOnly=yes -o UserKnownHostsFile=/root/.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" |
|||
Loading…
Reference in new issue