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>
53 lines
2.2 KiB
TypeScript
53 lines
2.2 KiB
TypeScript
import {
|
|
resolveDeploymentMethod,
|
|
resolveDeploymentTrigger,
|
|
type DeploymentMetadata,
|
|
} from "@edgeever/shared/deployment-metadata";
|
|
import type { Bindings } from "./api-context";
|
|
|
|
declare const __EDGEEVER_INSTANCE_DEPLOYMENT_TRIGGER__: string;
|
|
declare const __EDGEEVER_INSTANCE_DEPLOYMENT_METHOD__: string;
|
|
|
|
const bundledTrigger = typeof __EDGEEVER_INSTANCE_DEPLOYMENT_TRIGGER__ !== "undefined"
|
|
? __EDGEEVER_INSTANCE_DEPLOYMENT_TRIGGER__
|
|
: "";
|
|
const bundledMethod = typeof __EDGEEVER_INSTANCE_DEPLOYMENT_METHOD__ !== "undefined"
|
|
? __EDGEEVER_INSTANCE_DEPLOYMENT_METHOD__
|
|
: "";
|
|
|
|
export const resolveInstanceDeploymentMetadata = (
|
|
environment: Pick<Bindings, "EDGE_EVER_DEPLOYMENT_TRIGGER" | "EDGE_EVER_DEPLOYMENT_METHOD">,
|
|
): DeploymentMetadata => ({
|
|
trigger: resolveDeploymentTrigger(environment.EDGE_EVER_DEPLOYMENT_TRIGGER?.trim() || bundledTrigger),
|
|
method: resolveDeploymentMethod(environment.EDGE_EVER_DEPLOYMENT_METHOD?.trim() || bundledMethod),
|
|
});
|
|
|
|
export const resolveDeploymentVersionCreatedAt = (
|
|
environment: Pick<Bindings, "deploymentVersionCreatedAt">,
|
|
): string | null => {
|
|
const timestamp = environment.deploymentVersionCreatedAt;
|
|
if (!timestamp || !Number.isFinite(Date.parse(timestamp))) return null;
|
|
return new Date(timestamp).toISOString();
|
|
};
|
|
|
|
const normalizeTimestamp = (value: string | undefined): string | null => {
|
|
const timestamp = value?.trim();
|
|
if (!timestamp || !Number.isFinite(Date.parse(timestamp))) return null;
|
|
return new Date(timestamp).toISOString();
|
|
};
|
|
|
|
/**
|
|
* How and when the container image was produced. This is separate from the
|
|
* instance deployment metadata: an image can be deployed long after it was
|
|
* built, and by a different mechanism.
|
|
*/
|
|
export const resolveImageBuildMetadata = (
|
|
environment: Pick<Bindings, "EDGE_EVER_BUILD_CREATED_AT" | "EDGE_EVER_BUILD_TRIGGER" | "EDGE_EVER_BUILD_METHOD">,
|
|
): { buildCreatedAt: string | null; buildProvenance: DeploymentMetadata } => ({
|
|
buildCreatedAt: normalizeTimestamp(environment.EDGE_EVER_BUILD_CREATED_AT),
|
|
buildProvenance: {
|
|
trigger: resolveDeploymentTrigger(environment.EDGE_EVER_BUILD_TRIGGER?.trim()),
|
|
method: resolveDeploymentMethod(environment.EDGE_EVER_BUILD_METHOD?.trim()),
|
|
},
|
|
});
|