实现Salon生产流水线自动准备
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
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:
|
||||
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: 检出发布脚本
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ inputs.release_sha }}
|
||||
- name: 准备 Node.js 20
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
- 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: 下载已审核发布包
|
||||
uses: actions/download-artifact@v4
|
||||
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"
|
||||
@@ -0,0 +1,47 @@
|
||||
name: Salon 生产发布准备
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types:
|
||||
- closed
|
||||
branches:
|
||||
- prod
|
||||
|
||||
jobs:
|
||||
prepare:
|
||||
if: >-
|
||||
github.event.pull_request.merged == true &&
|
||||
github.event.pull_request.base.ref == 'prod' &&
|
||||
github.event.pull_request.head.ref == 'sit'
|
||||
runs-on: jayucloud
|
||||
steps:
|
||||
- name: 检出合并提交
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.merge_commit_sha }}
|
||||
fetch-depth: 0
|
||||
- name: 准备 Java 17
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: '17'
|
||||
cache: maven
|
||||
- name: 准备 Node.js 20
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
cache: npm
|
||||
cache-dependency-path: JC-Salon-Frontend/package-lock.json
|
||||
- name: 构建 Salon 发布包
|
||||
shell: pwsh
|
||||
run: >-
|
||||
./docs/scripts/deploy-jayucloud-salon-production.ps1
|
||||
-PackageOnly
|
||||
-SkipDatabaseInit
|
||||
- name: 上传发布包
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: salon-prod-${{ github.event.pull_request.merge_commit_sha }}
|
||||
path: artifacts/release/*
|
||||
if-no-files-found: error
|
||||
retention-days: 30
|
||||
Reference in New Issue
Block a user