feat(ci): add code queue dev smoke

This commit is contained in:
Codex
2026-05-18 13:22:43 +00:00
parent bd74492bb9
commit ca10682063
7 changed files with 468 additions and 117 deletions
+104 -2
View File
@@ -116,12 +116,12 @@ write_result() {
local ok="$1"
local status="$2"
local detail="$3"
python3 - "$result_json" "$ok" "$status" "$detail" "$run_id" "$repo_url" "$desired_ref" "$manifest_commit" "$environment" "$pipeline_run" "$temporary_namespace" <<'PY'
python3 - "$result_json" "$ok" "$status" "$detail" "$run_id" "$repo_url" "$desired_ref" "$manifest_commit" "$environment" "$pipeline_run" "$temporary_namespace" "$code_queue_image" <<'PY'
import json
import sys
from datetime import datetime, timezone
path, ok, status, detail, run_id, repo, desired_ref, commit, environment, pipeline_run, temporary_namespace = sys.argv[1:]
path, ok, status, detail, run_id, repo, desired_ref, commit, environment, pipeline_run, temporary_namespace, code_queue_image = sys.argv[1:]
record = {
"ok": ok == "true",
"status": status,
@@ -133,6 +133,7 @@ record = {
"environment": environment,
"pipelineRun": pipeline_run or None,
"temporaryNamespace": temporary_namespace or None,
"codeQueueImage": code_queue_image or None,
"finishedAt": datetime.now(timezone.utc).isoformat(),
}
with open(path, "w", encoding="utf-8") as handle:
@@ -144,6 +145,7 @@ PY
pipeline_run=""
temporary_namespace="unidesk-ci-e2e-$run_id"
code_queue_image=""
trap 'code=$?; if [ "$code" -ne 0 ] && [ ! -f "$result_json" ]; then write_result false failed "runner exited with code $code" || true; fi' EXIT
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
@@ -188,8 +190,106 @@ source "$service_env"
backend_commit="${BACKEND_CORE_COMMIT:-unknown}"
frontend_commit="${FRONTEND_COMMIT:-unknown}"
code_queue_commit="${CODE_QUEUE_COMMIT:-unknown}"
if ! [[ "$code_queue_commit" =~ ^[0-9a-f]{40}$ ]]; then
echo "deploy.json environments.$environment.services must include code-queue with a full 40 character commitId; got: $code_queue_commit" >&2
exit 2
fi
deploy_json_b64="$(base64 -w0 "$manifest_file")"
work_dir="$(dirname "$manifest_file")"
repo_dir="$work_dir/repo"
if [ ! -d "$repo_dir/.git" ]; then
echo "launcher repo checkout is missing: $repo_dir" >&2
exit 2
fi
root_exec() {
if [ "$(id -u)" = "0" ]; then
"$@"
return
fi
if sudo -n true >/dev/null 2>&1; then
sudo -n "$@"
return
fi
if [ -x /mnt/c/Windows/System32/wsl.exe ]; then
/mnt/c/Windows/System32/wsl.exe -u root -- "$@"
return
fi
echo "dev_e2e_native_k3s_root_access=missing" >&2
return 1
}
import_image_to_k3s() {
local image="$1"
local archive="/tmp/unidesk-ci-image-${run_id}-${image//[^A-Za-z0-9_.-]/-}.tar"
rm -f "$archive"
docker save "$image" -o "$archive"
root_exec ctr --address /run/k3s/containerd/containerd.sock -n k8s.io images import --digests --all-platforms "$archive"
rm -f "$archive"
echo "dev_e2e_image_imported=$image"
}
ensure_runtime_image() {
local image="$1"
if ! docker image inspect "$image" >/dev/null 2>&1; then
echo "dev_e2e_runtime_image_pull=$image"
docker pull --platform linux/amd64 "$image"
else
echo "dev_e2e_runtime_image_cached=$image"
fi
import_image_to_k3s "$image"
}
build_code_queue_image() {
local short="${code_queue_commit:0:12}"
local commit_image="unidesk-code-queue:ci-$short"
local run_image="unidesk-code-queue:ci-dev-e2e-$run_id"
local source_dir="$work_dir/code-queue-src-$short"
local resolved
git -C "$repo_dir" fetch --no-tags origin "$code_queue_commit" || git -C "$repo_dir" fetch --no-tags origin '+refs/heads/*:refs/remotes/origin/*'
resolved="$(git -C "$repo_dir" rev-parse --verify "$code_queue_commit^{commit}")"
if [ "$resolved" != "$code_queue_commit" ]; then
echo "code_queue_commit_mismatch resolved=$resolved expected=$code_queue_commit" >&2
exit 1
fi
local existing_rev
existing_rev="$(docker image inspect "$commit_image" --format '{{ index .Config.Labels "org.opencontainers.image.revision" }}' 2>/dev/null || true)"
if [ "$existing_rev" != "$resolved" ]; then
rm -rf "$source_dir"
mkdir -p "$source_dir"
git -C "$repo_dir" archive "$resolved" | tar -x -C "$source_dir"
local base_args=()
if docker image inspect unidesk-code-queue:d601-build-base >/dev/null 2>&1; then
base_args=(--build-arg CODE_QUEUE_BASE_IMAGE=unidesk-code-queue:d601-build-base)
elif docker image inspect unidesk-code-queue:d601 >/dev/null 2>&1; then
base_args=(--build-arg CODE_QUEUE_BASE_IMAGE=unidesk-code-queue:d601)
fi
echo "dev_e2e_code_queue_image_build=$commit_image commit=$resolved"
docker build \
"${base_args[@]}" \
--build-arg HTTP_PROXY="${HTTP_PROXY:-}" \
--build-arg HTTPS_PROXY="${HTTPS_PROXY:-}" \
--build-arg ALL_PROXY="${ALL_PROXY:-}" \
--build-arg NO_PROXY="${NO_PROXY:-}" \
--label "org.opencontainers.image.source=$repo_url" \
--label "org.opencontainers.image.revision=$resolved" \
--label "unidesk.ai/ci-run-id=$run_id" \
--label "unidesk.ai/ci-kind=dev-e2e" \
-t "$commit_image" \
-f "$source_dir/src/components/microservices/code-queue/Dockerfile" \
"$source_dir"
else
echo "dev_e2e_code_queue_image_cached=$commit_image commit=$resolved"
fi
docker tag "$commit_image" "$run_image"
import_image_to_k3s "$run_image"
code_queue_image="$run_image"
}
ensure_runtime_image "postgres:16-alpine"
build_code_queue_image
pipeline_manifest="$result_dir/pipelinerun.yaml"
cat >"$pipeline_manifest" <<YAML
apiVersion: tekton.dev/v1
@@ -227,6 +327,8 @@ spec:
value: "$frontend_commit"
- name: code-queue-commit
value: "$code_queue_commit"
- name: app-image
value: "$code_queue_image"
- name: deploy-json-b64
value: "$deploy_json_b64"
workspaces: