ci: 复用部署服务器缓存并支持 HTTPS 同源登录

This commit is contained in:
2026-10-09 21:11:44 +08:00
parent 2cad6d7533
commit ac936d2a1a
14 changed files with 158 additions and 47 deletions
+22 -43
View File
@@ -4,6 +4,8 @@ on:
branches: [master]
env:
REMOTE_DIR: /home/workspace/sundynix-veyra
DEPLOY_HOST: 192.168.100.132
DEPLOY_USER: root
jobs:
verify:
runs-on: ubuntu-latest
@@ -18,14 +20,28 @@ jobs:
curl -fLsS -H "Authorization: token ${GITEA_TOKEN}" \
"https://git.sundynix.cn/${REPOSITORY}/archive/${COMMIT_SHA}.tar.gz" \
| tar -xz --strip-components=1
- name: Check App, embedded admin, Go and PostgreSQL integration
run: bash deploy/check.sh
- name: Install SSH tools
run: |
set -eu
if command -v sshpass >/dev/null && command -v ssh >/dev/null; then exit 0; fi
if command -v apk >/dev/null; then
apk add --no-cache sshpass openssh-client
else
apt-get update -qq
apt-get install -y -qq --no-install-recommends sshpass openssh-client
fi
- name: Verify and build on cached deployment host
env:
SSHPASS: ${{ secrets.DEPLOY_PASSWORD }}
DEPLOY_KNOWN_HOSTS: ${{ secrets.DEPLOY_KNOWN_HOSTS }}
COMMIT_SHA: ${{ github.sha }}
run: bash deploy/ci-ssh.sh verify
deploy:
needs: verify
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Checkout verified commit from Gitea
- name: Checkout exact commit from Gitea
env:
GITEA_TOKEN: ${{ github.token }}
REPOSITORY: ${{ github.repository }}
@@ -35,56 +51,19 @@ jobs:
curl -fLsS -H "Authorization: token ${GITEA_TOKEN}" \
"https://git.sundynix.cn/${REPOSITORY}/archive/${COMMIT_SHA}.tar.gz" \
| tar -xz --strip-components=1
- name: Build and package immutable image
env:
COMMIT_SHA: ${{ github.sha }}
run: |
set -euo pipefail
docker build -t "sundynix/veyra:${COMMIT_SHA}" .
docker save "sundynix/veyra:${COMMIT_SHA}" | gzip > image.tar.gz
sha256sum image.tar.gz > image.tar.gz.sha256
- name: Install SSH tools
run: |
set -eu
if command -v sshpass >/dev/null && command -v ssh >/dev/null; then exit 0; fi
if command -v apk >/dev/null; then
apk add --no-cache sshpass openssh-client
elif command -v apt-get >/dev/null; then
else
apt-get update -qq
apt-get install -y -qq --no-install-recommends sshpass openssh-client
else
echo 'Runner requires ssh and sshpass' >&2
exit 1
fi
- name: Transfer and deploy
- name: Deploy verified image
env:
SSHPASS: ${{ secrets.DEPLOY_PASSWORD }}
DEPLOY_HOST: 192.168.100.132
DEPLOY_USER: root
DEPLOY_KNOWN_HOSTS: ${{ secrets.DEPLOY_KNOWN_HOSTS }}
VEYRA_ENV_FILE: ${{ secrets.VEYRA_ENV_FILE }}
COMMIT_SHA: ${{ github.sha }}
run: |
set -euo pipefail
: "${SSHPASS:?DEPLOY_PASSWORD is required}"
: "${DEPLOY_HOST:?DEPLOY_HOST is required}"
: "${DEPLOY_USER:?DEPLOY_USER is required}"
: "${DEPLOY_KNOWN_HOSTS:?DEPLOY_KNOWN_HOSTS is required}"
[[ "$DEPLOY_HOST" =~ ^[a-zA-Z0-9.-]+$ && "$DEPLOY_USER" =~ ^[a-zA-Z0-9_-]+$ ]] || exit 2
[[ "$COMMIT_SHA" =~ ^[0-9a-f]{40}$ ]] || exit 2
known_hosts="$(mktemp)"
trap 'rm -f "$known_hosts"' EXIT
printf '%s\n' "$DEPLOY_KNOWN_HOSTS" > "$known_hosts"
chmod 600 "$known_hosts"
options=(-o StrictHostKeyChecking=yes -o "UserKnownHostsFile=$known_hosts" -o ConnectTimeout=15)
target="$DEPLOY_USER@$DEPLOY_HOST"
release="$REMOTE_DIR/releases/$COMMIT_SHA"
sshpass -e ssh "${options[@]}" "$target" "umask 077; mkdir -p '$release' '$REMOTE_DIR/configs'"
sshpass -e scp "${options[@]}" deploy/bootstrap-config.sh "$target:$release/"
# Bootstrap once via secret; never replace an existing server configuration.
if [[ -n "$VEYRA_ENV_FILE" ]]; then
printf '%s\n' "$VEYRA_ENV_FILE" | sshpass -e ssh "${options[@]}" "$target" \
"bash '$release/bootstrap-config.sh' '$REMOTE_DIR'"
fi
sshpass -e scp "${options[@]}" image.tar.gz image.tar.gz.sha256 deploy/docker-compose.yml deploy/release.sh "$target:$release/"
sshpass -e ssh "${options[@]}" "$target" "bash '$release/release.sh' '$REMOTE_DIR' '$COMMIT_SHA'"
run: bash deploy/ci-ssh.sh deploy