Merge pull request #2029 from pikasTech/perf/selfmedia-env-reuse
fix: 使用可移植的 SELFMEDIA 阶段计时
This commit is contained in:
@@ -2913,7 +2913,7 @@ function envReuseText(envReuse: Record<string, unknown>): string {
|
||||
function stageTimingsText(timings: Record<string, unknown>): string {
|
||||
const parts = Object.entries(timings)
|
||||
.filter((entry): entry is [string, number] => typeof entry[1] === "number" && Number.isFinite(entry[1]))
|
||||
.map(([name, milliseconds]) => `${name}=${Math.round(milliseconds)}ms`);
|
||||
.map(([name, value]) => `${name}=${Math.round(value)}${name.endsWith("Seconds") ? "s" : "ms"}`);
|
||||
return parts.length === 0 ? "-" : parts.join(",");
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ function sourceStep(target: SelfMediaDeliveryTarget, effectiveDeploymentB64: str
|
||||
],
|
||||
script: `#!/bin/sh
|
||||
set -eu
|
||||
stage_started_ms=$(date +%s%3N)
|
||||
stage_started_seconds=$(date +%s)
|
||||
source_commit="$(params.revision)"
|
||||
snapshot_prefix="$(params.source-snapshot-prefix)"
|
||||
rm -rf /workspace/source /workspace/release
|
||||
@@ -171,8 +171,8 @@ bun deploy/scripts/prepare-build.ts \\
|
||||
--source-commit "$source_commit" \\
|
||||
--source-snapshot-prefix "$snapshot_prefix" \\
|
||||
--output-dir /workspace/release
|
||||
stage_finished_ms=$(date +%s%3N)
|
||||
printf '{"ok":true,"phase":"source-prepare","stageTimings":{"sourcePrepareMs":%s},"valuesPrinted":false}\n' "$((stage_finished_ms-stage_started_ms))"
|
||||
stage_finished_seconds=$(date +%s)
|
||||
printf '{"ok":true,"phase":"source-prepare","stageTimings":{"sourcePrepareSeconds":%s},"valuesPrinted":false}\n' "$((stage_finished_seconds-stage_started_seconds))"
|
||||
`,
|
||||
securityContext: nonRootSecurity(),
|
||||
volumeMounts: [
|
||||
@@ -205,7 +205,7 @@ function envReuseStep(target: SelfMediaDeliveryTarget): Record<string, unknown>
|
||||
imagePullPolicy: "IfNotPresent",
|
||||
script: `#!/bin/sh
|
||||
set -eu
|
||||
stage_started_ms=$(date +%s%3N)
|
||||
stage_started_seconds=$(date +%s)
|
||||
identity_file=/home/user/.local/share/buildkit/.unidesk/selfmedia-env-identity
|
||||
for input in ${identityInputs}; do test -f "$input"; done
|
||||
env_identity="sha256:$(sha256sum ${identityInputs} | sha256sum | awk '{print $1}')"
|
||||
@@ -219,8 +219,8 @@ else
|
||||
if [ -n "$previous_identity" ]; then previous_present=true; else previous_present=false; fi
|
||||
fi
|
||||
printf '%s\n' "$env_identity" > /workspace/env-identity
|
||||
stage_finished_ms=$(date +%s%3N)
|
||||
printf '{"ok":true,"phase":"env-reuse","envIdentity":"%s","envReuseStatus":"%s","envReuse":{"status":"%s","mode":"${target.build.envReuse.mode}","identitySource":"owning-yaml-source-artifact","previousIdentityPresent":%s},"stageTimings":{"envIdentityMs":%s},"valuesPrinted":false}\n' "$env_identity" "$reuse_status" "$reuse_status" "$previous_present" "$((stage_finished_ms-stage_started_ms))"
|
||||
stage_finished_seconds=$(date +%s)
|
||||
printf '{"ok":true,"phase":"env-reuse","envIdentity":"%s","envReuseStatus":"%s","envReuse":{"status":"%s","mode":"${target.build.envReuse.mode}","identitySource":"owning-yaml-source-artifact","previousIdentityPresent":%s},"stageTimings":{"envIdentitySeconds":%s},"valuesPrinted":false}\n' "$env_identity" "$reuse_status" "$reuse_status" "$previous_present" "$((stage_finished_seconds-stage_started_seconds))"
|
||||
`,
|
||||
securityContext: nonRootSecurity(),
|
||||
volumeMounts: [
|
||||
@@ -242,11 +242,11 @@ function imageBuildStep(target: SelfMediaDeliveryTarget): Record<string, unknown
|
||||
],
|
||||
script: `#!/bin/sh
|
||||
set -eu
|
||||
stage_started_ms=$(date +%s%3N)
|
||||
stage_started_seconds=$(date +%s)
|
||||
/bin/sh /workspace/source/deploy/scripts/build-image.sh
|
||||
cp /workspace/env-identity /home/user/.local/share/buildkit/.unidesk/selfmedia-env-identity
|
||||
stage_finished_ms=$(date +%s%3N)
|
||||
printf '{"ok":true,"phase":"image-build-complete","envIdentity":"%s","stageTimings":{"imageBuildMs":%s},"valuesPrinted":false}\n' "$(cat /workspace/env-identity)" "$((stage_finished_ms-stage_started_ms))"
|
||||
stage_finished_seconds=$(date +%s)
|
||||
printf '{"ok":true,"phase":"image-build-complete","envIdentity":"%s","stageTimings":{"imageBuildSeconds":%s},"valuesPrinted":false}\n' "$(cat /workspace/env-identity)" "$((stage_finished_seconds-stage_started_seconds))"
|
||||
`,
|
||||
securityContext: { privileged: true, runAsUser: 1000, runAsGroup: 1000 },
|
||||
volumeMounts: [
|
||||
@@ -266,7 +266,7 @@ function gitOpsPublishStep(target: SelfMediaDeliveryTarget): Record<string, unkn
|
||||
env: [{ name: "SOURCE_COMMIT", value: "$(params.revision)" }],
|
||||
script: `#!/bin/sh
|
||||
set -eu
|
||||
stage_started_ms=$(date +%s%3N)
|
||||
stage_started_seconds=$(date +%s)
|
||||
askpass=/tmp/selfmedia-git-askpass
|
||||
cat >"$askpass" <<'ASKPASS'
|
||||
#!/bin/sh
|
||||
@@ -287,8 +287,8 @@ bun /workspace/source/deploy/scripts/publish-gitops.ts \\
|
||||
--source-commit "$SOURCE_COMMIT" \\
|
||||
--worktree /workspace/selfmedia-gitops
|
||||
rm -f "$askpass"
|
||||
stage_finished_ms=$(date +%s%3N)
|
||||
printf '{"ok":true,"phase":"gitops-stage","stageTimings":{"gitopsPublishMs":%s},"valuesPrinted":false}\n' "$((stage_finished_ms-stage_started_ms))"
|
||||
stage_finished_seconds=$(date +%s)
|
||||
printf '{"ok":true,"phase":"gitops-stage","stageTimings":{"gitopsPublishSeconds":%s},"valuesPrinted":false}\n' "$((stage_finished_seconds-stage_started_seconds))"
|
||||
`,
|
||||
securityContext: nonRootSecurity(),
|
||||
volumeMounts: [
|
||||
|
||||
Reference in New Issue
Block a user