File size: 2,211 Bytes
7156a50
34fef0e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ca78461
1ae42b9
fc9f257
34fef0e
 
 
 
 
 
 
 
1ae42b9
34fef0e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import openapiTS, { astToString, type OpenAPI3 } from "openapi-typescript";
import { buildApp } from "./app.js";
import type { AppConfig } from "./config.js";
import { createRuntime } from "./runtime.js";

const repository = resolve(dirname(fileURLToPath(import.meta.url)), "../../..");
const scratch = await mkdtemp(join(tmpdir(), "harbor-hf-openapi-"));
const bucket = join(scratch, "bucket");
await mkdir(bucket, { recursive: true });
const config: AppConfig = {
  node_env: "test",
  port: 7860,
  namespace: "example",
  bucket_id: "example/artifacts",
  bucket_root: bucket,
  store_mode: "filesystem",
  projection_path: join(scratch, "projection.sqlite"),
  auth_path: join(scratch, "auth.sqlite"),
  profiles_root: join(repository, "profiles"),
  capacity_profile_alias: null,
  max_active_jobs: 16,
  task_image_mirror_repository: "mirror.example/harbor-hf/tasks",
  web_root: join(scratch, "web"),
  auth_mode: "development",
  write_mode: "disabled",
  public_origin: "http://127.0.0.1:7860",
  oauth: null,
  hf_token: null,
  hf_inference_token: null,
  reconcile_interval_ms: 1000,
  sync_interval_ms: 30000,
  observe_interval_ms: 1000,
  worker_receipt_grace_ms: 0,
  source_revision: "development",
  bootstrap_operator_subjects: [],
};
const runtime = await createRuntime(config);
const app = await buildApp(runtime);
try {
  await runtime.initialize();
  await app.ready();
  const document = app.swagger();
  const documentPath = join(repository, "docs", "control-api-v1.openapi.json");
  await writeFile(documentPath, `${JSON.stringify(document, null, 2)}\n`, "utf8");
  const generated = astToString(await openapiTS(document as unknown as OpenAPI3));
  const outputPath = join(
    repository,
    "apps",
    "control-web",
    "src",
    "generated",
    "api.ts",
  );
  await mkdir(dirname(outputPath), { recursive: true });
  await writeFile(outputPath, generated, "utf8");
} finally {
  await app.close();
  await runtime.close();
  await rm(scratch, { recursive: true, force: true });
}