109 lines
4.7 KiB
YAML
109 lines
4.7 KiB
YAML
name: Salon 生产发布
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
prepare_run_id:
|
|
description: 自动准备工作流的运行 ID
|
|
required: true
|
|
type: string
|
|
release_sha:
|
|
description: prod 合并提交 SHA
|
|
required: true
|
|
type: string
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: jayucloud
|
|
env:
|
|
GITHUB_SERVER_URL: http://192.168.5.15:3000
|
|
WEB_TARGET_HOST: ${{ secrets.SALON_PROD_WEB_HOST }}
|
|
WEB_TARGET_PORT: ${{ secrets.SALON_PROD_WEB_PORT }}
|
|
WEB_TARGET_USER: ${{ secrets.SALON_PROD_WEB_USER }}
|
|
WEB_REMOTE_DIR: ${{ secrets.SALON_PROD_WEB_DIR }}
|
|
steps:
|
|
- name: 从内网 Gitea 检出发布脚本
|
|
shell: bash
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
CHECKOUT_SHA: ${{ inputs.release_sha }}
|
|
run: |
|
|
set -euo pipefail
|
|
test -n "$GITEA_TOKEN"
|
|
test -n "$CHECKOUT_SHA"
|
|
git init .
|
|
git remote add origin "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git"
|
|
git -c http.extraheader="Authorization: token $GITEA_TOKEN" fetch --no-tags --depth=1 origin "$CHECKOUT_SHA"
|
|
git checkout --detach "$CHECKOUT_SHA"
|
|
- name: 发布并校验 Salon 生产 Nacos
|
|
shell: bash
|
|
env:
|
|
NACOS_ENVIRONMENT: prod-both
|
|
NACOS_PROD_URLS: ${{ secrets.NACOS_PROD_URLS }}
|
|
NACOS_PROD_USERNAME: ${{ secrets.NACOS_PROD_USERNAME }}
|
|
NACOS_PROD_PASSWORD: ${{ secrets.NACOS_PROD_PASSWORD }}
|
|
NACOS_DR_URLS: ${{ secrets.NACOS_DR_URLS }}
|
|
NACOS_DR_USERNAME: ${{ secrets.NACOS_DR_USERNAME }}
|
|
NACOS_DR_PASSWORD: ${{ secrets.NACOS_DR_PASSWORD }}
|
|
run: node .gitea/scripts/publish-nacos.mjs
|
|
- name: 检查发布工具链
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
java -version 2>&1 | grep -q '17\.'
|
|
node --version | grep -q '^v20\.'
|
|
pwsh --version
|
|
- name: 下载已审核发布包
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: salon-prod-${{ inputs.release_sha }}
|
|
path: artifacts/release
|
|
repository: ${{ github.repository }}
|
|
run-id: ${{ inputs.prepare_run_id }}
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
- name: 写入临时 SSH 配置和目标清单
|
|
shell: bash
|
|
env:
|
|
SALON_PROD_SSH_PRIVATE_KEY: ${{ secrets.SALON_PROD_SSH_PRIVATE_KEY }}
|
|
SALON_PROD_KNOWN_HOSTS: ${{ secrets.SALON_PROD_KNOWN_HOSTS }}
|
|
run: |
|
|
set -euo pipefail
|
|
test -n "$SALON_PROD_SSH_PRIVATE_KEY"
|
|
test -n "$SALON_PROD_KNOWN_HOSTS"
|
|
test -n "$WEB_TARGET_HOST"
|
|
test -n "$WEB_TARGET_PORT"
|
|
test -n "$WEB_TARGET_USER"
|
|
test -n "$WEB_REMOTE_DIR"
|
|
mkdir -p "$RUNNER_TEMP/salon-prod"
|
|
printf '%s\n' "$SALON_PROD_SSH_PRIVATE_KEY" > "$RUNNER_TEMP/salon-prod/id_ed25519"
|
|
printf '%s\n' "$SALON_PROD_KNOWN_HOSTS" > "$RUNNER_TEMP/salon-prod/known_hosts"
|
|
chmod 600 "$RUNNER_TEMP/salon-prod/id_ed25519" "$RUNNER_TEMP/salon-prod/known_hosts"
|
|
cat > "$RUNNER_TEMP/salon-prod/servers.json" <<JSON
|
|
[
|
|
{"Name":"core01-01","Host":"192.168.10.24","Port":22,"User":"root","Purpose":"Salon Core","Environment":"prod"},
|
|
{"Name":"core01-02","Host":"192.168.10.25","Port":22,"User":"root","Purpose":"Salon Core","Environment":"prod"},
|
|
{"Name":"core01-03","Host":"192.168.20.16","Port":22,"User":"root","Purpose":"Salon Core","Environment":"prod"},
|
|
{"Name":"gateway01-01","Host":"192.168.10.26","Port":22,"User":"root","Purpose":"Salon Gateway","Environment":"prod"},
|
|
{"Name":"gateway01-02","Host":"192.168.10.27","Port":22,"User":"root","Purpose":"Salon Gateway","Environment":"prod"},
|
|
{"Name":"gateway01-03","Host":"192.168.20.18","Port":22,"User":"root","Purpose":"Salon Gateway","Environment":"prod"},
|
|
{"Name":"salon-web","Host":"${WEB_TARGET_HOST}","Port":${WEB_TARGET_PORT},"User":"${WEB_TARGET_USER}","Purpose":"Salon NGINX","Environment":"prod"}
|
|
]
|
|
JSON
|
|
- name: 人工确认后执行生产发布
|
|
shell: pwsh
|
|
env:
|
|
SSH_KEY_PATH: ${{ runner.temp }}/salon-prod/id_ed25519
|
|
KNOWN_HOSTS_PATH: ${{ runner.temp }}/salon-prod/known_hosts
|
|
SERVER_INFO_JSON: ${{ runner.temp }}/salon-prod/servers.json
|
|
run: >-
|
|
./docs/scripts/deploy-jayucloud-salon-production.ps1
|
|
-Deploy
|
|
-SkipDatabaseInit
|
|
-RequireSystemd
|
|
-PackageDirectory "artifacts/release"
|
|
-ServerInfoJsonPath "$env:SERVER_INFO_JSON"
|
|
-SshKeyPath "$env:SSH_KEY_PATH"
|
|
-KnownHostsPath "$env:KNOWN_HOSTS_PATH"
|
|
-WebTargetName salon-web
|
|
-WebRemoteDir "$env:WEB_REMOTE_DIR"
|