eust-w aa151d16f9 ✨ Deliver to Fanyu's cluster from the dev branch beside the POC
- Profiles pin each environment: POC (branch poc) and Fanyu (branch dev,
  180.76.138.88, droboticflow-fanyu), with their Deployments by UID
- Releases expect every Deployment of their profile; Fanyu's api image
  also runs its annotation processor and validator, each rolled back to
  its own image
- Bindings may list several projects; each Runner has its own settings
- fanyu-access: least-privilege identity and build-Pod admission policy in
  Fanyu's cluster, its token only in the executor and Fanyu's Runner
- projects --replace: delete every project with all it holds, then create
  the POC and Fanyu projects, their environments and Runners
- Ship the Runner's public keys in the ConfigMap, not a Mac path

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 17:47:47 +08:00

134 lines
5.4 KiB
TypeScript

import { z } from 'zod';
import { createHash } from 'node:crypto';
import { readFile, stat } from 'node:fs/promises';
import { pocTargetImage, type PocTarget } from '@wishforge/contracts';
export const pocComponentNames = ['api', 'worker', 'coordinator'] as const;
export type PocComponent = (typeof pocComponentNames)[number];
export const pocComponents = {
api: {
deployment: 'droboticflow-api',
container: 'api',
dockerfile: 'Dockerfile.api',
repository: 'droboticflow-api',
},
worker: {
deployment: 'droboticflow-worker',
container: 'worker',
dockerfile: 'Dockerfile.worker',
repository: 'droboticflow-worker',
},
coordinator: {
deployment: 'drosync-coordinator',
container: 'coordinator',
dockerfile: 'Dockerfile.drosync-coordinator',
repository: 'drosync-coordinator',
},
} as const;
/** Deployments that run the api image beside the api itself, as Fanyu's annotation workers do. */
export const pocApiFollowers = {
'annotation-processor': { deployment: 'droboticflow-annotation-processor', container: 'processor' },
'annotation-validator': { deployment: 'droboticflow-annotation-validator', container: 'processor' },
} as const;
/** Web files, which only the api image includes; a change anywhere else may reach every component. */
export const pocApiOnlyPath = (file: string) =>
/^(src\/|tests\/frontend\/|tools\/drosync\/Cargo\.(toml|lock)$)/.test(file);
const absolutePath = z
.string()
.startsWith('/')
.refine(v => !/[\x00\r\n]/.test(v));
const uid = z.string().uuid();
const repository = z.enum([
'git@gitea.d-robotics.cc:longtao.wu/droboticflow.git',
'https://gitea.d-robotics.cc/longtao.wu/droboticflow.git',
]);
const kanikoImage = z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:/-]*@sha256:[a-f0-9]{64}$/);
const registryMirrors = z.array(z.string().regex(/^[a-z0-9][a-z0-9.-]+(?::[0-9]+)?$/)).default(['mirror.gcr.io']);
const rolloutTimeoutSeconds = z.number().int().min(30).max(1800).default(600);
const buildTimeoutSeconds = z.number().int().min(60).max(3600).default(1800);
/**
* The two environments WishForge delivers DroboticFlow to, each pinned to its branch, cluster,
* namespace, registry and address: the POC (branch poc) and Fanyu's (branch dev). The fields keep
* one order, which the profile's digest depends on.
*/
export const pocProfileSchema = z.discriminatedUnion('id', [
z
.object({
schemaVersion: z.literal(1),
id: z.literal('droboticflow-poc'),
repository,
branch: z.literal('poc'),
kubeconfig: absolutePath,
clusterServer: z.literal('https://120.48.181.105:6443'),
namespace: z.literal('droboticflow'),
namespaceUid: uid,
deployments: z.object({ api: uid, worker: uid, coordinator: uid }).strict(),
registry: z.literal('ccr-29eug8s3-pub.cnc.bj.baidubce.com/dataflow-poc'),
registrySecret: z.literal('droboticflow-registry'),
applicationUrl: z.literal('http://120.48.164.19'),
kanikoImage,
registryMirrors,
rolloutTimeoutSeconds,
buildTimeoutSeconds,
})
.strict(),
z
.object({
schemaVersion: z.literal(1),
id: z.literal('droboticflow-fanyu'),
repository,
branch: z.literal('dev'),
kubeconfig: absolutePath,
clusterServer: z.literal('https://180.76.138.88:6443'),
namespace: z.literal('droboticflow-fanyu'),
namespaceUid: uid,
deployments: z
.object({ api: uid, worker: uid, coordinator: uid, 'annotation-processor': uid, 'annotation-validator': uid })
.strict(),
registry: z.literal('ccr-29eug8s3-pub.cnc.bj.baidubce.com/fanyu'),
registrySecret: z.literal('droboticflow-registry'),
applicationUrl: z.literal('http://120.48.180.80'),
kanikoImage,
registryMirrors,
rolloutTimeoutSeconds,
buildTimeoutSeconds,
})
.strict(),
]);
export type PocProfile = z.infer<typeof pocProfileSchema>;
/** Each environment's address, for checks that cannot read its profile. */
export const pocApplicationUrls = { poc: 'http://120.48.164.19', dev: 'http://120.48.180.80' } as const;
export interface PocTargetSpec {
name: PocTarget;
image: PocComponent;
deployment: string;
container: string;
uid: string;
}
/** The Deployments a profile's releases update, in the order they are updated: the api's last. */
export function pocTargets(profile: PocProfile): PocTargetSpec[] {
const order: PocTarget[] = ['coordinator', 'worker', 'api', 'annotation-processor', 'annotation-validator'];
const deployments = profile.deployments as Partial<Record<PocTarget, string>>;
return order
.filter(name => deployments[name])
.map(name => {
const image = pocTargetImage[name];
const placement =
name in pocApiFollowers ? pocApiFollowers[name as keyof typeof pocApiFollowers] : pocComponents[image];
return { name, image, deployment: placement.deployment, container: placement.container, uid: deployments[name]! };
});
}
export function profileDigest(profile: PocProfile): string {
return `sha256:${createHash('sha256')
.update(JSON.stringify(pocProfileSchema.parse(profile)))
.digest('hex')}`;
}
export async function loadPocProfile(file: string): Promise<PocProfile> {
const info = await stat(file);
if (!info.isFile() || (info.mode & 0o022) !== 0 || (process.getuid && info.uid !== process.getuid()))
throw Error('POC profile must be an operator-owned file without group/world write permission');
return pocProfileSchema.parse(JSON.parse(await readFile(file, 'utf8')));
}