fix(telemetry): service.version reports the release, not the crate version (#883)
CI / Agent integration (push) Skipped
CI / Check (push) Skipped
CI / Detect Changes (push) Successful in 6s
CI / Deploy Docs (push) Skipped
CI / Deploy MCP (push) Successful in 4m40s
CI / Deploy Dashboard (push) Successful in 6m12s
CI / Deploy Agent (push) Successful in 8m36s
CI / Agent integration (push) Skipped
CI / Check (push) Skipped
CI / Detect Changes (push) Successful in 6s
CI / Deploy Docs (push) Skipped
CI / Deploy MCP (push) Successful in 4m40s
CI / Deploy Dashboard (push) Successful in 6m12s
CI / Deploy Agent (push) Successful in 8m36s
This commit was merged in pull request #883.
This commit is contained in:
1 parent
13d09dc830
commit
2157ae2d42
6 files changed
+55
-32
No files matched your search
@@ -374,9 +374,16 @@ 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
|
||||
# service.version in telemetry: the latest release tag without its v,
|
||||
# as for the agent. No tag → empty, and the crate version is used.
|
||||
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}"
|
||||
IMAGE=repo.breakpilot.com/pruefwerk/compliance-dashboard
|
||||
echo "$REGISTRY_PASSWORD" | docker login repo.breakpilot.com -u "$REGISTRY_USERNAME" --password-stdin
|
||||
DOCKER_BUILDKIT=1 docker build --pull --secret id=git_token,env=PLATFORM_CI_TOKEN \
|
||||
--build-arg PRUEFWERK_VERSION="${PRUEFWERK_VERSION}" \
|
||||
-f Dockerfile.dashboard -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,6 +5,9 @@ RUN cargo install dioxus-cli --version 0.7.3 --locked
|
||||
# Legal pages linked from the sidebar; the defaults are breakpilot.com's.
|
||||
ARG IMPRINT_URL=https://breakpilot.com/impressum
|
||||
ARG PRIVACY_URL=https://breakpilot.com/datenschutz
|
||||
# The release telemetry reports as service.version (CI passes the latest
|
||||
# release tag); empty falls back to the crate version.
|
||||
ARG PRUEFWERK_VERSION=
|
||||
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
|
||||
@@ -18,6 +18,8 @@ use mongodb::bson::{doc, Document};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use compliance_core::auth::{validate_service_token, JwksState};
|
||||
// Re-exported: the VEX, evidence and change-detection code import them from here.
|
||||
pub use compliance_core::build_info::{BUILD_COMMIT, BUILD_VERSION};
|
||||
|
||||
use crate::agent::ComplianceAgent;
|
||||
|
||||
@@ -432,23 +434,6 @@ 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!({
|
||||
@@ -807,20 +792,6 @@ pub async fn delete_git_source(
|
||||
})))
|
||||
}
|
||||
|
||||
#[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());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod target_count_tests {
|
||||
use super::*;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
//! The release a binary was built as, read at compile time.
|
||||
//!
|
||||
//! CI passes the latest release tag (without its `v`) as `PRUEFWERK_VERSION`
|
||||
//! and the commit as `PRUEFWERK_COMMIT` to the image build. The crate version
|
||||
//! is only the fallback for a local build: it is not bumped per release, so
|
||||
//! anything that names the running version (the agent's `/version` handshake,
|
||||
//! telemetry's `service.version`, evidence tooling) uses these constants.
|
||||
|
||||
/// The build version: `PRUEFWERK_VERSION` at compile time, 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,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod 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());
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod build_info;
|
||||
pub mod config;
|
||||
pub mod control_check;
|
||||
pub mod csaf_docs;
|
||||
|
||||
@@ -55,7 +55,10 @@ fn build_resource(service_name: &str) -> Resource {
|
||||
let name = std::env::var("OTEL_SERVICE_NAME").unwrap_or_else(|_| service_name.to_string());
|
||||
Resource::builder()
|
||||
.with_service_name(name)
|
||||
.with_attributes([KeyValue::new("service.version", env!("CARGO_PKG_VERSION"))])
|
||||
.with_attributes([KeyValue::new(
|
||||
"service.version",
|
||||
crate::build_info::BUILD_VERSION,
|
||||
)])
|
||||
.build()
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user