mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 09:20:22 +08:00
fix: propagate build version through local deploy
This commit is contained in:
@@ -20,6 +20,12 @@ pub(crate) fn mount_core_routes(router: Router<AppState>) -> Router<AppState> {
|
||||
.route("/_gateway/health", get(health))
|
||||
}
|
||||
|
||||
fn current_gateway_version() -> &'static str {
|
||||
option_env!("AETHER_BUILD_VERSION")
|
||||
.filter(|version| !version.is_empty())
|
||||
.unwrap_or(env!("CARGO_PKG_VERSION"))
|
||||
}
|
||||
|
||||
pub(crate) async fn health(State(state): State<AppState>) -> impl IntoResponse {
|
||||
let request_concurrency = state.request_concurrency_snapshot().map(|snapshot| {
|
||||
json!({
|
||||
@@ -78,7 +84,7 @@ pub(crate) async fn frontdoor_manifest(State(state): State<AppState>) -> impl In
|
||||
Json(json!({
|
||||
"component": "aether-gateway",
|
||||
"manifest_version": FRONTDOOR_MANIFEST_VERSION,
|
||||
"version": env!("CARGO_PKG_VERSION"),
|
||||
"version": current_gateway_version(),
|
||||
"mode": "compatibility_frontdoor",
|
||||
"entrypoints": {
|
||||
"public_manifest": FRONTDOOR_MANIFEST_PATH,
|
||||
|
||||
@@ -24,6 +24,42 @@ fn admin_system_build_version_contract_uses_explicit_local_build_arg() {
|
||||
"Dockerfile.app.local should pass explicit build version pattern {pattern}"
|
||||
);
|
||||
}
|
||||
|
||||
let deploy = read_workspace_file("deploy.sh");
|
||||
for pattern in [
|
||||
"detect_build_version()",
|
||||
"git describe --tags --always --dirty",
|
||||
"AETHER_BUILD_VERSION=\"${AETHER_BUILD_VERSION:-$(detect_build_version)}\"",
|
||||
"--build-arg \"AETHER_BUILD_VERSION=$AETHER_BUILD_VERSION\"",
|
||||
">>> AETHER_BUILD_VERSION",
|
||||
] {
|
||||
assert!(
|
||||
deploy.contains(pattern),
|
||||
"deploy.sh should pass deterministic local build version pattern {pattern}"
|
||||
);
|
||||
}
|
||||
|
||||
let vite_config = read_workspace_file("frontend/vite.config.ts");
|
||||
for pattern in [
|
||||
"process.env.AETHER_BUILD_VERSION",
|
||||
"process.env.AETHER_VERSION",
|
||||
] {
|
||||
assert!(
|
||||
vite_config.contains(pattern),
|
||||
"frontend/vite.config.ts should consume local build version pattern {pattern}"
|
||||
);
|
||||
}
|
||||
|
||||
let core_api = read_workspace_file("apps/aether-gateway/src/api/core.rs");
|
||||
for pattern in [
|
||||
"option_env!(\"AETHER_BUILD_VERSION\")",
|
||||
"\"version\": current_gateway_version()",
|
||||
] {
|
||||
assert!(
|
||||
core_api.contains(pattern),
|
||||
"api/core.rs should expose build version pattern {pattern}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
28
deploy.sh
28
deploy.sh
@@ -11,6 +11,23 @@ cd "$(dirname "$0")"
|
||||
LOCAL_APP_IMAGE="${LOCAL_APP_IMAGE:-aether-app:latest}"
|
||||
export LOCAL_APP_IMAGE
|
||||
|
||||
detect_build_version() {
|
||||
if command -v git >/dev/null 2>&1; then
|
||||
local version
|
||||
if version=$(git describe --tags --always --dirty 2>/dev/null); then
|
||||
if [ -n "$version" ]; then
|
||||
printf '%s\n' "$version"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
printf 'local-%s\n' "$(date -u +%Y%m%d%H%M%S)"
|
||||
}
|
||||
|
||||
AETHER_BUILD_VERSION="${AETHER_BUILD_VERSION:-$(detect_build_version)}"
|
||||
export AETHER_BUILD_VERSION
|
||||
|
||||
# 兼容 docker-compose 和 docker compose
|
||||
if command -v docker-compose &> /dev/null; then
|
||||
DC=(docker-compose -f docker-compose.yml -f docker-compose.local.yml)
|
||||
@@ -41,6 +58,7 @@ Options:
|
||||
|
||||
Environment:
|
||||
LOCAL_APP_IMAGE 本地构建镜像名,默认 aether-app:latest
|
||||
AETHER_BUILD_VERSION 应用显示版本,默认 git describe --tags --always --dirty
|
||||
EOF
|
||||
}
|
||||
|
||||
@@ -103,6 +121,8 @@ emit_tree_for_hash() {
|
||||
# 计算代码文件的哈希值
|
||||
calc_code_hash() {
|
||||
{
|
||||
printf '\n>>> AETHER_BUILD_VERSION\n%s\n' "$AETHER_BUILD_VERSION"
|
||||
|
||||
for file in \
|
||||
Dockerfile.app.local \
|
||||
docker-compose.yml \
|
||||
@@ -149,7 +169,13 @@ save_code_hash() { calc_code_hash > "$CODE_HASH_FILE"; }
|
||||
build_app() {
|
||||
require_file Dockerfile.app.local
|
||||
echo ">>> Building app image: $LOCAL_APP_IMAGE"
|
||||
DOCKER_BUILDKIT="${DOCKER_BUILDKIT:-1}" docker build --pull=false -f Dockerfile.app.local -t "$LOCAL_APP_IMAGE" .
|
||||
echo ">>> Build version: $AETHER_BUILD_VERSION"
|
||||
DOCKER_BUILDKIT="${DOCKER_BUILDKIT:-1}" docker build \
|
||||
--pull=false \
|
||||
--build-arg "AETHER_BUILD_VERSION=$AETHER_BUILD_VERSION" \
|
||||
-f Dockerfile.app.local \
|
||||
-t "$LOCAL_APP_IMAGE" \
|
||||
.
|
||||
save_code_hash
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,19 @@ import vue from '@vitejs/plugin-vue'
|
||||
import path from 'path'
|
||||
import { execSync } from 'child_process'
|
||||
|
||||
function normalizeVersion(version: string): string {
|
||||
const trimmed = version.trim()
|
||||
return trimmed.startsWith('v') || trimmed.startsWith('V') ? trimmed.slice(1) : trimmed
|
||||
}
|
||||
|
||||
function getGitVersion(): string {
|
||||
const envVersion = process.env.AETHER_BUILD_VERSION || process.env.AETHER_VERSION
|
||||
if (envVersion?.trim()) {
|
||||
return normalizeVersion(envVersion)
|
||||
}
|
||||
|
||||
try {
|
||||
return execSync('git describe --tags --always').toString().trim()
|
||||
return normalizeVersion(execSync('git describe --tags --always --dirty').toString())
|
||||
} catch {
|
||||
return '0.0.0.dev0'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user