@enspirit/emb 0.0.2 → 0.0.3

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.
Files changed (164) hide show
  1. package/README.md +190 -164
  2. package/bin/run.js +8 -2
  3. package/dist/src/cli/abstract/FlavouredCommand.d.ts +12 -0
  4. package/dist/src/cli/abstract/FlavouredCommand.js +40 -0
  5. package/dist/src/cli/abstract/index.d.ts +1 -0
  6. package/dist/src/cli/abstract/index.js +1 -0
  7. package/dist/src/cli/commands/clean.d.ts +15 -0
  8. package/dist/src/cli/commands/clean.js +29 -0
  9. package/dist/src/cli/commands/components/build.d.ts +11 -0
  10. package/dist/src/cli/commands/components/build.js +24 -0
  11. package/dist/src/cli/commands/components/index.d.ts +14 -0
  12. package/dist/src/cli/commands/components/index.js +44 -0
  13. package/dist/src/cli/commands/config/print.d.ts +13 -0
  14. package/dist/src/cli/commands/config/print.js +16 -0
  15. package/dist/src/cli/commands/containers/index.d.ts +12 -0
  16. package/dist/src/cli/commands/containers/index.js +66 -0
  17. package/dist/src/cli/commands/containers/prune.d.ts +8 -0
  18. package/dist/src/cli/commands/containers/prune.js +23 -0
  19. package/dist/src/cli/commands/down.d.ts +8 -0
  20. package/dist/src/cli/commands/down.js +42 -0
  21. package/dist/src/cli/commands/images/delete.d.ts +10 -0
  22. package/dist/src/cli/commands/images/delete.js +44 -0
  23. package/dist/src/cli/commands/images/index.d.ts +17 -0
  24. package/dist/src/cli/commands/images/index.js +59 -0
  25. package/dist/src/cli/commands/images/prune.d.ts +11 -0
  26. package/dist/src/cli/commands/images/prune.js +35 -0
  27. package/dist/src/cli/commands/run/index.d.ts +10 -0
  28. package/dist/src/cli/commands/run/index.js +49 -0
  29. package/dist/src/cli/commands/tasks/index.d.ts +9 -0
  30. package/dist/src/cli/commands/tasks/index.js +23 -0
  31. package/dist/src/cli/commands/tasks/run.d.ts +16 -0
  32. package/dist/src/cli/commands/tasks/run.js +113 -0
  33. package/dist/src/cli/commands/up.d.ts +10 -0
  34. package/dist/src/cli/commands/up.js +49 -0
  35. package/dist/src/cli/constants.d.ts +2 -0
  36. package/dist/src/cli/constants.js +6 -0
  37. package/dist/src/cli/hooks/init.d.ts +3 -0
  38. package/dist/src/cli/hooks/init.js +27 -0
  39. package/dist/src/cli/index.d.ts +3 -0
  40. package/dist/src/cli/index.js +3 -0
  41. package/dist/src/config/convert.d.ts +5 -0
  42. package/dist/src/config/convert.js +48 -0
  43. package/dist/src/config/index.d.ts +6 -0
  44. package/dist/src/config/index.js +25 -0
  45. package/dist/src/config/schema.d.ts +102 -0
  46. package/dist/src/config/schema.js +7 -0
  47. package/dist/src/config/schema.json +209 -0
  48. package/dist/src/config/types.d.ts +43 -0
  49. package/dist/src/config/types.js +1 -0
  50. package/dist/src/config/validation.d.ts +1 -0
  51. package/dist/src/config/validation.js +27 -0
  52. package/dist/src/context.d.ts +3 -0
  53. package/dist/src/context.js +7 -0
  54. package/dist/src/docker/compose/index.d.ts +7 -0
  55. package/dist/src/docker/compose/index.js +13 -0
  56. package/dist/src/docker/containers/getContainer.d.ts +2 -0
  57. package/dist/src/docker/containers/getContainer.js +5 -0
  58. package/dist/src/docker/containers/index.d.ts +1 -0
  59. package/dist/src/docker/containers/index.js +1 -0
  60. package/dist/src/docker/images/buildImage.d.ts +19 -0
  61. package/dist/src/docker/images/buildImage.js +64 -0
  62. package/dist/src/docker/images/deleteImage.d.ts +5 -0
  63. package/dist/src/docker/images/deleteImage.js +6 -0
  64. package/dist/src/docker/images/index.d.ts +4 -0
  65. package/dist/src/docker/images/index.js +4 -0
  66. package/dist/src/docker/images/listImages.d.ts +2 -0
  67. package/dist/src/docker/images/listImages.js +8 -0
  68. package/dist/src/docker/images/pruneImages.d.ts +6 -0
  69. package/dist/src/docker/images/pruneImages.js +8 -0
  70. package/dist/src/docker/index.d.ts +7 -0
  71. package/dist/src/docker/index.js +7 -0
  72. package/dist/src/docker/operations/containers/ListContainersOperation.d.ts +18 -0
  73. package/dist/src/docker/operations/containers/ListContainersOperation.js +44 -0
  74. package/dist/src/docker/operations/containers/PruneContainersOperation.d.ts +16 -0
  75. package/dist/src/docker/operations/containers/PruneContainersOperation.js +33 -0
  76. package/dist/src/docker/operations/containers/index.d.ts +2 -0
  77. package/dist/src/docker/operations/containers/index.js +2 -0
  78. package/dist/src/docker/operations/images/BuildImageOperation.d.ts +20 -0
  79. package/dist/src/docker/operations/images/BuildImageOperation.js +69 -0
  80. package/dist/src/docker/operations/images/ListImagesOperation.d.ts +17 -0
  81. package/dist/src/docker/operations/images/ListImagesOperation.js +38 -0
  82. package/dist/src/docker/operations/images/PruneImagesOperation.d.ts +16 -0
  83. package/dist/src/docker/operations/images/PruneImagesOperation.js +33 -0
  84. package/dist/src/docker/operations/images/index.d.ts +3 -0
  85. package/dist/src/docker/operations/images/index.js +3 -0
  86. package/dist/src/docker/operations/index.d.ts +2 -0
  87. package/dist/src/docker/operations/index.js +2 -0
  88. package/dist/src/docker/protobuf/control.proto +48 -0
  89. package/dist/src/docker/protobuf/index.d.ts +5 -0
  90. package/dist/src/docker/protobuf/index.js +29 -0
  91. package/dist/src/docker/types.d.ts +14 -0
  92. package/dist/src/docker/types.js +1 -0
  93. package/dist/src/docker/utils.d.ts +7 -0
  94. package/dist/src/docker/utils.js +10 -0
  95. package/dist/src/executors/docker.d.ts +6 -0
  96. package/dist/src/executors/docker.js +14 -0
  97. package/dist/src/executors/index.d.ts +6 -0
  98. package/dist/src/executors/index.js +7 -0
  99. package/dist/src/executors/shell.d.ts +2 -0
  100. package/dist/src/executors/shell.js +14 -0
  101. package/dist/src/executors/types.d.ts +8 -0
  102. package/dist/src/executors/types.js +1 -0
  103. package/dist/src/index.d.ts +3 -0
  104. package/dist/src/index.js +3 -0
  105. package/dist/src/monorepo/component.d.ts +24 -0
  106. package/dist/src/monorepo/component.js +77 -0
  107. package/dist/src/monorepo/config.d.ts +16 -0
  108. package/dist/src/monorepo/config.js +66 -0
  109. package/dist/src/monorepo/index.d.ts +7 -0
  110. package/dist/src/monorepo/index.js +7 -0
  111. package/dist/src/monorepo/monorepo.d.ts +29 -0
  112. package/dist/src/monorepo/monorepo.js +106 -0
  113. package/dist/src/monorepo/operations/components/BuildComponentsOperation.d.ts +11 -0
  114. package/dist/src/monorepo/operations/components/BuildComponentsOperation.js +144 -0
  115. package/dist/src/monorepo/operations/components/index.d.ts +1 -0
  116. package/dist/src/monorepo/operations/components/index.js +1 -0
  117. package/dist/src/monorepo/operations/index.d.ts +1 -0
  118. package/dist/src/monorepo/operations/index.js +1 -0
  119. package/dist/src/monorepo/plugins/ComponentsDiscover.d.ts +6 -0
  120. package/dist/src/monorepo/plugins/ComponentsDiscover.js +30 -0
  121. package/dist/src/monorepo/plugins/DotEnvPlugin.d.ts +5 -0
  122. package/dist/src/monorepo/plugins/DotEnvPlugin.js +11 -0
  123. package/dist/src/monorepo/plugins/index.d.ts +7 -0
  124. package/dist/src/monorepo/plugins/index.js +20 -0
  125. package/dist/src/monorepo/plugins/plugin.d.ts +15 -0
  126. package/dist/src/monorepo/plugins/plugin.js +12 -0
  127. package/dist/src/monorepo/project.d.ts +6 -0
  128. package/dist/src/monorepo/project.js +8 -0
  129. package/dist/src/monorepo/store/index.d.ts +20 -0
  130. package/dist/src/monorepo/store/index.js +65 -0
  131. package/dist/src/monorepo/types.d.ts +7 -0
  132. package/dist/src/monorepo/types.js +1 -0
  133. package/dist/src/monorepo/utils/findBuildOrder.d.ts +2 -0
  134. package/dist/src/monorepo/utils/findBuildOrder.js +41 -0
  135. package/dist/src/monorepo/utils/index.d.ts +1 -0
  136. package/dist/src/monorepo/utils/index.js +1 -0
  137. package/dist/src/operations/abstract/AbstractOperation.d.ts +10 -0
  138. package/dist/src/operations/abstract/AbstractOperation.js +13 -0
  139. package/dist/src/operations/abstract/index.d.ts +1 -0
  140. package/dist/src/operations/abstract/index.js +1 -0
  141. package/dist/src/operations/index.d.ts +2 -0
  142. package/dist/src/operations/index.js +2 -0
  143. package/dist/src/operations/types.d.ts +3 -0
  144. package/dist/src/operations/types.js +1 -0
  145. package/dist/src/prerequisites/FilePrerequisitePlugin.d.ts +7 -0
  146. package/dist/src/prerequisites/FilePrerequisitePlugin.js +41 -0
  147. package/dist/src/prerequisites/GitPrerequisitePlugin.d.ts +5 -0
  148. package/dist/src/prerequisites/GitPrerequisitePlugin.js +17 -0
  149. package/dist/src/prerequisites/index.d.ts +3 -0
  150. package/dist/src/prerequisites/index.js +3 -0
  151. package/dist/src/prerequisites/types.d.ts +46 -0
  152. package/dist/src/prerequisites/types.js +24 -0
  153. package/dist/src/types.d.ts +13 -0
  154. package/dist/src/types.js +1 -0
  155. package/dist/src/utils/TemplateExpander.d.ts +21 -0
  156. package/dist/src/utils/TemplateExpander.js +53 -0
  157. package/dist/src/utils/deepMergeArray.d.ts +1 -0
  158. package/dist/src/utils/deepMergeArray.js +19 -0
  159. package/dist/src/utils/index.d.ts +3 -0
  160. package/dist/src/utils/index.js +3 -0
  161. package/dist/src/utils/time.d.ts +2 -0
  162. package/dist/src/utils/time.js +19 -0
  163. package/oclif.manifest.json +572 -2
  164. package/package.json +8 -9
