Files
edgeever/apps/api/src/instance-deployment.test.mjs
T
Dariusz Korytoandtianma-if df22f55d1c feat(docker): report image build metadata in System information (#602)
Docker instances reported most deployment fields as unknown. Report how
and when the container image was built, separately from how the
instance was deployed:

- Dockerfile: optional EDGE_EVER_BUILD_CREATED_AT, EDGE_EVER_BUILD_TRIGGER
  and EDGE_EVER_BUILD_METHOD build args, empty by default.
- /api/health (self-hosted-bun only): optional buildCreatedAt and
  buildProvenance. deploymentVersionCreatedAt and deployment keep their
  meaning and stay runtime-supplied; Cloudflare responses are unchanged.
- docker-image.yml: official images record the build time and their
  provenance. Draft-release builds dispatched with release_tag are
  github_release, main pushes main_push, other dispatches manual.
  The container test checks the health response for a metadata build
  with runtime overrides and for a default self-build; the post-publish
  audit checks the published image.
- Add an explicit `docker` deployment method. It is never inferred from
  the runtime, and the registry source still comes only from
  EDGE_EVER_CONTAINER_IMAGE.
- Web/desktop show "Image built at" and "Image build source" for Docker;
  Android shows "Image built at". Older clients ignore the new fields.
- Document the build args and runtime variables in both Docker guides.

Co-authored-by: tianma-if <yingwaizhiying@gmail.com>
2026-10-18 11:43:41 +08:00

36 lines
1.9 KiB
JavaScript

import { expect, test } from "bun:test";
import { resolveDeploymentVersionCreatedAt, resolveImageBuildMetadata, resolveInstanceDeploymentMetadata } from "./instance-deployment";
test("normalizes a runtime-supplied deployment version timestamp and rejects missing or invalid values", () => {
expect(resolveDeploymentVersionCreatedAt({ deploymentVersionCreatedAt: "2026-10-02T08:00:00+08:00" }))
.toBe("2026-10-02T00:00:00.000Z");
expect(resolveDeploymentVersionCreatedAt({})).toBeNull();
expect(resolveDeploymentVersionCreatedAt({ deploymentVersionCreatedAt: "unknown" })).toBeNull();
});
test("reports image build metadata only from valid build arguments", () => {
expect(resolveImageBuildMetadata({
EDGE_EVER_BUILD_CREATED_AT: " 2026-01-02T03:04:05Z ",
EDGE_EVER_BUILD_TRIGGER: "github_release",
EDGE_EVER_BUILD_METHOD: "github_actions",
})).toEqual({
buildCreatedAt: "2026-01-02T03:04:05.000Z",
buildProvenance: { trigger: "github_release", method: "github_actions" },
});
// A default self-build passes empty build arguments.
expect(resolveImageBuildMetadata({ EDGE_EVER_BUILD_CREATED_AT: "", EDGE_EVER_BUILD_TRIGGER: "", EDGE_EVER_BUILD_METHOD: "" })).toEqual({
buildCreatedAt: null,
buildProvenance: { trigger: "unknown", method: "unknown" },
});
expect(resolveImageBuildMetadata({ EDGE_EVER_BUILD_CREATED_AT: "yesterday", EDGE_EVER_BUILD_TRIGGER: "nightly", EDGE_EVER_BUILD_METHOD: "kubernetes" })).toEqual({
buildCreatedAt: null,
buildProvenance: { trigger: "unknown", method: "unknown" },
});
});
test("accepts docker as an explicit deployment method without inferring it", () => {
expect(resolveInstanceDeploymentMetadata({ EDGE_EVER_DEPLOYMENT_TRIGGER: "manual", EDGE_EVER_DEPLOYMENT_METHOD: "docker" }))
.toEqual({ trigger: "manual", method: "docker" });
expect(resolveInstanceDeploymentMetadata({})).toEqual({ trigger: "unknown", method: "unknown" });
});