@capsulos/provider-namespace 0.0.0-stage → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/dist/index.d.ts +118 -0
- package/dist/index.js +340 -0
- package/dist/index.js.map +1 -0
- package/dist/registry.d.ts +39 -0
- package/dist/registry.js +96 -0
- package/dist/registry.js.map +1 -0
- package/dist/templates.d.ts +19 -0
- package/dist/templates.js +42 -0
- package/dist/templates.js.map +1 -0
- package/package.json +56 -3
- package/src/index.ts +401 -0
- package/src/namespace.test.ts +148 -0
- package/src/registry.ts +114 -0
- package/src/templates.ts +51 -0
- package/README.md +0 -3
package/src/templates.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Templates on Namespace: one repository per template in the workspace's registry,
|
|
2
|
+
// `nscr.io/<workspace>/capsulos/<name>`, one tag per version. The image carries its identity and its
|
|
3
|
+
// manifest in labels (the same ones the Docker target writes), and they are read back from the registry.
|
|
4
|
+
//
|
|
5
|
+
// Who builds the image is the caller's: the CLI with Docker on the user's machine, capsulos cloud with
|
|
6
|
+
// BuildKit in a short-lived builder instance of the org's workspace. Both write these labels.
|
|
7
|
+
import { IMAGE_LABEL, type ImageConfig } from './index.js';
|
|
8
|
+
|
|
9
|
+
const VERSION = /^\d+\.\d+\.\d+$/;
|
|
10
|
+
|
|
11
|
+
/** The repository of a template inside a workspace's registry. */
|
|
12
|
+
export const namespaceRepository = (workspace: string, name: string) => `${workspace}/capsulos/${name}`;
|
|
13
|
+
|
|
14
|
+
/** The labels an image of a template version carries. */
|
|
15
|
+
export function namespaceImageLabels(m: { name: string; version: string; digest: string; memoryMiB: number }, manifest: unknown = m): Record<string, string> {
|
|
16
|
+
return {
|
|
17
|
+
[`${IMAGE_LABEL}.template`]: m.name,
|
|
18
|
+
[`${IMAGE_LABEL}.version`]: m.version,
|
|
19
|
+
[`${IMAGE_LABEL}.digest`]: m.digest,
|
|
20
|
+
[`${IMAGE_LABEL}.memory-mib`]: String(m.memoryMiB),
|
|
21
|
+
[`${IMAGE_LABEL}.manifest`]: JSON.stringify(manifest),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface NamespaceVersion {
|
|
26
|
+
version: string;
|
|
27
|
+
digest: string;
|
|
28
|
+
/** The manifest the image's labels carry, as written (null when it has none or it does not parse). */
|
|
29
|
+
manifest: unknown;
|
|
30
|
+
createdAt?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** What an image's labels say it is: a version of this template under this tag, when it was built from a capsule.yaml. */
|
|
34
|
+
export function namespaceVersionFromImage(name: string, tag: string, config: ImageConfig): NamespaceVersion | null {
|
|
35
|
+
const l = config.labels;
|
|
36
|
+
const version = l[`${IMAGE_LABEL}.version`];
|
|
37
|
+
const digest = l[`${IMAGE_LABEL}.digest`];
|
|
38
|
+
if (l[`${IMAGE_LABEL}.template`] !== name || !version || !digest || version !== tag || !VERSION.test(tag)) return null;
|
|
39
|
+
let manifest: unknown = null;
|
|
40
|
+
try {
|
|
41
|
+
manifest = l[`${IMAGE_LABEL}.manifest`] ? JSON.parse(l[`${IMAGE_LABEL}.manifest`]!) : null;
|
|
42
|
+
} catch {
|
|
43
|
+
manifest = null;
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
version,
|
|
47
|
+
digest,
|
|
48
|
+
manifest,
|
|
49
|
+
...(config.created ? { createdAt: config.created } : {}),
|
|
50
|
+
};
|
|
51
|
+
}
|
package/README.md
DELETED