@@ -0,0 +1 @@
1
+ export declare const validateUserConfig: (pathOrObject: string | unknown) => Promise<import("./types.js").IMonorepoConfig>;
@@ -0,0 +1,27 @@
1
+ import { Ajv } from 'ajv';
2
+ import { readFile, stat } from 'node:fs/promises';
3
+ import yaml from 'yaml';
4
+ import { toProjectConfig } from './convert.js';
5
+ export const validateUserConfig = async (pathOrObject) => {
6
+ const ajv = new Ajv();
7
+ let userConfig;
8
+ if (typeof pathOrObject === 'string') {
9
+ if (await stat(pathOrObject)) {
10
+ const cfgYaml = (await readFile(pathOrObject)).toString();
11
+ userConfig = yaml.parse(cfgYaml.toString());
12
+ }
13
+ else {
14
+ throw new Error(`Could not find file: ${pathOrObject}`);
15
+ }
16
+ }
17
+ else {
18
+ userConfig = pathOrObject;
19
+ }
20
+ /*
21
+ if (!ajv.validate(configSchema, userConfig)) {
22
+ ajv.errors!.forEach((err) => console.error(err));
23
+ throw new Error(`Your .emb.yml is incorrect`);
24
+ }
25
+ */
26
+ return toProjectConfig(userConfig);
27
+ };
@@ -0,0 +1,3 @@
1
+ import { EmbContext } from './types.js';
2
+ export declare const getContext: () => EmbContext;
3
+ export declare const setContext: (ctx: EmbContext) => void;
@@ -0,0 +1,7 @@
1
+ let context;
2
+ export const getContext = () => {
3
+ return context;
4
+ };
5
+ export const setContext = (ctx) => {
6
+ context = ctx;
7
+ };
@@ -0,0 +1,7 @@
1
+ export type DockerComposeOptions = {
2
+ cwd?: string;
3
+ };
4
+ export type UpOptions = DockerComposeOptions & {};
5
+ export declare const up: (opts?: UpOptions) => Promise<import("child_process").ChildProcessWithoutNullStreams>;
6
+ export type DownOptions = DockerComposeOptions & {};
7
+ export declare const down: (opts?: UpOptions) => Promise<import("child_process").ChildProcessWithoutNullStreams>;
@@ -0,0 +1,13 @@
1
+ import { spawn } from 'node:child_process';
2
+ export const up = async (opts) => {
3
+ return spawn('docker', ['compose', 'up', '-d'], {
4
+ cwd: opts?.cwd,
5
+ env: process.env,
6
+ });
7
+ };
8
+ export const down = async (opts) => {
9
+ return spawn('docker', ['compose', 'down'], {
10
+ cwd: opts?.cwd,
11
+ env: process.env,
12
+ });
13
+ };
@@ -0,0 +1,2 @@
1
+ import { Container } from 'dockerode';
2
+ export declare const getContainer: (id: string) => Promise<Container>;
@@ -0,0 +1,5 @@
1
+ import { getContext } from '../../index.js';
2
+ export const getContainer = async (id) => {
3
+ const { docker } = getContext();
4
+ return docker.getContainer(id);
5
+ };
@@ -0,0 +1 @@
1
+ export * from './getContainer.js';
@@ -0,0 +1 @@
1
+ export * from './getContainer.js';
@@ -0,0 +1,19 @@
1
+ import { Writable } from 'node:stream';
2
+ import { DockerComponentBuild } from '../index.js';
3
+ import { Component } from '../../monorepo/index.js';
4
+ export type MobyTrace = {
5
+ aux: unknown;
6
+ error?: string;
7
+ id: string;
8
+ };
9
+ export type Progress = {
10
+ error?: string;
11
+ name?: string;
12
+ };
13
+ export type DockerBuildExtraOptions = {
14
+ output?: Writable;
15
+ };
16
+ export type BuildDockerImageOutput = DockerComponentBuild & {
17
+ traces: Array<MobyTrace>;
18
+ };
19
+ export declare const buildDockerImage: (component: Component, opts?: DockerBuildExtraOptions, progress?: (progress: Progress) => void) => Promise<BuildDockerImageOutput | undefined>;
@@ -0,0 +1,64 @@
1
+ import { getContext } from '../../index.js';
2
+ import { decodeBuildkitStatusResponse, getSentinelFile, } from '../index.js';
3
+ import { FilePrerequisitePlugin } from '../../prerequisites/index.js';
4
+ export const buildDockerImage = async (component, opts = {}, progress) => {
5
+ const cmp = await component.toDockerBuild();
6
+ const files = (cmp.prerequisites || []).map((f) => f.path);
7
+ const { docker, monorepo } = getContext();
8
+ /** SENTINEL LOGIC */
9
+ // TODO: make configurable
10
+ const prereqPlugin = new FilePrerequisitePlugin();
11
+ const preBuildMeta = await prereqPlugin.meta(component, cmp.prerequisites, 'pre');
12
+ const sentinelFile = getSentinelFile(component);
13
+ let lastValue;
14
+ try {
15
+ lastValue = (await monorepo.store.readFile(sentinelFile)).toString();
16
+ }
17
+ catch {
18
+ lastValue = undefined;
19
+ }
20
+ if (lastValue) {
21
+ const diff = await prereqPlugin.diff(component, cmp.prerequisites, lastValue, preBuildMeta);
22
+ if (!diff) {
23
+ return;
24
+ }
25
+ }
26
+ const stream = await docker.buildImage({
27
+ context: cmp.context,
28
+ src: [...files],
29
+ }, {
30
+ buildargs: cmp.buildArgs,
31
+ dockerfile: cmp.dockerfile,
32
+ labels: cmp.labels,
33
+ t: cmp.name + ':' + (cmp.tag || 'latest'),
34
+ target: cmp.target,
35
+ version: '2',
36
+ });
37
+ if (opts.output) {
38
+ stream.pipe(opts.output);
39
+ }
40
+ stream.on('close', async () => {
41
+ const sentinelValue = await prereqPlugin.meta(component, cmp.prerequisites, 'post');
42
+ await monorepo.store.writeFile(sentinelFile, sentinelValue);
43
+ });
44
+ return new Promise((resolve, reject) => {
45
+ docker.modem.followProgress(stream, (err, traces) => {
46
+ return err ? reject(err) : resolve({ ...cmp, traces });
47
+ }, async (trace) => {
48
+ if (trace.error) {
49
+ reject(new Error(trace.error));
50
+ }
51
+ else {
52
+ try {
53
+ const { vertexes } = await decodeBuildkitStatusResponse(trace.aux);
54
+ vertexes.forEach((v) => {
55
+ progress?.(v);
56
+ });
57
+ }
58
+ catch (error) {
59
+ console.error(error);
60
+ }
61
+ }
62
+ });
63
+ });
64
+ };
@@ -0,0 +1,5 @@
1
+ export type ImageRemoveOptions = {
2
+ force?: boolean;
3
+ removeAnonymousVolumes?: boolean;
4
+ };
5
+ export declare const deleteImage: (name: string, opts?: ImageRemoveOptions) => Promise<unknown>;
@@ -0,0 +1,6 @@
1
+ import { getContext } from '../../index.js';
2
+ export const deleteImage = async (name, opts) => {
3
+ const { docker } = getContext();
4
+ const image = await docker.getImage(name);
5
+ return image.remove(opts);
6
+ };
@@ -0,0 +1,4 @@
1
+ export * from './buildImage.js';
2
+ export * from './deleteImage.js';
3
+ export * from './listImages.js';
4
+ export * from './pruneImages.js';
@@ -0,0 +1,4 @@
1
+ export * from './buildImage.js';
2
+ export * from './deleteImage.js';
3
+ export * from './listImages.js';
4
+ export * from './pruneImages.js';
@@ -0,0 +1,2 @@
1
+ import { ImageInfo, ListImagesOptions } from 'dockerode';
2
+ export declare const listImages: (opts?: ListImagesOptions) => Promise<Array<ImageInfo>>;
@@ -0,0 +1,8 @@
1
+ import { getContext } from '../../index.js';
2
+ export const listImages = async (opts) => {
3
+ const { docker } = getContext();
4
+ const images = await docker.listImages({
5
+ ...opts,
6
+ });
7
+ return images;
8
+ };
@@ -0,0 +1,6 @@
1
+ import { PruneImagesInfo } from 'dockerode';
2
+ export type PruneImagesOptions = {
3
+ dangling?: boolean;
4
+ label?: Array<string>;
5
+ };
6
+ export declare const pruneImages: (opts?: PruneImagesOptions) => Promise<PruneImagesInfo>;
@@ -0,0 +1,8 @@
1
+ import { getContext } from '../../index.js';
2
+ export const pruneImages = async (opts) => {
3
+ const { docker } = getContext();
4
+ const info = await docker.pruneImages({
5
+ ...opts,
6
+ });
7
+ return info;
8
+ };
@@ -0,0 +1,7 @@
1
+ export * from './compose/index.js';
2
+ export * from './containers/index.js';
3
+ export * from './images/index.js';
4
+ export * from './operations/index.js';
5
+ export * from './protobuf/index.js';
6
+ export * from './types.js';
7
+ export * from './utils.js';
@@ -0,0 +1,7 @@
1
+ export * from './compose/index.js';
2
+ export * from './containers/index.js';
3
+ export * from './images/index.js';
4
+ export * from './operations/index.js';
5
+ export * from './protobuf/index.js';
6
+ export * from './types.js';
7
+ export * from './utils.js';
@@ -0,0 +1,18 @@
1
+ import { ContainerInfo } from 'dockerode';
2
+ import * as z from 'zod';
3
+ import { AbstractOperation } from '../../../operations/index.js';
4
+ /**
5
+ * https://docs.docker.com/reference/api/engine/version/v1.37/#tag/Container/operation/ContainerList
6
+ */
7
+ declare const schema: z.ZodOptional<z.ZodObject<{
8
+ all: z.ZodOptional<z.ZodBoolean>;
9
+ filters: z.ZodOptional<z.ZodObject<{
10
+ label: z.ZodArray<z.ZodString>;
11
+ }, z.core.$strip>>;
12
+ limit: z.ZodOptional<z.ZodInt>;
13
+ }, z.core.$strip>>;
14
+ export declare class ListContainersOperation extends AbstractOperation<typeof schema, Array<ContainerInfo>> {
15
+ constructor();
16
+ protected _run(input: z.input<typeof schema>): Promise<Array<ContainerInfo>>;
17
+ }
18
+ export {};
@@ -0,0 +1,44 @@
1
+ import * as z from 'zod';
2
+ import { AbstractOperation } from '../../../operations/index.js';
3
+ /**
4
+ * https://docs.docker.com/reference/api/engine/version/v1.37/#tag/Container/operation/ContainerList
5
+ */
6
+ const schema = z
7
+ .object({
8
+ all: z
9
+ .boolean()
10
+ .optional()
11
+ .describe('Return all containers. By default, only running containers are shown'),
12
+ filters: z
13
+ .object({
14
+ label: z.array(z.string()).describe('Labels on the container'),
15
+ })
16
+ .optional()
17
+ .describe('Filters to process on the container list,'),
18
+ limit: z
19
+ .int()
20
+ .positive()
21
+ .optional()
22
+ .describe('Return this number of most recently created containers, including non-running ones.'),
23
+ })
24
+ .optional();
25
+ export class ListContainersOperation extends AbstractOperation {
26
+ constructor() {
27
+ super(schema);
28
+ }
29
+ async _run(input) {
30
+ let filters = {};
31
+ if (input?.filters?.label) {
32
+ filters.label = input.filters.label;
33
+ }
34
+ // Let's not even pass empty filters
35
+ if (Object.keys(filters).length === 0) {
36
+ filters = undefined;
37
+ }
38
+ return this.context.docker.listContainers({
39
+ all: input?.all,
40
+ filters,
41
+ limit: input?.limit,
42
+ });
43
+ }
44
+ }
@@ -0,0 +1,16 @@
1
+ import { PruneContainersInfo } from 'dockerode';
2
+ import * as z from 'zod';
3
+ import { AbstractOperation } from '../../../operations/index.js';
4
+ /**
5
+ * https://docs.docker.com/reference/api/engine/version/v1.37/#tag/Container/operation/ContainerPrune
6
+ */
7
+ declare const schema: z.ZodOptional<z.ZodObject<{
8
+ filters: z.ZodOptional<z.ZodObject<{
9
+ label: z.ZodArray<z.ZodString>;
10
+ }, z.core.$strip>>;
11
+ }, z.core.$strip>>;
12
+ export declare class PruneContainersOperation extends AbstractOperation<typeof schema, PruneContainersInfo> {
13
+ constructor();
14
+ protected _run(input: z.input<typeof schema>): Promise<PruneContainersInfo>;
15
+ }
16
+ export {};
@@ -0,0 +1,33 @@
1
+ import * as z from 'zod';
2
+ import { AbstractOperation } from '../../../operations/index.js';
3
+ /**
4
+ * https://docs.docker.com/reference/api/engine/version/v1.37/#tag/Container/operation/ContainerPrune
5
+ */
6
+ const schema = z
7
+ .object({
8
+ filters: z
9
+ .object({
10
+ label: z.array(z.string()).describe('Labels on the container'),
11
+ })
12
+ .optional()
13
+ .describe('Filters to process on the container list,'),
14
+ })
15
+ .optional();
16
+ export class PruneContainersOperation extends AbstractOperation {
17
+ constructor() {
18
+ super(schema);
19
+ }
20
+ async _run(input) {
21
+ let filters = {};
22
+ if (input?.filters?.label) {
23
+ filters.label = input.filters.label;
24
+ }
25
+ // Let's not even pass empty filters
26
+ if (Object.keys(filters).length === 0) {
27
+ filters = undefined;
28
+ }
29
+ return this.context.docker.pruneContainers({
30
+ filters,
31
+ });
32
+ }
33
+ }
@@ -0,0 +1,2 @@
1
+ export * from './ListContainersOperation.js';
2
+ export * from './PruneContainersOperation.js';
@@ -0,0 +1,2 @@
1
+ export * from './ListContainersOperation.js';
2
+ export * from './PruneContainersOperation.js';
@@ -0,0 +1,20 @@
1
+ import * as z from 'zod';
2
+ import { AbstractOperation } from '../../../operations/index.js';
3
+ /**
4
+ * https://docs.docker.com/reference/api/engine/version/v1.37/#tag/Image/operation/ImageBuild
5
+ */
6
+ declare const schema: z.ZodObject<{
7
+ buildArgs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
8
+ context: z.ZodString;
9
+ dockerfile: z.ZodString;
10
+ labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
11
+ src: z.ZodArray<z.ZodString>;
12
+ tag: z.ZodString;
13
+ target: z.ZodOptional<z.ZodString>;
14
+ }, z.core.$strip>;
15
+ export declare class BuildImageOperation extends AbstractOperation<typeof schema, Array<unknown>> {
16
+ private observer?;
17
+ constructor(observer?: ((progress: string) => void) | undefined);
18
+ protected _run(input: z.input<typeof schema>): Promise<Array<unknown>>;
19
+ }
20
+ export {};
@@ -0,0 +1,69 @@
1
+ import * as z from 'zod';
2
+ import { decodeBuildkitStatusResponse } from '../../index.js';
3
+ import { AbstractOperation } from '../../../operations/index.js';
4
+ /**
5
+ * https://docs.docker.com/reference/api/engine/version/v1.37/#tag/Image/operation/ImageBuild
6
+ */
7
+ const schema = z.object({
8
+ buildArgs: z
9
+ .record(z.string(), z.string())
10
+ .optional()
11
+ .describe('Map of string pairs for build-time variables'),
12
+ context: z.string().describe('Path to the build context'),
13
+ dockerfile: z
14
+ .string()
15
+ .describe('Path within the build context to the Dockerfile.'),
16
+ labels: z
17
+ .record(z.string(), z.string())
18
+ .optional()
19
+ .describe('Arbitrary key/value labels to set on the image, as a JSON map of string pairs.'),
20
+ src: z.array(z.string()),
21
+ tag: z.z
22
+ .string()
23
+ .describe('A name and optional tag to apply to the image in the name:tag'),
24
+ target: z.string().optional().describe('Target build stage'),
25
+ });
26
+ export class BuildImageOperation extends AbstractOperation {
27
+ observer;
28
+ constructor(observer) {
29
+ super(schema);
30
+ this.observer = observer;
31
+ }
32
+ async _run(input) {
33
+ const logStream = await this.context.monorepo.store.createWriteStream(`logs/docker/build/${input.tag}.log`);
34
+ const stream = await this.context.docker.buildImage({
35
+ context: input.context,
36
+ src: [...input.src],
37
+ }, {
38
+ buildargs: input.buildArgs,
39
+ dockerfile: input.dockerfile,
40
+ labels: input.labels,
41
+ t: input.tag,
42
+ target: input.target,
43
+ version: '2',
44
+ });
45
+ return new Promise((resolve, reject) => {
46
+ this.context.docker.modem.followProgress(stream, (err, traces) => {
47
+ logStream.close();
48
+ return err ? reject(err) : resolve(traces);
49
+ }, async (trace) => {
50
+ if (trace.error) {
51
+ logStream.close();
52
+ reject(new Error(trace.error));
53
+ }
54
+ else {
55
+ try {
56
+ const { vertexes } = await decodeBuildkitStatusResponse(trace.aux);
57
+ vertexes.forEach((v) => {
58
+ logStream.write(JSON.stringify(v) + '\n');
59
+ this.observer?.(v.name);
60
+ });
61
+ }
62
+ catch (error) {
63
+ console.error(error);
64
+ }
65
+ }
66
+ });
67
+ });
68
+ }
69
+ }
@@ -0,0 +1,17 @@
1
+ import { ImageInfo } from 'dockerode';
2
+ import * as z from 'zod';
3
+ import { AbstractOperation } from '../../../operations/index.js';
4
+ /**
5
+ * https://docs.docker.com/reference/api/engine/version/v1.37/#tag/Image/operation/ImageList
6
+ */
7
+ declare const schema: z.ZodOptional<z.ZodObject<{
8
+ all: z.ZodOptional<z.ZodBoolean>;
9
+ filters: z.ZodOptional<z.ZodObject<{
10
+ label: z.ZodArray<z.ZodString>;
11
+ }, z.core.$strip>>;
12
+ }, z.core.$strip>>;
13
+ export declare class ListImagesOperation extends AbstractOperation<typeof schema, Array<ImageInfo>> {
14
+ constructor();
15
+ protected _run(input: z.input<typeof schema>): Promise<Array<ImageInfo>>;
16
+ }
17
+ export {};
@@ -0,0 +1,38 @@
1
+ import * as z from 'zod';
2
+ import { AbstractOperation } from '../../../operations/index.js';
3
+ /**
4
+ * https://docs.docker.com/reference/api/engine/version/v1.37/#tag/Image/operation/ImageList
5
+ */
6
+ const schema = z
7
+ .object({
8
+ all: z
9
+ .boolean()
10
+ .optional()
11
+ .describe('Show all images. Only images from a final layer (no children) are shown by default.'),
12
+ filters: z
13
+ .object({
14
+ label: z.array(z.string()).describe('Labels on the images'),
15
+ })
16
+ .optional()
17
+ .describe('Filters to process on the images list,'),
18
+ })
19
+ .optional();
20
+ export class ListImagesOperation extends AbstractOperation {
21
+ constructor() {
22
+ super(schema);
23
+ }
24
+ async _run(input) {
25
+ let filters = {};
26
+ if (input?.filters?.label) {
27
+ filters.label = input.filters.label;
28
+ }
29
+ // Let's not even pass empty filters
30
+ if (Object.keys(filters).length === 0) {
31
+ filters = undefined;
32
+ }
33
+ return this.context.docker.listImages({
34
+ all: input?.all,
35
+ filters,
36
+ });
37
+ }
38
+ }
@@ -0,0 +1,16 @@
1
+ import { PruneImagesInfo } from 'dockerode';
2
+ import * as z from 'zod';
3
+ import { AbstractOperation } from '../../../operations/index.js';
4
+ /**
5
+ * https://docs.docker.com/reference/api/engine/version/v1.37/#tag/Image/operation/ImagePrune
6
+ */
7
+ declare const schema: z.ZodOptional<z.ZodObject<{
8
+ filters: z.ZodOptional<z.ZodObject<{
9
+ label: z.ZodArray<z.ZodString>;
10
+ }, z.core.$strip>>;
11
+ }, z.core.$strip>>;
12
+ export declare class PruneImagesOperation extends AbstractOperation<typeof schema, PruneImagesInfo> {
13
+ constructor();
14
+ protected _run(input: z.input<typeof schema>): Promise<PruneImagesInfo>;
15
+ }
16
+ export {};
@@ -0,0 +1,33 @@
1
+ import * as z from 'zod';
2
+ import { AbstractOperation } from '../../../operations/index.js';
3
+ /**
4
+ * https://docs.docker.com/reference/api/engine/version/v1.37/#tag/Image/operation/ImagePrune
5
+ */
6
+ const schema = z
7
+ .object({
8
+ filters: z
9
+ .object({
10
+ label: z.array(z.string()).describe('Labels on the images'),
11
+ })
12
+ .optional()
13
+ .describe('Filters to process on the images list,'),
14
+ })
15
+ .optional();
16
+ export class PruneImagesOperation extends AbstractOperation {
17
+ constructor() {
18
+ super(schema);
19
+ }
20
+ async _run(input) {
21
+ let filters = {};
22
+ if (input?.filters?.label) {
23
+ filters.label = input.filters.label;
24
+ }
25
+ // Let's not even pass empty filters
26
+ if (Object.keys(filters).length === 0) {
27
+ filters = undefined;
28
+ }
29
+ return this.context.docker.pruneImages({
30
+ filters,
31
+ });
32
+ }
33
+ }
@@ -0,0 +1,3 @@
1
+ export * from './BuildImageOperation.js';
2
+ export * from './ListImagesOperation.js';
3
+ export * from './PruneImagesOperation.js';
@@ -0,0 +1,3 @@
1
+ export * from './BuildImageOperation.js';
2
+ export * from './ListImagesOperation.js';
3
+ export * from './PruneImagesOperation.js';
@@ -0,0 +1,2 @@
1
+ export * from './containers/index.js';
2
+ export * from './images/index.js';
@@ -0,0 +1,2 @@
1
+ export * from './containers/index.js';
2
+ export * from './images/index.js';
@@ -0,0 +1,48 @@
1
+ syntax = "proto3";
2
+
3
+ package moby.buildkit.v1;
4
+
5
+ import "google/protobuf/timestamp.proto";
6
+
7
+ message StatusResponse {
8
+ repeated Vertex vertexes = 1;
9
+ repeated VertexStatus statuses = 2;
10
+ repeated VertexLog logs = 3;
11
+ repeated VertexWarning warnings = 4;
12
+ }
13
+
14
+ message Vertex {
15
+ string digest = 1;
16
+ repeated string inputs = 2;
17
+ string name = 3;
18
+ bool cached = 4;
19
+ google.protobuf.Timestamp started = 5;
20
+ google.protobuf.Timestamp completed = 6;
21
+ string error = 7; // typed errors?
22
+ }
23
+
24
+ message VertexStatus {
25
+ string ID = 1;
26
+ string vertex = 2;
27
+ string name = 3;
28
+ int64 current = 4;
29
+ int64 total = 5;
30
+ google.protobuf.Timestamp timestamp = 6;
31
+ google.protobuf.Timestamp started = 7;
32
+ google.protobuf.Timestamp completed = 8;
33
+ }
34
+
35
+ message VertexLog {
36
+ string vertex = 1;
37
+ google.protobuf.Timestamp timestamp = 2;
38
+ int64 stream = 3;
39
+ bytes msg = 4;
40
+ }
41
+
42
+ message VertexWarning {
43
+ string vertex = 1;
44
+ int64 level = 2;
45
+ bytes short = 3;
46
+ repeated bytes detail = 4;
47
+ string url = 5;
48
+ }
@@ -0,0 +1,5 @@
1
+ import protobuf from 'protobufjs';
2
+ export declare const loadControl: () => Promise<protobuf.Root>;
3
+ export declare const decodeBuildkitStatusResponse: (str: Buffer | string) => Promise<{
4
+ [k: string]: any;
5
+ }>;