feat(platform): build commit in the version handshake #470

Merged
sharang merged 1 commits from feat/version-commit into main 2026-10-05 22:20:18 +00:00
3 changed files with 47 additions and 1 deletions

No files matched your search

+9
View File
@@ -227,9 +227,18 @@ jobs:
apk add --no-cache git curl openssl
git init && git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
git fetch --depth=1 origin "${GITHUB_SHA}" && git checkout FETCH_HEAD
# GET /api/v1/platform/version: the latest release tag without its v
# (the checkout is shallow, so fetch the history and tags first) and
# the commit. No tag → empty, and the agent reports its crate version.
git fetch --quiet --unshallow --tags origin || true
TAG=$(git describe --tags --abbrev=0 --match 'v[0-9]*' 2>/dev/null || true)
PRUEFWERK_VERSION="${TAG#v}"
echo "version: ${PRUEFWERK_VERSION:-crate} commit: ${GITHUB_SHA}"
IMAGE=repo.breakpilot.com/pruefwerk/compliance-agent
echo "$REGISTRY_PASSWORD" | docker login repo.breakpilot.com -u "$REGISTRY_USERNAME" --password-stdin
DOCKER_BUILDKIT=1 docker build --secret id=git_token,env=PLATFORM_CI_TOKEN \
--build-arg PRUEFWERK_VERSION="${PRUEFWERK_VERSION}" \
--build-arg PRUEFWERK_COMMIT="${GITHUB_SHA}" \
-f Dockerfile.agent -t "$IMAGE:latest" -t "$IMAGE:${GITHUB_SHA}" .
docker push "$IMAGE:latest" && docker push "$IMAGE:${GITHUB_SHA}"
{ command -v cosign >/dev/null 2>&1 || curl -sSfLo /usr/local/bin/cosign https://github.com/sigstore/cosign/releases/download/v2.4.3/cosign-linux-amd64 || wget -qO /usr/local/bin/cosign https://github.com/sigstore/cosign/releases/download/v2.4.3/cosign-linux-amd64; } || echo "::warning::cosign fetch failed"
+5
View File
@@ -17,6 +17,11 @@ FROM rust:1.94-bookworm AS builder
WORKDIR /app
COPY . .
# The version and commit GET /api/v1/platform/version reports (CI passes the
# latest release tag and the commit); the agent reads them at compile time and
# falls back to the crate version and "unknown" when they are empty.
ARG PRUEFWERK_VERSION=
ARG PRUEFWERK_COMMIT=
# compliance-agent depends on the private firmwerk git repo (platform/firmwerk). Authenticate
# the fetch with a PAT passed as a BuildKit secret (never baked into a layer).
# Build with: DOCKER_BUILDKIT=1 docker build --secret id=git_token,env=PLATFORM_CI_TOKEN ...
+33 -1
View File
@@ -432,11 +432,29 @@ pub async fn usage(
}))
}
/// The build version: `PRUEFWERK_VERSION` at compile time (CI: the latest
/// release tag without its `v`), else the crate version.
pub const BUILD_VERSION: &str =
non_empty_or(option_env!("PRUEFWERK_VERSION"), env!("CARGO_PKG_VERSION"));
/// The commit the build is from: `PRUEFWERK_COMMIT` at compile time (CI:
/// the full SHA), else "unknown". The portal's version line shows 8 characters.
pub const BUILD_COMMIT: &str = non_empty_or(option_env!("PRUEFWERK_COMMIT"), "unknown");
/// A Docker build arg left empty is an empty env var, not an unset one.
const fn non_empty_or(value: Option<&'static str>, fallback: &'static str) -> &'static str {
match value {
Some(v) if !v.is_empty() => v,
_ => fallback,
}
}
/// `GET /api/v1/platform/version` — contract handshake (§4.1 /version).
pub async fn version(State(st): State<PlatformState>) -> Json<serde_json::Value> {
Json(serde_json::json!({
"product": st.agent.config.product_key,
"version": env!("CARGO_PKG_VERSION"),
"version": BUILD_VERSION,
"commit": BUILD_COMMIT,
"contract": "2.0",
// Deployment feature flags (PW_FEATURES). The dashboard reads the same
// set the agent enforces instead of carrying its own copy of the env.
@@ -750,3 +768,17 @@ pub async fn delete_git_source(
"targets_archived": archived,
})))
}
#[cfg(test)]
mod build_info_tests {
use super::*;
#[test]
fn an_unset_or_empty_build_value_falls_back() {
assert_eq!(non_empty_or(None, "0.4.4"), "0.4.4");
assert_eq!(non_empty_or(Some(""), "unknown"), "unknown");
assert_eq!(non_empty_or(Some("0.4.5"), "0.4.4"), "0.4.5");
assert!(!BUILD_VERSION.is_empty());
assert!(!BUILD_COMMIT.is_empty());
}
}