Initial project source
这个提交包含在:
@@ -0,0 +1,38 @@
|
||||
# DataGov release tools
|
||||
|
||||
These tools prepare and verify an immutable DataGov release identity. They do
|
||||
not replace the D-020 preflight, runtime lock, backup gates, migration runner,
|
||||
health checks, authenticated API checks, or Browser acceptance.
|
||||
|
||||
Generate and verify a release manifest after all eight JARs and the frontend
|
||||
`dist` directory have been built:
|
||||
|
||||
```bash
|
||||
install -d -m 700 /approved/datagov-release-evidence
|
||||
ruby script/datagov/release/prepare-release.rb \
|
||||
--release-id r20260901-001 \
|
||||
--output /approved/datagov-release-evidence/release-manifest.json
|
||||
ruby script/datagov/release/verify-release.rb \
|
||||
--manifest /approved/datagov-release-evidence/release-manifest.json
|
||||
```
|
||||
|
||||
The release ID is lowercase, tag-safe, 1–64 characters, and must not be a
|
||||
moving alias such as `latest`, `current`, `previous`, or `rollback`. Reusing a
|
||||
release ID with different manifest bytes fails closed.
|
||||
|
||||
Nacos commands support a no-network `--dry-run` and an explicit `--execute`.
|
||||
Execute mode accepts only the DataGov namespace/group and a mode-0600 DataGov
|
||||
environment file. Configuration content, credentials, and tokens are never
|
||||
printed.
|
||||
|
||||
```bash
|
||||
script/datagov/release/nacos-config-release.sh snapshot \
|
||||
--snapshot-dir /approved/datagov-release-evidence/nacos-before --execute
|
||||
script/datagov/release/nacos-config-release.sh publish-source \
|
||||
--snapshot-dir /approved/datagov-release-evidence/nacos-before --execute
|
||||
script/datagov/release/nacos-config-release.sh restore \
|
||||
--snapshot-dir /approved/datagov-release-evidence/nacos-before --execute
|
||||
```
|
||||
|
||||
Use [the M7 runbook](../../../docs/runbook/M7-发布升级回滚.md) for the required
|
||||
order, rollback boundary, and evidence checklist.
|
||||
@@ -0,0 +1,311 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
readonly PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../../.." && pwd)"
|
||||
readonly DEFAULT_ENV_FILE="${PROJECT_ROOT}/script/datagov/.env.datagov"
|
||||
readonly DEFAULT_SOURCE_DIR="${PROJECT_ROOT}/script/config/datagov/nacos"
|
||||
readonly EXPECTED_NAMESPACE="aixun-datagov-local"
|
||||
readonly EXPECTED_GROUP="AIXUN_DATAGOV_GROUP"
|
||||
readonly CONFIG_FILES=(
|
||||
application-common.yml
|
||||
datasource.yml
|
||||
aixun-datagov-auth.yml
|
||||
aixun-datagov-gateway.yml
|
||||
aixun-datagov-resource.yml
|
||||
aixun-datagov-system.yml
|
||||
aixun-integration.yml
|
||||
aixun-dataops.yml
|
||||
aixun-governance.yml
|
||||
aixun-dataproduct.yml
|
||||
)
|
||||
|
||||
usage() {
|
||||
echo "Usage: nacos-config-release.sh <snapshot|publish-source|restore> --snapshot-dir DIR [--env-file FILE] [--source-dir DIR] [--transport host|container] (--dry-run|--execute)" >&2
|
||||
}
|
||||
|
||||
fail() {
|
||||
echo "DataGov Nacos release operation failed: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[[ $# -ge 1 ]] || {
|
||||
usage
|
||||
exit 2
|
||||
}
|
||||
|
||||
mode="$1"
|
||||
shift
|
||||
snapshot_dir=""
|
||||
env_file="${DEFAULT_ENV_FILE}"
|
||||
source_dir="${DEFAULT_SOURCE_DIR}"
|
||||
execution=""
|
||||
transport="host"
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--snapshot-dir)
|
||||
[[ $# -ge 2 ]] || fail "--snapshot-dir requires a value"
|
||||
snapshot_dir="$2"
|
||||
shift 2
|
||||
;;
|
||||
--env-file)
|
||||
[[ $# -ge 2 ]] || fail "--env-file requires a value"
|
||||
env_file="$2"
|
||||
shift 2
|
||||
;;
|
||||
--source-dir)
|
||||
[[ $# -ge 2 ]] || fail "--source-dir requires a value"
|
||||
source_dir="$2"
|
||||
shift 2
|
||||
;;
|
||||
--transport)
|
||||
[[ $# -ge 2 ]] || fail "--transport requires a value"
|
||||
transport="$2"
|
||||
shift 2
|
||||
;;
|
||||
--dry-run|--execute)
|
||||
[[ -z "${execution}" ]] || fail "choose exactly one of --dry-run or --execute"
|
||||
execution="${1#--}"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
fail "unknown argument: $1"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
case "${mode}" in
|
||||
snapshot|publish-source|restore) ;;
|
||||
*) fail "unsupported mode: ${mode}" ;;
|
||||
esac
|
||||
[[ -n "${snapshot_dir}" ]] || fail "--snapshot-dir is required"
|
||||
[[ -n "${execution}" ]] || fail "choose --dry-run or --execute"
|
||||
case "${transport}" in host|container) ;; *) fail "unsupported transport: ${transport}" ;; esac
|
||||
|
||||
for config_file in "${CONFIG_FILES[@]}"; do
|
||||
if [[ "${mode}" == "publish-source" ]]; then
|
||||
[[ -f "${source_dir}/${config_file}" ]] || fail "source config is missing: ${config_file}"
|
||||
fi
|
||||
done
|
||||
|
||||
validate_snapshot() {
|
||||
[[ -d "${snapshot_dir}" ]] || return 1
|
||||
[[ -f "${snapshot_dir}/metadata.json" && -f "${snapshot_dir}/configs.sha256" ]] || return 1
|
||||
ruby -rjson -e '
|
||||
value=JSON.parse(File.binread(ARGV.fetch(0)))
|
||||
abort "metadata mismatch" unless value == {
|
||||
"schemaVersion"=>1,
|
||||
"namespace"=>"aixun-datagov-local",
|
||||
"group"=>"AIXUN_DATAGOV_GROUP",
|
||||
"configCount"=>10
|
||||
}
|
||||
' "${snapshot_dir}/metadata.json" >/dev/null 2>&1 || return 1
|
||||
for config_file in "${CONFIG_FILES[@]}"; do
|
||||
[[ -f "${snapshot_dir}/${config_file}" ]] || return 1
|
||||
done
|
||||
(cd "${snapshot_dir}" && shasum -a 256 -c configs.sha256 >/dev/null 2>&1) || return 1
|
||||
}
|
||||
|
||||
if [[ "${execution}" == "dry-run" ]]; then
|
||||
case "${mode}" in
|
||||
snapshot)
|
||||
[[ ! -e "${snapshot_dir}" ]] || fail "snapshot directory already exists"
|
||||
;;
|
||||
publish-source|restore)
|
||||
validate_snapshot || fail "complete hashed Nacos snapshot is required"
|
||||
;;
|
||||
esac
|
||||
echo "DRY_RUN mode=${mode} transport=${transport} namespace=${EXPECTED_NAMESPACE} group=${EXPECTED_GROUP} configs=${#CONFIG_FILES[@]}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
[[ -f "${env_file}" ]] || fail "DataGov environment file is missing"
|
||||
env_mode="$(stat -f '%Lp' "${env_file}" 2>/dev/null || stat -c '%a' "${env_file}")"
|
||||
[[ "${env_mode}" == "600" ]] || fail "DataGov environment file must be mode 0600"
|
||||
|
||||
set -a
|
||||
# shellcheck disable=SC1090
|
||||
source "${env_file}"
|
||||
set +a
|
||||
|
||||
[[ "${AIXUN_DATAGOV_NACOS_NAMESPACE:-}" == "${EXPECTED_NAMESPACE}" ]] || fail "unexpected Nacos namespace"
|
||||
[[ "${AIXUN_DATAGOV_NACOS_GROUP:-}" == "${EXPECTED_GROUP}" ]] || fail "unexpected Nacos group"
|
||||
[[ -n "${AIXUN_DATAGOV_NACOS_CLIENT_PORT:-}" ]] || fail "Nacos client port is missing"
|
||||
[[ -n "${AIXUN_DATAGOV_NACOS_USERNAME:-}" && -n "${AIXUN_DATAGOV_NACOS_PASSWORD:-}" ]] || fail "Nacos credentials are missing"
|
||||
|
||||
umask 077
|
||||
tmp_dir="$(mktemp -d "${TMPDIR:-/tmp}/aixun-datagov-nacos-release.XXXXXX")"
|
||||
snapshot_tmp=""
|
||||
access_token=""
|
||||
|
||||
cleanup() {
|
||||
unset access_token AIXUN_DATAGOV_NACOS_PASSWORD AIXUN_DATAGOV_NACOS_USERNAME
|
||||
if [[ -n "${snapshot_tmp}" && -d "${snapshot_tmp}" ]]; then
|
||||
rm -rf -- "${snapshot_tmp}"
|
||||
fi
|
||||
rm -rf -- "${tmp_dir}"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
if [[ "${transport}" == "container" ]]; then
|
||||
readonly NACOS_CONTAINER="aixun-datagov-nacos"
|
||||
container_state="$(docker inspect --format '{{.State.Running}}' "${NACOS_CONTAINER}" 2>/dev/null || true)"
|
||||
[[ "${container_state}" == "true" ]] || fail "Nacos container is not running"
|
||||
compose_project="$(docker inspect --format '{{index .Config.Labels "com.docker.compose.project"}}' "${NACOS_CONTAINER}" 2>/dev/null || true)"
|
||||
owner_project="$(docker inspect --format '{{index .Config.Labels "com.aixun.project"}}' "${NACOS_CONTAINER}" 2>/dev/null || true)"
|
||||
[[ "${compose_project}" == "aixun-datagov-local" ]] || fail "Nacos container has unexpected Compose project"
|
||||
[[ "${owner_project}" == "aixun-datagov" ]] || fail "Nacos container has unexpected owner"
|
||||
readonly NACOS_API_URL="http://127.0.0.1:8848/nacos"
|
||||
else
|
||||
readonly NACOS_API_URL="http://127.0.0.1:${AIXUN_DATAGOV_NACOS_CLIENT_PORT}/nacos"
|
||||
fi
|
||||
|
||||
transport_curl() {
|
||||
local output_file="$1"
|
||||
local status_file="${output_file}.status"
|
||||
local status
|
||||
shift
|
||||
if [[ "${transport}" == "container" ]]; then
|
||||
docker exec -i "${NACOS_CONTAINER}" curl -sS -w '%{stderr}__AIXUN_HTTP_STATUS__%{http_code}' "$@" >"${output_file}" 2>"${status_file}" || true
|
||||
status="$(awk -F'__AIXUN_HTTP_STATUS__' 'NF>1 {value=$NF} END {print value}' "${status_file}")"
|
||||
rm -f -- "${status_file}"
|
||||
else
|
||||
status="$(curl -sS -o "${output_file}" -w '%{http_code}' "$@")"
|
||||
fi
|
||||
printf '%s' "${status}"
|
||||
}
|
||||
|
||||
transport_curl_stdin() {
|
||||
local input_file="$1"
|
||||
local output_file="$2"
|
||||
local status_file="${output_file}.status"
|
||||
local status
|
||||
shift 2
|
||||
if [[ "${transport}" == "container" ]]; then
|
||||
docker exec -i "${NACOS_CONTAINER}" curl -sS -w '%{stderr}__AIXUN_HTTP_STATUS__%{http_code}' "$@" <"${input_file}" >"${output_file}" 2>"${status_file}" || true
|
||||
status="$(awk -F'__AIXUN_HTTP_STATUS__' 'NF>1 {value=$NF} END {print value}' "${status_file}")"
|
||||
rm -f -- "${status_file}"
|
||||
else
|
||||
status="$(curl -sS -o "${output_file}" -w '%{http_code}' "$@" <"${input_file}")"
|
||||
fi
|
||||
printf '%s' "${status}"
|
||||
}
|
||||
|
||||
ruby -ruri -e 'File.binwrite(ARGV.fetch(0), "username=#{URI.encode_www_form_component(ENV.fetch(%q{AIXUN_DATAGOV_NACOS_USERNAME}))}&password=#{URI.encode_www_form_component(ENV.fetch(%q{AIXUN_DATAGOV_NACOS_PASSWORD}))}")' \
|
||||
"${tmp_dir}/login.form"
|
||||
login_status="$(transport_curl_stdin "${tmp_dir}/login.form" "${tmp_dir}/login.json" -X POST "${NACOS_API_URL}/v3/auth/user/login" -H 'Content-Type: application/x-www-form-urlencoded' --data-binary @- 2>"${tmp_dir}/login.err")"
|
||||
[[ "${login_status}" == "200" ]] || fail "Nacos login returned HTTP ${login_status}"
|
||||
access_token="$(ruby -rjson -e 'value=JSON.parse(File.binread(ARGV.fetch(0)))["accessToken"]; print value if value.is_a?(String)' "${tmp_dir}/login.json")"
|
||||
[[ -n "${access_token}" ]] || fail "Nacos login response did not contain a token"
|
||||
|
||||
fetch_config() {
|
||||
local data_id="$1"
|
||||
local output_file="$2"
|
||||
local safe_name="${data_id%.yml}"
|
||||
local response_file="${tmp_dir}/${safe_name}.get.json"
|
||||
local http_status
|
||||
|
||||
http_status="$(transport_curl "${response_file}" -G "${NACOS_API_URL}/v3/admin/cs/config" \
|
||||
-H "Authorization: Bearer ${access_token}" \
|
||||
--data-urlencode "dataId=${data_id}" \
|
||||
--data-urlencode "groupName=${EXPECTED_GROUP}" \
|
||||
--data-urlencode "namespaceId=${EXPECTED_NAMESPACE}")"
|
||||
[[ "${http_status}" == "200" ]] || return 1
|
||||
|
||||
ruby -rjson -e '
|
||||
response=JSON.parse(File.binread(ARGV.fetch(0)))
|
||||
abort "invalid code" unless response["code"] == 0
|
||||
data=response["data"]
|
||||
content=data.is_a?(String) ? data : (data.is_a?(Hash) ? data["content"] : nil)
|
||||
abort "unsupported data shape" unless content.is_a?(String)
|
||||
File.binwrite(ARGV.fetch(1), content)
|
||||
' "${response_file}" "${output_file}" >/dev/null 2>"${tmp_dir}/${safe_name}.parse.err"
|
||||
}
|
||||
|
||||
post_config() {
|
||||
local data_id="$1"
|
||||
local content_file="$2"
|
||||
local safe_name="${data_id%.yml}"
|
||||
local response_file="${tmp_dir}/${safe_name}.post.json"
|
||||
local http_status
|
||||
|
||||
http_status="$(transport_curl_stdin "${content_file}" "${response_file}" -X POST "${NACOS_API_URL}/v3/admin/cs/config" \
|
||||
-H "Authorization: Bearer ${access_token}" \
|
||||
--data-urlencode "dataId=${data_id}" \
|
||||
--data-urlencode "groupName=${EXPECTED_GROUP}" \
|
||||
--data-urlencode "namespaceId=${EXPECTED_NAMESPACE}" \
|
||||
--data-urlencode "type=yaml" \
|
||||
--data-urlencode 'content@-')"
|
||||
[[ "${http_status}" == "200" ]] || return 1
|
||||
|
||||
ruby -rjson -e '
|
||||
response=JSON.parse(File.binread(ARGV.fetch(0)))
|
||||
ok=response["code"] == 0 || response["data"] == true
|
||||
abort "publish rejected" unless ok
|
||||
' "${response_file}" >/dev/null 2>"${tmp_dir}/${safe_name}.publish.err"
|
||||
}
|
||||
|
||||
restore_snapshot() {
|
||||
validate_snapshot || return 1
|
||||
for config_file in "${CONFIG_FILES[@]}"; do
|
||||
if ! post_config "${config_file}" "${snapshot_dir}/${config_file}"; then
|
||||
return 1
|
||||
fi
|
||||
if ! fetch_config "${config_file}" "${tmp_dir}/${config_file}.restored"; then
|
||||
return 1
|
||||
fi
|
||||
cmp -s "${snapshot_dir}/${config_file}" "${tmp_dir}/${config_file}.restored" || return 1
|
||||
done
|
||||
}
|
||||
|
||||
case "${mode}" in
|
||||
snapshot)
|
||||
[[ ! -e "${snapshot_dir}" ]] || fail "snapshot directory already exists"
|
||||
snapshot_parent="$(dirname "${snapshot_dir}")"
|
||||
mkdir -p -m 700 "${snapshot_parent}"
|
||||
snapshot_tmp="$(mktemp -d "${snapshot_parent}/.nacos-snapshot.XXXXXX")"
|
||||
chmod 700 "${snapshot_tmp}"
|
||||
for config_file in "${CONFIG_FILES[@]}"; do
|
||||
fetch_config "${config_file}" "${snapshot_tmp}/${config_file}" || fail "snapshot GET failed for ${config_file}"
|
||||
chmod 600 "${snapshot_tmp}/${config_file}"
|
||||
done
|
||||
(
|
||||
cd "${snapshot_tmp}"
|
||||
shasum -a 256 "${CONFIG_FILES[@]}" >configs.sha256
|
||||
)
|
||||
printf '{"schemaVersion":1,"namespace":"%s","group":"%s","configCount":10}\n' \
|
||||
"${EXPECTED_NAMESPACE}" "${EXPECTED_GROUP}" >"${snapshot_tmp}/metadata.json"
|
||||
chmod 600 "${snapshot_tmp}/configs.sha256" "${snapshot_tmp}/metadata.json"
|
||||
mv "${snapshot_tmp}" "${snapshot_dir}"
|
||||
snapshot_tmp=""
|
||||
echo "Nacos snapshot completed: configs=10 content=SUPPRESSED"
|
||||
;;
|
||||
publish-source)
|
||||
validate_snapshot || fail "complete hashed Nacos snapshot is required before publish"
|
||||
publish_failed="false"
|
||||
for config_file in "${CONFIG_FILES[@]}"; do
|
||||
if ! post_config "${config_file}" "${source_dir}/${config_file}"; then
|
||||
publish_failed="true"
|
||||
break
|
||||
fi
|
||||
if ! fetch_config "${config_file}" "${tmp_dir}/${config_file}.published"; then
|
||||
publish_failed="true"
|
||||
break
|
||||
fi
|
||||
if ! cmp -s "${source_dir}/${config_file}" "${tmp_dir}/${config_file}.published"; then
|
||||
publish_failed="true"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [[ "${publish_failed}" == "true" ]]; then
|
||||
restore_snapshot || fail "publish failed and snapshot restore also failed; manual recovery required"
|
||||
fail "publish failed; complete snapshot was restored"
|
||||
fi
|
||||
echo "Nacos source publish completed: configs=10 readback=PASS content=SUPPRESSED"
|
||||
;;
|
||||
restore)
|
||||
restore_snapshot || fail "snapshot restore or readback failed"
|
||||
echo "Nacos snapshot restore completed: configs=10 readback=PASS content=SUPPRESSED"
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "fileutils"
|
||||
require "optparse"
|
||||
require_relative "release_manifest"
|
||||
|
||||
options = {
|
||||
project_root: File.expand_path("../../..", __dir__)
|
||||
}
|
||||
|
||||
OptionParser.new do |parser|
|
||||
parser.banner = "Usage: prepare-release.rb --release-id ID --output FILE [--project-root DIR]"
|
||||
parser.on("--release-id ID", "Immutable lowercase release ID") { |value| options[:release_id] = value }
|
||||
parser.on("--output FILE", "Release manifest output path") { |value| options[:output] = value }
|
||||
parser.on("--project-root DIR", "Project root, primarily for offline fixtures") { |value| options[:project_root] = value }
|
||||
end.parse!
|
||||
|
||||
abort "--release-id is required" unless options[:release_id]
|
||||
abort "--output is required" unless options[:output]
|
||||
|
||||
manifest = DataGovReleaseManifest.build(options[:project_root], options[:release_id])
|
||||
bytes = DataGovReleaseManifest.canonical_json(manifest)
|
||||
output = File.expand_path(options[:output])
|
||||
abort "release manifest output must not be a symlink" if File.symlink?(output)
|
||||
|
||||
if File.exist?(output)
|
||||
abort "release manifest already exists with different bytes" unless File.binread(output) == bytes
|
||||
|
||||
puts "Release manifest already identical: #{output}"
|
||||
exit 0
|
||||
end
|
||||
|
||||
FileUtils.mkdir_p(File.dirname(output), mode: 0o700)
|
||||
temporary = "#{output}.tmp.#{Process.pid}"
|
||||
begin
|
||||
File.open(temporary, File::WRONLY | File::CREAT | File::EXCL, 0o600) { |file| file.write(bytes) }
|
||||
File.rename(temporary, output)
|
||||
ensure
|
||||
FileUtils.rm_f(temporary)
|
||||
end
|
||||
|
||||
puts "Release manifest prepared: id=#{manifest.fetch("releaseId")} services=9 nacos=10 migrations=#{manifest.dig("migration", "count")}"
|
||||
@@ -0,0 +1,149 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "digest"
|
||||
require "json"
|
||||
require "yaml"
|
||||
|
||||
module DataGovReleaseManifest
|
||||
RELEASE_ID_PATTERN = /\A[a-z0-9][a-z0-9._-]{0,63}\z/.freeze
|
||||
RESERVED_RELEASE_IDS = %w[current development latest previous rollback].freeze
|
||||
|
||||
SERVICE_ARTIFACTS = [
|
||||
["gateway", "aixun-gateway/target/aixun-gateway.jar"],
|
||||
["auth", "aixun-auth/target/aixun-auth.jar"],
|
||||
["system", "aixun-modules/aixun-system/target/aixun-system.jar"],
|
||||
["resource", "aixun-modules/aixun-resource/target/aixun-resource.jar"],
|
||||
["integration", "aixun-modules/aixun-integration/target/aixun-integration.jar"],
|
||||
["dataops", "aixun-modules/aixun-dataops/target/aixun-dataops.jar"],
|
||||
["governance", "aixun-modules/aixun-governance/target/aixun-governance.jar"],
|
||||
["dataproduct", "aixun-modules/aixun-dataproduct/target/aixun-dataproduct.jar"]
|
||||
].freeze
|
||||
|
||||
NACOS_CONFIGS = %w[
|
||||
application-common.yml
|
||||
datasource.yml
|
||||
aixun-datagov-auth.yml
|
||||
aixun-datagov-gateway.yml
|
||||
aixun-datagov-resource.yml
|
||||
aixun-datagov-system.yml
|
||||
aixun-integration.yml
|
||||
aixun-dataops.yml
|
||||
aixun-governance.yml
|
||||
aixun-dataproduct.yml
|
||||
].freeze
|
||||
|
||||
module_function
|
||||
|
||||
def validate_release_id!(release_id)
|
||||
unless release_id.is_a?(String) && release_id.match?(RELEASE_ID_PATTERN)
|
||||
raise ArgumentError, "release ID must be 1-64 lowercase tag-safe characters"
|
||||
end
|
||||
if RESERVED_RELEASE_IDS.include?(release_id)
|
||||
raise ArgumentError, "reserved release ID is forbidden: #{release_id}"
|
||||
end
|
||||
release_id
|
||||
end
|
||||
|
||||
def file_sha256(project_root, relative_path)
|
||||
path = File.join(project_root, relative_path)
|
||||
raise ArgumentError, "required file is missing: #{relative_path}" unless File.file?(path)
|
||||
|
||||
Digest::SHA256.file(path).hexdigest
|
||||
end
|
||||
|
||||
def tree_summary(project_root, relative_directory)
|
||||
directory = File.join(project_root, relative_directory)
|
||||
raise ArgumentError, "required directory is missing: #{relative_directory}" unless File.directory?(directory)
|
||||
|
||||
records = Dir.glob(File.join(directory, "**", "*"), File::FNM_DOTMATCH)
|
||||
.select { |path| File.file?(path) }
|
||||
.map do |path|
|
||||
relative_path = path.delete_prefix(directory + File::SEPARATOR)
|
||||
[relative_path, Digest::SHA256.file(path).hexdigest]
|
||||
end
|
||||
.sort_by(&:first)
|
||||
raise ArgumentError, "required directory is empty: #{relative_directory}" if records.empty?
|
||||
|
||||
serialized = records.map { |path, sha| "#{path}\0#{sha}\n" }.join
|
||||
{
|
||||
"path" => relative_directory,
|
||||
"fileCount" => records.length,
|
||||
"treeSha256" => Digest::SHA256.hexdigest(serialized)
|
||||
}
|
||||
end
|
||||
|
||||
def migration_summary(project_root)
|
||||
relative_path = "db/migration/catalog.yml"
|
||||
catalog_path = File.join(project_root, relative_path)
|
||||
parsed = YAML.safe_load(File.binread(catalog_path))
|
||||
migrations = parsed.fetch("migrations")
|
||||
raise ArgumentError, "migration catalog must not be empty" if migrations.empty?
|
||||
|
||||
{
|
||||
"path" => relative_path,
|
||||
"sha256" => Digest::SHA256.file(catalog_path).hexdigest,
|
||||
"count" => migrations.length,
|
||||
"firstVersion" => migrations.first.fetch("version"),
|
||||
"lastVersion" => migrations.last.fetch("version")
|
||||
}
|
||||
rescue KeyError, Psych::Exception => error
|
||||
raise ArgumentError, "migration catalog is invalid: #{error.message}"
|
||||
end
|
||||
|
||||
def build(project_root, release_id)
|
||||
project_root = File.expand_path(project_root)
|
||||
validate_release_id!(release_id)
|
||||
|
||||
services = SERVICE_ARTIFACTS.map do |service, artifact|
|
||||
{
|
||||
"service" => service,
|
||||
"image" => "aixun-datagov/#{service}:#{release_id}",
|
||||
"artifact" => artifact,
|
||||
"artifactSha256" => file_sha256(project_root, artifact)
|
||||
}
|
||||
end
|
||||
|
||||
frontend = tree_summary(project_root, "aixun-ui/dist").merge(
|
||||
"service" => "frontend",
|
||||
"image" => "aixun-datagov/frontend:#{release_id}"
|
||||
)
|
||||
|
||||
nacos_configs = NACOS_CONFIGS.map do |data_id|
|
||||
relative_path = File.join("script/config/datagov/nacos", data_id)
|
||||
{
|
||||
"dataId" => data_id,
|
||||
"path" => relative_path,
|
||||
"sha256" => file_sha256(project_root, relative_path)
|
||||
}
|
||||
end
|
||||
|
||||
legal = %w[LICENSE THIRD_PARTY.md].map do |relative_path|
|
||||
{ "path" => relative_path, "sha256" => file_sha256(project_root, relative_path) }
|
||||
end
|
||||
|
||||
{
|
||||
"schemaVersion" => 1,
|
||||
"releaseId" => release_id,
|
||||
"composeProject" => "aixun-datagov-local",
|
||||
"services" => services,
|
||||
"frontend" => frontend,
|
||||
"migration" => migration_summary(project_root),
|
||||
"nacos" => {
|
||||
"namespace" => "aixun-datagov-local",
|
||||
"group" => "AIXUN_DATAGOV_GROUP",
|
||||
"configs" => nacos_configs
|
||||
},
|
||||
"legal" => legal,
|
||||
"rollbackPolicy" => {
|
||||
"database" => "SAME_CATALOG_ONLY_OR_FORWARD_COMPENSATION",
|
||||
"nacos" => "COMPLETE_HASHED_SNAPSHOT_REQUIRED",
|
||||
"frontend" => "PERSISTENT_HASH_ASSET_MERGE_NO_AUTOMATIC_DELETE"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def canonical_json(manifest)
|
||||
JSON.pretty_generate(manifest) + "\n"
|
||||
end
|
||||
end
|
||||
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
readonly PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../../.." && pwd)"
|
||||
readonly RELEASE_ID="r20260901-static"
|
||||
readonly CONFIG_FILES=(
|
||||
application-common.yml
|
||||
datasource.yml
|
||||
aixun-datagov-auth.yml
|
||||
aixun-datagov-gateway.yml
|
||||
aixun-datagov-resource.yml
|
||||
aixun-datagov-system.yml
|
||||
aixun-integration.yml
|
||||
aixun-dataops.yml
|
||||
aixun-governance.yml
|
||||
aixun-dataproduct.yml
|
||||
)
|
||||
|
||||
fail() {
|
||||
echo "Release tooling offline verification failed: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
expect_failure() {
|
||||
if "$@" >/dev/null 2>&1; then
|
||||
fail "command unexpectedly succeeded: $*"
|
||||
fi
|
||||
}
|
||||
|
||||
fixture_root="$(mktemp -d "${TMPDIR:-/tmp}/aixun-datagov-release-test.XXXXXX")"
|
||||
cleanup() {
|
||||
rm -rf -- "${fixture_root}"
|
||||
}
|
||||
trap cleanup EXIT HUP INT TERM
|
||||
|
||||
manifest_one="${fixture_root}/release-one.json"
|
||||
manifest_two="${fixture_root}/release-two.json"
|
||||
ruby "${SCRIPT_DIR}/prepare-release.rb" --project-root "${PROJECT_ROOT}" --release-id "${RELEASE_ID}" --output "${manifest_one}" >/dev/null
|
||||
ruby "${SCRIPT_DIR}/prepare-release.rb" --project-root "${PROJECT_ROOT}" --release-id "${RELEASE_ID}" --output "${manifest_two}" >/dev/null
|
||||
cmp -s "${manifest_one}" "${manifest_two}" || fail "deterministic manifests differ"
|
||||
ruby "${SCRIPT_DIR}/verify-release.rb" --project-root "${PROJECT_ROOT}" --manifest "${manifest_one}" >/dev/null
|
||||
ruby -rjson -e '
|
||||
value=JSON.parse(File.binread(ARGV.fetch(0)))
|
||||
abort "service count" unless value.fetch("services").length == 8
|
||||
abort "frontend missing" unless value.dig("frontend", "service") == "frontend"
|
||||
abort "Nacos count" unless value.dig("nacos", "configs").length == 10
|
||||
abort "migration count" unless value.dig("migration", "count") == 112
|
||||
abort "legal count" unless value.fetch("legal").length == 2
|
||||
' "${manifest_one}"
|
||||
|
||||
tampered_manifest="${fixture_root}/release-tampered.json"
|
||||
ruby -rjson -e '
|
||||
value=JSON.parse(File.binread(ARGV.fetch(0)))
|
||||
value.fetch("services").first["artifactSha256"]="0" * 64
|
||||
File.binwrite(ARGV.fetch(1), JSON.pretty_generate(value) + "\n")
|
||||
' "${manifest_one}" "${tampered_manifest}"
|
||||
expect_failure ruby "${SCRIPT_DIR}/verify-release.rb" --project-root "${PROJECT_ROOT}" --manifest "${tampered_manifest}"
|
||||
for invalid_id in latest development UPPER ../bad; do
|
||||
expect_failure ruby "${SCRIPT_DIR}/prepare-release.rb" --project-root "${PROJECT_ROOT}" --release-id "${invalid_id}" --output "${fixture_root}/${invalid_id//\//_}.json"
|
||||
done
|
||||
|
||||
snapshot_dir="${fixture_root}/snapshot"
|
||||
mkdir -m 700 "${snapshot_dir}"
|
||||
for config_file in "${CONFIG_FILES[@]}"; do
|
||||
printf 'fixtureConfig: %s\n' "${config_file}" >"${snapshot_dir}/${config_file}"
|
||||
chmod 600 "${snapshot_dir}/${config_file}"
|
||||
done
|
||||
(
|
||||
cd "${snapshot_dir}"
|
||||
shasum -a 256 "${CONFIG_FILES[@]}" >configs.sha256
|
||||
)
|
||||
printf '%s\n' '{"schemaVersion":1,"namespace":"aixun-datagov-local","group":"AIXUN_DATAGOV_GROUP","configCount":10}' >"${snapshot_dir}/metadata.json"
|
||||
chmod 600 "${snapshot_dir}/configs.sha256" "${snapshot_dir}/metadata.json"
|
||||
|
||||
"${SCRIPT_DIR}/nacos-config-release.sh" snapshot --snapshot-dir "${fixture_root}/future-snapshot" --dry-run >/dev/null
|
||||
"${SCRIPT_DIR}/nacos-config-release.sh" snapshot --snapshot-dir "${fixture_root}/future-container-snapshot" --transport container --dry-run >/dev/null
|
||||
"${SCRIPT_DIR}/nacos-config-release.sh" publish-source --snapshot-dir "${snapshot_dir}" --source-dir "${PROJECT_ROOT}/script/config/datagov/nacos" --dry-run >/dev/null
|
||||
"${SCRIPT_DIR}/nacos-config-release.sh" publish-source --snapshot-dir "${snapshot_dir}" --transport host --source-dir "${PROJECT_ROOT}/script/config/datagov/nacos" --dry-run >/dev/null
|
||||
"${SCRIPT_DIR}/nacos-config-release.sh" restore --snapshot-dir "${snapshot_dir}" --dry-run >/dev/null
|
||||
expect_failure "${SCRIPT_DIR}/nacos-config-release.sh" restore --snapshot-dir "${snapshot_dir}" --transport invalid --dry-run
|
||||
cp -R "${snapshot_dir}" "${fixture_root}/invalid-snapshot"
|
||||
printf 'tampered\n' >>"${fixture_root}/invalid-snapshot/application-common.yml"
|
||||
expect_failure "${SCRIPT_DIR}/nacos-config-release.sh" restore --snapshot-dir "${fixture_root}/invalid-snapshot" --dry-run
|
||||
|
||||
mock_bin="${fixture_root}/mock-bin"
|
||||
mkdir -m 700 "${mock_bin}"
|
||||
printf '%s\n' '#!/usr/bin/env bash' 'case "$*" in *State.Running*) printf "true\\n";; *com.docker.compose.project*) printf "wrong-project\\n";; *com.aixun.project*) printf "wrong-owner\\n";; *) exit 1;; esac' >"${mock_bin}/docker"
|
||||
chmod 700 "${mock_bin}/docker"
|
||||
bad_env="${fixture_root}/bad.env"
|
||||
printf '%s\n' 'AIXUN_DATAGOV_NACOS_NAMESPACE=aixun-datagov-local' 'AIXUN_DATAGOV_NACOS_GROUP=AIXUN_DATAGOV_GROUP' 'AIXUN_DATAGOV_NACOS_CLIENT_PORT=28848' 'AIXUN_DATAGOV_NACOS_USERNAME=test-user' 'AIXUN_DATAGOV_NACOS_PASSWORD=test-password' >"${bad_env}"
|
||||
chmod 600 "${bad_env}"
|
||||
expect_failure env PATH="${mock_bin}:${PATH}" "${SCRIPT_DIR}/nacos-config-release.sh" restore --snapshot-dir "${snapshot_dir}" --env-file "${bad_env}" --transport container --execute
|
||||
|
||||
frontend_source_one="${fixture_root}/frontend-one"
|
||||
frontend_source_two="${fixture_root}/frontend-two"
|
||||
frontend_source_collision="${fixture_root}/frontend-collision"
|
||||
frontend_target="${fixture_root}/frontend-target"
|
||||
mkdir -p \
|
||||
"${frontend_source_one}/assets" \
|
||||
"${frontend_source_two}/assets" \
|
||||
"${frontend_source_collision}/assets" \
|
||||
"${frontend_target}"
|
||||
printf '%s\n' '<html>old</html>' >"${frontend_source_one}/index.html"
|
||||
printf '%s\n' 'old-gzip-entry' >"${frontend_source_one}/index.html.gz"
|
||||
printf '%s\n' 'old-brotli-entry' >"${frontend_source_one}/index.html.br"
|
||||
printf '%s\n' 'old-hash' >"${frontend_source_one}/assets/old-hash.js"
|
||||
printf '%s\n' 'stable-hash' >"${frontend_source_one}/assets/stable-hash.js"
|
||||
printf '%s\n' '<html>new</html>' >"${frontend_source_two}/index.html"
|
||||
printf '%s\n' 'new-gzip-entry' >"${frontend_source_two}/index.html.gz"
|
||||
printf '%s\n' 'new-hash' >"${frontend_source_two}/assets/new-hash.js"
|
||||
printf '%s\n' 'stable-hash' >"${frontend_source_two}/assets/stable-hash.js"
|
||||
AIXUN_DATAGOV_RELEASE_ID=r20260901-old \
|
||||
AIXUN_DATAGOV_FRONTEND_SOURCE="${frontend_source_one}" \
|
||||
AIXUN_DATAGOV_FRONTEND_TARGET="${frontend_target}" \
|
||||
"${PROJECT_ROOT}/script/datagov/docker/prepare-frontend-assets.sh" >/dev/null
|
||||
AIXUN_DATAGOV_RELEASE_ID=r20260901-new \
|
||||
AIXUN_DATAGOV_FRONTEND_SOURCE="${frontend_source_two}" \
|
||||
AIXUN_DATAGOV_FRONTEND_TARGET="${frontend_target}" \
|
||||
"${PROJECT_ROOT}/script/datagov/docker/prepare-frontend-assets.sh" >/dev/null
|
||||
cmp -s "${frontend_source_two}/index.html" "${frontend_target}/index.html" || fail "new index was not activated"
|
||||
cmp -s "${frontend_source_two}/index.html.gz" "${frontend_target}/index.html.gz" || fail "new gzip index was not activated"
|
||||
[[ ! -e "${frontend_target}/index.html.br" ]] || fail "obsolete brotli index was not removed"
|
||||
cmp -s "${frontend_source_one}/assets/old-hash.js" "${frontend_target}/assets/old-hash.js" || fail "old hash asset was removed"
|
||||
cmp -s "${frontend_source_two}/assets/new-hash.js" "${frontend_target}/assets/new-hash.js" || fail "new hash asset is missing"
|
||||
cmp -s "${frontend_source_two}/assets/stable-hash.js" "${frontend_target}/assets/stable-hash.js" || fail "same-byte hash asset was rejected"
|
||||
|
||||
AIXUN_DATAGOV_RELEASE_ID=r20260901-new-repeat \
|
||||
AIXUN_DATAGOV_FRONTEND_SOURCE="${frontend_source_two}" \
|
||||
AIXUN_DATAGOV_FRONTEND_TARGET="${frontend_target}" \
|
||||
"${PROJECT_ROOT}/script/datagov/docker/prepare-frontend-assets.sh" >/dev/null
|
||||
|
||||
cp "${frontend_source_two}/index.html" "${frontend_source_collision}/index.html"
|
||||
cp "${frontend_source_two}/index.html.gz" "${frontend_source_collision}/index.html.gz"
|
||||
printf '%s\n' 'changed-hash' >"${frontend_source_collision}/assets/stable-hash.js"
|
||||
expect_failure env \
|
||||
AIXUN_DATAGOV_RELEASE_ID=r20260901-collision \
|
||||
AIXUN_DATAGOV_FRONTEND_SOURCE="${frontend_source_collision}" \
|
||||
AIXUN_DATAGOV_FRONTEND_TARGET="${frontend_target}" \
|
||||
"${PROJECT_ROOT}/script/datagov/docker/prepare-frontend-assets.sh"
|
||||
cmp -s "${frontend_source_two}/index.html" "${frontend_target}/index.html" || fail "hash collision changed the active index"
|
||||
|
||||
ln -s "${frontend_source_two}/assets/new-hash.js" "${frontend_source_collision}/assets/symlink.js"
|
||||
expect_failure env \
|
||||
AIXUN_DATAGOV_RELEASE_ID=r20260901-symlink \
|
||||
AIXUN_DATAGOV_FRONTEND_SOURCE="${frontend_source_collision}" \
|
||||
AIXUN_DATAGOV_FRONTEND_TARGET="${frontend_target}" \
|
||||
"${PROJECT_ROOT}/script/datagov/docker/prepare-frontend-assets.sh"
|
||||
expect_failure env \
|
||||
AIXUN_DATAGOV_RELEASE_ID=latest \
|
||||
AIXUN_DATAGOV_FRONTEND_SOURCE="${frontend_source_two}" \
|
||||
AIXUN_DATAGOV_FRONTEND_TARGET="${frontend_target}" \
|
||||
"${PROJECT_ROOT}/script/datagov/docker/prepare-frontend-assets.sh"
|
||||
|
||||
compose_file="${PROJECT_ROOT}/script/datagov/docker-compose.local.yml"
|
||||
[[ "$(grep -Ec '^ image: aixun-datagov/(gateway|auth|system|resource|integration|dataops|governance|dataproduct|frontend):\$\{AIXUN_DATAGOV_RELEASE_ID:-[0-9.]+\}$' "${compose_file}")" == "9" ]] || fail "Compose release-tag coverage is not 9/9"
|
||||
[[ "$(grep -Fc 'RELEASE_ID: ${AIXUN_DATAGOV_RELEASE_ID:-local-development}' "${compose_file}")" == "9" ]] || fail "Compose build-arg coverage is not 9/9"
|
||||
grep -Fq -- '- frontend-assets:/usr/share/nginx/html' "${compose_file}" || fail "frontend persistent asset volume is missing"
|
||||
grep -Fq 'name: aixun-datagov-local-frontend-assets' "${compose_file}" || fail "frontend volume name is not isolated"
|
||||
|
||||
nginx_file="${PROJECT_ROOT}/script/datagov/nginx/default.conf"
|
||||
grep -Fq 'location = /index.html' "${nginx_file}" || fail "index cache location is missing"
|
||||
grep -Fq 'Cache-Control "no-store, no-cache, must-revalidate"' "${nginx_file}" || fail "index no-store policy is missing"
|
||||
grep -Fq 'location /assets/' "${nginx_file}" || fail "hashed asset cache location is missing"
|
||||
grep -Fq 'Cache-Control "public, max-age=604800, immutable"' "${nginx_file}" || fail "immutable asset cache policy is missing"
|
||||
|
||||
echo "Release tooling offline verification passed: manifest=PASS nacos-dry-run=PASS frontend-entry-family=PASS old-new-hash-retention=PASS immutable-collision=PASS symlink=PASS release-id=PASS compose=9/9"
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "json"
|
||||
require "optparse"
|
||||
require_relative "release_manifest"
|
||||
|
||||
options = {
|
||||
project_root: File.expand_path("../../..", __dir__)
|
||||
}
|
||||
|
||||
OptionParser.new do |parser|
|
||||
parser.banner = "Usage: verify-release.rb --manifest FILE [--project-root DIR]"
|
||||
parser.on("--manifest FILE", "Release manifest to verify") { |value| options[:manifest] = value }
|
||||
parser.on("--project-root DIR", "Project root, primarily for offline fixtures") { |value| options[:project_root] = value }
|
||||
end.parse!
|
||||
|
||||
abort "--manifest is required" unless options[:manifest]
|
||||
abort "release manifest must be a regular file" unless File.file?(options[:manifest])
|
||||
|
||||
actual = JSON.parse(File.binread(options[:manifest]))
|
||||
release_id = actual.fetch("releaseId")
|
||||
expected = DataGovReleaseManifest.build(options[:project_root], release_id)
|
||||
|
||||
unless actual == expected
|
||||
changed_sections = (actual.keys | expected.keys).select { |key| actual[key] != expected[key] }
|
||||
abort "release manifest verification failed; changed sections: #{changed_sections.sort.join(",")}"
|
||||
end
|
||||
|
||||
puts "Release manifest verified: id=#{release_id} services=9 nacos=10 migrations=#{actual.dig("migration", "count")}"
|
||||
|
||||
在新工单中引用
屏蔽一个用户