@ericminassian/platform-engine 0.4.0 → 0.5.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/dist/clients.d.ts +0 -4
- package/dist/clients.js +1 -14
- package/dist/clients.js.map +1 -1
- package/dist/compat.d.ts +9 -21
- package/dist/compat.js +6 -26
- package/dist/compat.js.map +1 -1
- package/dist/drivers/cognito.d.ts +27 -3
- package/dist/drivers/cognito.js +76 -24
- package/dist/drivers/cognito.js.map +1 -1
- package/dist/drivers/index.d.ts +0 -2
- package/dist/drivers/index.js +0 -2
- package/dist/drivers/index.js.map +1 -1
- package/dist/drivers/logs.d.ts +11 -0
- package/dist/drivers/logs.js +15 -1
- package/dist/drivers/logs.js.map +1 -1
- package/dist/drivers/scheduler.d.ts +0 -21
- package/dist/drivers/scheduler.js +0 -43
- package/dist/drivers/scheduler.js.map +1 -1
- package/dist/index.d.ts +2 -81
- package/dist/index.js +0 -5
- package/dist/index.js.map +1 -1
- package/dist/local.js +2 -140
- package/dist/local.js.map +1 -1
- package/dist/login-branding.d.ts +27 -0
- package/dist/login-branding.js +329 -0
- package/dist/login-branding.js.map +1 -0
- package/dist/login-glyphs.d.ts +12 -0
- package/dist/login-glyphs.js +903 -0
- package/dist/login-glyphs.js.map +1 -0
- package/dist/policy.d.ts +2 -26
- package/dist/policy.js +2 -107
- package/dist/policy.js.map +1 -1
- package/dist/stage.d.ts +1 -2
- package/dist/stage.js +16 -87
- package/dist/stage.js.map +1 -1
- package/dist/util.d.ts +0 -22
- package/dist/util.js +0 -16
- package/dist/util.js.map +1 -1
- package/package.json +10 -7
- package/src/clients.ts +1 -15
- package/src/compat.ts +9 -32
- package/src/drivers/cognito.ts +98 -23
- package/src/drivers/index.ts +0 -2
- package/src/drivers/logs.ts +21 -0
- package/src/drivers/scheduler.ts +0 -69
- package/src/index.ts +3 -78
- package/src/local.ts +2 -152
- package/src/login-branding.ts +407 -0
- package/src/login-glyphs.ts +911 -0
- package/src/policy.ts +2 -132
- package/src/stage.ts +16 -102
- package/src/util.ts +0 -34
- package/dist/drivers/ecr.d.ts +0 -109
- package/dist/drivers/ecr.js +0 -303
- package/dist/drivers/ecr.js.map +0 -1
- package/dist/drivers/ecs.d.ts +0 -163
- package/dist/drivers/ecs.js +0 -447
- package/dist/drivers/ecs.js.map +0 -1
- package/dist/images.d.ts +0 -104
- package/dist/images.js +0 -182
- package/dist/images.js.map +0 -1
- package/dist/services.d.ts +0 -155
- package/dist/services.js +0 -464
- package/dist/services.js.map +0 -1
- package/src/drivers/ecr.ts +0 -457
- package/src/drivers/ecs.ts +0 -661
- package/src/images.ts +0 -254
- package/src/services.ts +0 -663
package/src/images.ts
DELETED
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OCI image assembly without Docker: a layer is a deterministic tarball of
|
|
3
|
-
* files, an image is a base image's layers plus that layer, described by a
|
|
4
|
-
* config and a manifest. Pure functions; the registry calls live in
|
|
5
|
-
* `drivers/ecr.ts`.
|
|
6
|
-
*
|
|
7
|
-
* Determinism matters: the same files on the same base give byte-identical
|
|
8
|
-
* blobs, so redeploying unchanged code pushes nothing new and the image
|
|
9
|
-
* digest says whether a build changed.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { createHash } from 'node:crypto';
|
|
13
|
-
import { gzipSync } from 'fflate';
|
|
14
|
-
|
|
15
|
-
export const MEDIA_TYPES = {
|
|
16
|
-
ociManifest: 'application/vnd.oci.image.manifest.v1+json',
|
|
17
|
-
ociIndex: 'application/vnd.oci.image.index.v1+json',
|
|
18
|
-
ociConfig: 'application/vnd.oci.image.config.v1+json',
|
|
19
|
-
ociLayerGzip: 'application/vnd.oci.image.layer.v1.tar+gzip',
|
|
20
|
-
dockerManifest: 'application/vnd.docker.distribution.manifest.v2+json',
|
|
21
|
-
dockerManifestList: 'application/vnd.docker.distribution.manifest.list.v2+json',
|
|
22
|
-
} as const;
|
|
23
|
-
|
|
24
|
-
/** Single-platform manifest types a base image may have. */
|
|
25
|
-
export const IMAGE_MANIFEST_TYPES: readonly string[] = [MEDIA_TYPES.ociManifest, MEDIA_TYPES.dockerManifest];
|
|
26
|
-
|
|
27
|
-
export interface Descriptor {
|
|
28
|
-
mediaType: string;
|
|
29
|
-
digest: string;
|
|
30
|
-
size: number;
|
|
31
|
-
annotations?: Record<string, string>;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface ImageManifest {
|
|
35
|
-
schemaVersion: 2;
|
|
36
|
-
mediaType?: string;
|
|
37
|
-
config: Descriptor;
|
|
38
|
-
layers: Descriptor[];
|
|
39
|
-
annotations?: Record<string, string>;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** The parts of an OCI image config the platform reads or writes; the rest passes through. */
|
|
43
|
-
export interface ImageConfig {
|
|
44
|
-
architecture: string;
|
|
45
|
-
os: string;
|
|
46
|
-
created?: string;
|
|
47
|
-
config?: {
|
|
48
|
-
Env?: string[];
|
|
49
|
-
Entrypoint?: string[] | null;
|
|
50
|
-
Cmd?: string[] | null;
|
|
51
|
-
WorkingDir?: string;
|
|
52
|
-
User?: string;
|
|
53
|
-
[key: string]: unknown;
|
|
54
|
-
};
|
|
55
|
-
rootfs: { type: 'layers'; diff_ids: string[] };
|
|
56
|
-
history?: Array<{ created?: string; created_by?: string; comment?: string; empty_layer?: boolean }>;
|
|
57
|
-
[key: string]: unknown;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export interface ImageFile {
|
|
61
|
-
/** Absolute path inside the image (`/app/index.mjs`). */
|
|
62
|
-
path: string;
|
|
63
|
-
content: Uint8Array;
|
|
64
|
-
/** Default 0o644. */
|
|
65
|
-
mode?: number;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export interface Layer {
|
|
69
|
-
/** The gzipped tarball as pushed. */
|
|
70
|
-
blob: Uint8Array;
|
|
71
|
-
/** sha256 of `blob`: the layer's digest in the manifest. */
|
|
72
|
-
digest: string;
|
|
73
|
-
/** sha256 of the uncompressed tarball: the layer's entry in the config's `rootfs.diff_ids`. */
|
|
74
|
-
diffId: string;
|
|
75
|
-
size: number;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function sha256Digest(bytes: Uint8Array): string {
|
|
79
|
-
return `sha256:${createHash('sha256').update(bytes).digest('hex')}`;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* A ustar archive of `files` plus an entry for every parent directory,
|
|
84
|
-
* sorted by path, owned by root with mtime 0, so equal input gives equal
|
|
85
|
-
* bytes.
|
|
86
|
-
*/
|
|
87
|
-
export function tarFiles(files: readonly ImageFile[]): Uint8Array {
|
|
88
|
-
const entries = new Map<string, { type: 'dir' } | { type: 'file'; content: Uint8Array; mode: number }>();
|
|
89
|
-
for (const f of files) {
|
|
90
|
-
const rel = normalizePath(f.path);
|
|
91
|
-
const parts = rel.split('/');
|
|
92
|
-
for (let i = 1; i < parts.length; i++) entries.set(`${parts.slice(0, i).join('/')}/`, { type: 'dir' });
|
|
93
|
-
if (entries.has(rel)) throw new Error(`duplicate file in layer: ${f.path}`);
|
|
94
|
-
entries.set(rel, { type: 'file', content: f.content, mode: f.mode ?? 0o644 });
|
|
95
|
-
}
|
|
96
|
-
const blocks: Uint8Array[] = [];
|
|
97
|
-
for (const name of [...entries.keys()].toSorted()) {
|
|
98
|
-
const e = entries.get(name)!;
|
|
99
|
-
if (e.type === 'dir') {
|
|
100
|
-
blocks.push(tarHeader({ name, mode: 0o755, size: 0, type: '5' }));
|
|
101
|
-
} else {
|
|
102
|
-
blocks.push(tarHeader({ name, mode: e.mode, size: e.content.length, type: '0' }), e.content);
|
|
103
|
-
const pad = (512 - (e.content.length % 512)) % 512;
|
|
104
|
-
if (pad) blocks.push(new Uint8Array(pad));
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
blocks.push(new Uint8Array(1024));
|
|
108
|
-
return concat(blocks);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** A gzipped layer of `files` with its digests. */
|
|
112
|
-
export function buildLayer(files: readonly ImageFile[]): Layer {
|
|
113
|
-
const tar = tarFiles(files);
|
|
114
|
-
// mtime 0 keeps the gzip header (and so the digest) stable.
|
|
115
|
-
const blob = gzipSync(tar, { level: 9, mtime: 0 });
|
|
116
|
-
return { blob, digest: sha256Digest(blob), diffId: sha256Digest(tar), size: blob.length };
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export interface ImageConfigSpec {
|
|
120
|
-
entrypoint: string[];
|
|
121
|
-
/** Replaces the base image's Cmd; none when omitted (the base's would be appended to the entrypoint). */
|
|
122
|
-
cmd?: string[];
|
|
123
|
-
/** Merged over the base image's environment. */
|
|
124
|
-
env?: Record<string, string>;
|
|
125
|
-
workingDir?: string;
|
|
126
|
-
user?: string;
|
|
127
|
-
/** History line for the added layer. */
|
|
128
|
-
createdBy?: string;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/** The base image's config with `layer` on top and the process settings of `spec`. */
|
|
132
|
-
export function imageConfig(base: ImageConfig, layer: Layer, spec: ImageConfigSpec): ImageConfig {
|
|
133
|
-
const env = new Map<string, string>();
|
|
134
|
-
for (const kv of base.config?.Env ?? []) {
|
|
135
|
-
const i = kv.indexOf('=');
|
|
136
|
-
env.set(i === -1 ? kv : kv.slice(0, i), i === -1 ? '' : kv.slice(i + 1));
|
|
137
|
-
}
|
|
138
|
-
for (const [k, v] of Object.entries(spec.env ?? {})) env.set(k, v);
|
|
139
|
-
const { Cmd: _cmd, ...baseProcess } = base.config ?? {};
|
|
140
|
-
return {
|
|
141
|
-
...base,
|
|
142
|
-
config: {
|
|
143
|
-
...baseProcess,
|
|
144
|
-
Env: [...env].map(([k, v]) => `${k}=${v}`),
|
|
145
|
-
Entrypoint: spec.entrypoint,
|
|
146
|
-
...(spec.cmd ? { Cmd: spec.cmd } : {}),
|
|
147
|
-
...(spec.workingDir ? { WorkingDir: spec.workingDir } : {}),
|
|
148
|
-
...(spec.user ? { User: spec.user } : {}),
|
|
149
|
-
},
|
|
150
|
-
rootfs: { type: 'layers', diff_ids: [...base.rootfs.diff_ids, layer.diffId] },
|
|
151
|
-
history: [
|
|
152
|
-
...(base.history ?? []),
|
|
153
|
-
{ ...(base.created ? { created: base.created } : {}), created_by: spec.createdBy ?? 'platform' },
|
|
154
|
-
],
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/** An OCI image manifest (serialized: its bytes are what the digest covers). */
|
|
159
|
-
export function imageManifest(
|
|
160
|
-
config: { digest: string; size: number },
|
|
161
|
-
layers: readonly Descriptor[],
|
|
162
|
-
): string {
|
|
163
|
-
const manifest: ImageManifest = {
|
|
164
|
-
schemaVersion: 2,
|
|
165
|
-
mediaType: MEDIA_TYPES.ociManifest,
|
|
166
|
-
config: { mediaType: MEDIA_TYPES.ociConfig, digest: config.digest, size: config.size },
|
|
167
|
-
layers: layers.map((l) => ({ mediaType: l.mediaType, digest: l.digest, size: l.size })),
|
|
168
|
-
};
|
|
169
|
-
return JSON.stringify(manifest);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export function layerDescriptor(layer: Layer): Descriptor {
|
|
173
|
-
return { mediaType: MEDIA_TYPES.ociLayerGzip, digest: layer.digest, size: layer.size };
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/** Parse a registry manifest, refusing multi-platform indexes (a base must be pinned to one platform). */
|
|
177
|
-
export function parseImageManifest(raw: string, fallbackMediaType?: string): ImageManifest {
|
|
178
|
-
const m = JSON.parse(raw) as Partial<ImageManifest> & { manifests?: unknown };
|
|
179
|
-
const mediaType = m.mediaType ?? fallbackMediaType;
|
|
180
|
-
if (m.manifests || mediaType === MEDIA_TYPES.ociIndex || mediaType === MEDIA_TYPES.dockerManifestList) {
|
|
181
|
-
throw new Error('expected a single-platform image manifest, got a multi-platform index');
|
|
182
|
-
}
|
|
183
|
-
if (m.schemaVersion !== 2 || !m.config?.digest || !Array.isArray(m.layers)) {
|
|
184
|
-
throw new Error('not an image manifest (schema version 2 with a config and layers)');
|
|
185
|
-
}
|
|
186
|
-
return m as ImageManifest;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function normalizePath(path: string): string {
|
|
190
|
-
const rel = path.replace(/^\/+/, '');
|
|
191
|
-
if (!rel || rel.endsWith('/') || rel.split('/').some((p) => p === '' || p === '.' || p === '..')) {
|
|
192
|
-
throw new Error(`invalid file path in layer: ${path}`);
|
|
193
|
-
}
|
|
194
|
-
return rel;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const encoder = new TextEncoder();
|
|
198
|
-
|
|
199
|
-
function tarHeader(e: { name: string; mode: number; size: number; type: '0' | '5' }): Uint8Array {
|
|
200
|
-
const h = new Uint8Array(512);
|
|
201
|
-
const [prefix, name] = splitName(e.name);
|
|
202
|
-
writeString(h, 0, 100, name);
|
|
203
|
-
writeOctal(h, 100, 8, e.mode);
|
|
204
|
-
writeOctal(h, 108, 8, 0); // uid
|
|
205
|
-
writeOctal(h, 116, 8, 0); // gid
|
|
206
|
-
writeOctal(h, 124, 12, e.size);
|
|
207
|
-
writeOctal(h, 136, 12, 0); // mtime
|
|
208
|
-
h.fill(0x20, 148, 156); // checksum is computed with its own field as spaces
|
|
209
|
-
h[156] = e.type.charCodeAt(0);
|
|
210
|
-
writeString(h, 257, 6, 'ustar');
|
|
211
|
-
writeString(h, 263, 2, '00');
|
|
212
|
-
writeString(h, 265, 32, 'root');
|
|
213
|
-
writeString(h, 297, 32, 'root');
|
|
214
|
-
writeString(h, 345, 155, prefix);
|
|
215
|
-
const sum = h.reduce((a, b) => a + b, 0);
|
|
216
|
-
writeString(h, 148, 8, `${sum.toString(8).padStart(6, '0')}\0 `);
|
|
217
|
-
return h;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/** ustar keeps names ≤ 100 bytes, or a ≤ 155-byte prefix plus a ≤ 100-byte name split at a `/`. */
|
|
221
|
-
function splitName(path: string): [string, string] {
|
|
222
|
-
const bytes = encoder.encode(path);
|
|
223
|
-
if (bytes.length <= 100) return ['', path];
|
|
224
|
-
// A directory entry's trailing slash stays with the name part.
|
|
225
|
-
for (let i = path.length - 2; i > 0; i--) {
|
|
226
|
-
if (path[i] !== '/') continue;
|
|
227
|
-
const prefix = path.slice(0, i);
|
|
228
|
-
const name = path.slice(i + 1);
|
|
229
|
-
if (encoder.encode(prefix).length <= 155 && encoder.encode(name).length <= 100) return [prefix, name];
|
|
230
|
-
}
|
|
231
|
-
throw new Error(`path too long for a ustar layer: ${path}`);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function writeString(h: Uint8Array, offset: number, length: number, value: string): void {
|
|
235
|
-
const bytes = encoder.encode(value);
|
|
236
|
-
if (bytes.length > length) throw new Error(`tar header field too long: ${value}`);
|
|
237
|
-
h.set(bytes, offset);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function writeOctal(h: Uint8Array, offset: number, length: number, value: number): void {
|
|
241
|
-
const digits = value.toString(8);
|
|
242
|
-
if (digits.length > length - 1) throw new Error(`tar header value too large: ${value}`);
|
|
243
|
-
writeString(h, offset, length, `${digits.padStart(length - 1, '0')}\0`);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function concat(parts: readonly Uint8Array[]): Uint8Array {
|
|
247
|
-
const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
|
|
248
|
-
let at = 0;
|
|
249
|
-
for (const p of parts) {
|
|
250
|
-
out.set(p, at);
|
|
251
|
-
at += p.length;
|
|
252
|
-
}
|
|
253
|
-
return out;
|
|
254
|
-
}
|