feat: expose runtime build version
This commit is contained in:
+20
-4
@@ -1,18 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
root="/home/zheromiku/dobotai-platform"
|
||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
root="${DOBOTAI_SOURCE_ROOT:-$(cd "$script_dir/.." && pwd)}"
|
||||
go_bin="${GO_BIN:-/home/zheromiku/.local/share/go1.26.5/bin/go}"
|
||||
bin_dir="$root/bin"
|
||||
current="$bin_dir/dobotai"
|
||||
next="$bin_dir/dobotai.new"
|
||||
previous="$bin_dir/dobotai.prev"
|
||||
service="dobotai.service"
|
||||
version_url="http://127.0.0.1:8090/version"
|
||||
|
||||
if [[ -n "$(git -C "$root" status --porcelain)" ]]; then
|
||||
echo "DobotAI source worktree is dirty; refusing unverifiable build" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
commit_sha="$(git -C "$root" rev-parse HEAD)"
|
||||
version="${DOBOTAI_VERSION:-dev}"
|
||||
build_time="$(date -u '+%Y-%m-%dT%H:%M:%SZ')"
|
||||
ldflags="-X main.version=$version -X main.commitSHA=$commit_sha -X main.buildTime=$build_time"
|
||||
|
||||
mkdir -p "$bin_dir"
|
||||
cd "$root"
|
||||
|
||||
"$go_bin" build -trimpath -o "$next" ./cmd/dobotai
|
||||
"$go_bin" build -trimpath -ldflags "$ldflags" -o "$next" ./cmd/dobotai
|
||||
chmod 0755 "$next"
|
||||
|
||||
if [[ -f "$current" ]]; then
|
||||
@@ -24,8 +36,12 @@ systemctl --user restart "$service"
|
||||
|
||||
for _ in $(seq 1 30); do
|
||||
if curl --noproxy '*' --fail --silent --max-time 2 http://127.0.0.1:8090/healthz >/dev/null; then
|
||||
echo "DOBOTAI_DEPLOY_OK"
|
||||
exit 0
|
||||
deployed_sha="$(curl --noproxy '*' --fail --silent --max-time 2 "$version_url" | python3 -c 'import json,sys; print(json.load(sys.stdin).get("commit_sha", ""))' 2>/dev/null || true)"
|
||||
if [[ "$deployed_sha" == "$commit_sha" ]]; then
|
||||
echo "DOBOTAI_DEPLOY_OK"
|
||||
echo "DOBOTAI_COMMIT_SHA=$commit_sha"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user