@enspirit/emb 0.0.5 → 0.0.7
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/README.md +61 -31
- package/dist/src/cli/commands/clean.d.ts +3 -1
- package/dist/src/cli/commands/clean.js +13 -2
- package/dist/src/cli/commands/components/build.d.ts +6 -2
- package/dist/src/cli/commands/components/build.js +16 -7
- package/dist/src/cli/commands/config/print.js +2 -3
- package/dist/src/cli/commands/down.d.ts +2 -2
- package/dist/src/cli/commands/down.js +5 -25
- package/dist/src/cli/commands/tasks/index.js +11 -5
- package/dist/src/cli/commands/tasks/run.d.ts +1 -3
- package/dist/src/cli/commands/tasks/run.js +11 -93
- package/dist/src/cli/commands/up.d.ts +1 -1
- package/dist/src/cli/commands/up.js +12 -34
- package/dist/src/config/convert.d.ts +2 -3
- package/dist/src/config/convert.js +4 -11
- package/dist/src/config/index.d.ts +1 -0
- package/dist/src/config/index.js +1 -0
- package/dist/src/config/schema.d.ts +36 -29
- package/dist/src/config/schema.json +42 -25
- package/dist/src/config/types.d.ts +11 -7
- package/dist/src/config/validation.d.ts +2 -0
- package/dist/src/config/validation.js +26 -1
- package/dist/src/docker/compose/index.d.ts +1 -7
- package/dist/src/docker/compose/index.js +1 -13
- package/dist/src/docker/compose/operations/ComposeDownOperation.d.ts +12 -0
- package/dist/src/docker/compose/operations/ComposeDownOperation.js +21 -0
- package/dist/src/docker/compose/operations/ComposeUpOperation.d.ts +13 -0
- package/dist/src/docker/compose/operations/ComposeUpOperation.js +39 -0
- package/dist/src/docker/compose/operations/index.d.ts +2 -0
- package/dist/src/docker/compose/operations/index.js +2 -0
- package/dist/src/docker/operations/containers/ExecContainerOperation.d.ts +22 -0
- package/dist/src/docker/operations/containers/ExecContainerOperation.js +78 -0
- package/dist/src/docker/operations/containers/index.d.ts +1 -0
- package/dist/src/docker/operations/containers/index.js +1 -0
- package/dist/src/monorepo/component.d.ts +2 -2
- package/dist/src/monorepo/component.js +6 -6
- package/dist/src/monorepo/config.d.ts +6 -3
- package/dist/src/monorepo/config.js +22 -4
- package/dist/src/monorepo/index.d.ts +2 -0
- package/dist/src/monorepo/index.js +2 -0
- package/dist/src/monorepo/monorepo.d.ts +4 -2
- package/dist/src/monorepo/monorepo.js +30 -6
- package/dist/src/monorepo/operations/components/BuildComponentsOperation.d.ts +11 -2
- package/dist/src/monorepo/operations/components/BuildComponentsOperation.js +45 -59
- package/dist/src/monorepo/operations/components/GetComponentContainerOperation.d.ts +6 -0
- package/dist/src/monorepo/operations/components/GetComponentContainerOperation.js +21 -0
- package/dist/src/monorepo/operations/components/index.d.ts +1 -0
- package/dist/src/monorepo/operations/components/index.js +1 -0
- package/dist/src/monorepo/operations/index.d.ts +2 -0
- package/dist/src/monorepo/operations/index.js +2 -0
- package/dist/src/monorepo/operations/shell/ExecuteLocalCommandOperation.d.ts +16 -0
- package/dist/src/monorepo/operations/shell/ExecuteLocalCommandOperation.js +30 -0
- package/dist/src/monorepo/operations/shell/index.d.ts +1 -0
- package/dist/src/monorepo/operations/shell/index.js +1 -0
- package/dist/src/monorepo/operations/tasks/RunTasksOperation.d.ts +21 -0
- package/dist/src/monorepo/operations/tasks/RunTasksOperation.js +84 -0
- package/dist/src/monorepo/operations/tasks/index.d.ts +1 -0
- package/dist/src/monorepo/operations/tasks/index.js +1 -0
- package/dist/src/monorepo/plugins/ComponentDiscoverPlugin.d.ts +15 -0
- package/dist/src/monorepo/plugins/{ComponentsDiscover.js → ComponentDiscoverPlugin.js} +16 -2
- package/dist/src/monorepo/plugins/EmbfileLoaderPlugin.d.ts +14 -0
- package/dist/src/monorepo/plugins/EmbfileLoaderPlugin.js +37 -0
- package/dist/src/monorepo/plugins/index.d.ts +3 -2
- package/dist/src/monorepo/plugins/index.js +5 -2
- package/dist/src/monorepo/store/index.js +5 -3
- package/dist/src/monorepo/taskManagerFactory.d.ts +3 -0
- package/dist/src/monorepo/taskManagerFactory.js +20 -0
- package/dist/src/monorepo/types.d.ts +2 -1
- package/dist/src/monorepo/utils/findRunOrder.d.ts +34 -0
- package/dist/src/monorepo/utils/findRunOrder.js +165 -0
- package/dist/src/monorepo/utils/index.d.ts +1 -1
- package/dist/src/monorepo/utils/index.js +1 -1
- package/dist/src/operations/abstract/AbstractOperation.d.ts +1 -1
- package/dist/src/utils/deepMergeArray.d.ts +3 -0
- package/dist/src/utils/deepMergeArray.js +1 -0
- package/oclif.manifest.json +63 -74
- package/package.json +4 -2
- package/dist/src/cli/commands/run/index.d.ts +0 -10
- package/dist/src/cli/commands/run/index.js +0 -49
- package/dist/src/executors/docker.d.ts +0 -6
- package/dist/src/executors/docker.js +0 -14
- package/dist/src/executors/index.d.ts +0 -6
- package/dist/src/executors/index.js +0 -7
- package/dist/src/executors/shell.d.ts +0 -2
- package/dist/src/executors/shell.js +0 -14
- package/dist/src/executors/types.d.ts +0 -8
- package/dist/src/executors/types.js +0 -1
- package/dist/src/monorepo/plugins/ComponentsDiscover.d.ts +0 -6
- package/dist/src/monorepo/utils/findBuildOrder.d.ts +0 -2
- package/dist/src/monorepo/utils/findBuildOrder.js +0 -41
|
@@ -3,32 +3,18 @@
|
|
|
3
3
|
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
4
4
|
* and run json-schema-to-typescript to regenerate this file.
|
|
5
5
|
*/
|
|
6
|
-
export type
|
|
7
|
-
/**
|
|
8
|
-
* The name of the component.
|
|
9
|
-
*/
|
|
6
|
+
export type Task = Task1 & {
|
|
10
7
|
name: string;
|
|
11
|
-
/**
|
|
12
|
-
* The directory of the component.
|
|
13
|
-
*/
|
|
14
|
-
context?: string;
|
|
15
|
-
/**
|
|
16
|
-
* A description of the component.
|
|
17
|
-
*/
|
|
18
8
|
description?: string;
|
|
19
|
-
|
|
9
|
+
script?: string;
|
|
10
|
+
executor?: string;
|
|
11
|
+
options?: {
|
|
20
12
|
[k: string]: unknown;
|
|
21
13
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
target?: string;
|
|
27
|
-
/**
|
|
28
|
-
* The Dockerfile to use
|
|
29
|
-
*/
|
|
30
|
-
dockerfile?: string;
|
|
31
|
-
tasks?: Task[];
|
|
14
|
+
pre?: string[];
|
|
15
|
+
};
|
|
16
|
+
export type Task1 = {
|
|
17
|
+
[k: string]: unknown;
|
|
32
18
|
};
|
|
33
19
|
export interface EMBConfigSchema {
|
|
34
20
|
project: string | {
|
|
@@ -60,6 +46,7 @@ export interface EMBConfigSchema {
|
|
|
60
46
|
defaults?: Defaults;
|
|
61
47
|
components?: Component[];
|
|
62
48
|
flavors?: Flavor[];
|
|
49
|
+
tasks?: Task[];
|
|
63
50
|
}
|
|
64
51
|
/**
|
|
65
52
|
* Default settings for build aspects
|
|
@@ -72,7 +59,7 @@ export interface Defaults {
|
|
|
72
59
|
tag?: string;
|
|
73
60
|
target?: string;
|
|
74
61
|
buildArgs?: {
|
|
75
|
-
[k: string]:
|
|
62
|
+
[k: string]: string;
|
|
76
63
|
};
|
|
77
64
|
labels?: {
|
|
78
65
|
[k: string]: string;
|
|
@@ -80,14 +67,34 @@ export interface Defaults {
|
|
|
80
67
|
[k: string]: unknown;
|
|
81
68
|
};
|
|
82
69
|
}
|
|
83
|
-
export interface
|
|
70
|
+
export interface Component {
|
|
71
|
+
/**
|
|
72
|
+
* The name of the component.
|
|
73
|
+
*/
|
|
84
74
|
name: string;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
75
|
+
docker?: {
|
|
76
|
+
/**
|
|
77
|
+
* The directory of the component.
|
|
78
|
+
*/
|
|
79
|
+
context?: string;
|
|
80
|
+
buildArgs?: {
|
|
81
|
+
[k: string]: string;
|
|
82
|
+
};
|
|
83
|
+
dependencies?: string[];
|
|
84
|
+
/**
|
|
85
|
+
* The stage to target for the build
|
|
86
|
+
*/
|
|
87
|
+
target?: string;
|
|
88
|
+
/**
|
|
89
|
+
* The Dockerfile to use
|
|
90
|
+
*/
|
|
91
|
+
dockerfile?: string;
|
|
90
92
|
};
|
|
93
|
+
/**
|
|
94
|
+
* A description of the component.
|
|
95
|
+
*/
|
|
96
|
+
description?: string;
|
|
97
|
+
tasks?: Task[];
|
|
91
98
|
}
|
|
92
99
|
export interface Flavor {
|
|
93
100
|
name: string;
|
|
@@ -70,6 +70,12 @@
|
|
|
70
70
|
"items": {
|
|
71
71
|
"$ref": "#/$defs/flavor"
|
|
72
72
|
}
|
|
73
|
+
},
|
|
74
|
+
"tasks": {
|
|
75
|
+
"type": "array",
|
|
76
|
+
"items": {
|
|
77
|
+
"$ref": "#/$defs/task"
|
|
78
|
+
}
|
|
73
79
|
}
|
|
74
80
|
},
|
|
75
81
|
"required": ["project"],
|
|
@@ -88,7 +94,9 @@
|
|
|
88
94
|
"target": { "type": "string" },
|
|
89
95
|
"buildArgs": {
|
|
90
96
|
"type": "object",
|
|
91
|
-
"additionalProperties":
|
|
97
|
+
"additionalProperties": {
|
|
98
|
+
"type": "string"
|
|
99
|
+
}
|
|
92
100
|
},
|
|
93
101
|
"labels": {
|
|
94
102
|
"type": "object",
|
|
@@ -102,7 +110,11 @@
|
|
|
102
110
|
},
|
|
103
111
|
"task": {
|
|
104
112
|
"type": "object",
|
|
105
|
-
"required": ["name"
|
|
113
|
+
"required": ["name"],
|
|
114
|
+
"anyOf": [
|
|
115
|
+
{ "required": ["script"] },
|
|
116
|
+
{ "required": ["pre"] }
|
|
117
|
+
],
|
|
106
118
|
"properties": {
|
|
107
119
|
"name": {
|
|
108
120
|
"type": "string"
|
|
@@ -119,40 +131,39 @@
|
|
|
119
131
|
"options": {
|
|
120
132
|
"type": "object",
|
|
121
133
|
"additionalProperties": true
|
|
134
|
+
},
|
|
135
|
+
"pre": {
|
|
136
|
+
"type": "array",
|
|
137
|
+
"items": {
|
|
138
|
+
"type": "string"
|
|
139
|
+
}
|
|
122
140
|
}
|
|
123
141
|
},
|
|
124
142
|
"additionalProperties": false
|
|
125
143
|
},
|
|
126
144
|
"component": {
|
|
127
|
-
"
|
|
128
|
-
|
|
145
|
+
"type": "object",
|
|
146
|
+
"required": ["name"],
|
|
147
|
+
"properties": {
|
|
148
|
+
"name": {
|
|
129
149
|
"type": "string",
|
|
130
150
|
"minLength": 3,
|
|
131
|
-
"description": "
|
|
151
|
+
"description": "The name of the component."
|
|
132
152
|
},
|
|
133
|
-
{
|
|
153
|
+
"docker": {
|
|
134
154
|
"type": "object",
|
|
135
|
-
"required": ["name"],
|
|
136
155
|
"properties": {
|
|
137
|
-
"name": {
|
|
138
|
-
"type": "string",
|
|
139
|
-
"minLength": 3,
|
|
140
|
-
"description": "The name of the component."
|
|
141
|
-
},
|
|
142
156
|
"context": {
|
|
143
157
|
"type": "string",
|
|
144
158
|
"minLength": 1,
|
|
145
159
|
"description": "The directory of the component."
|
|
146
160
|
},
|
|
147
|
-
"description": {
|
|
148
|
-
"type": "string",
|
|
149
|
-
"minLength": 1,
|
|
150
|
-
"description": "A description of the component."
|
|
151
|
-
},
|
|
152
161
|
"buildArgs": {
|
|
153
162
|
"type": "object",
|
|
154
163
|
"properties": {},
|
|
155
|
-
"additionalProperties":
|
|
164
|
+
"additionalProperties": {
|
|
165
|
+
"type": "string"
|
|
166
|
+
}
|
|
156
167
|
},
|
|
157
168
|
"dependencies": {
|
|
158
169
|
"type": "array",
|
|
@@ -167,17 +178,23 @@
|
|
|
167
178
|
"dockerfile": {
|
|
168
179
|
"type": "string",
|
|
169
180
|
"description": "The Dockerfile to use"
|
|
170
|
-
},
|
|
171
|
-
"tasks": {
|
|
172
|
-
"type": "array",
|
|
173
|
-
"items": {
|
|
174
|
-
"$ref": "#/$defs/task"
|
|
175
|
-
}
|
|
176
181
|
}
|
|
177
182
|
},
|
|
178
183
|
"additionalProperties": false
|
|
184
|
+
},
|
|
185
|
+
"description": {
|
|
186
|
+
"type": "string",
|
|
187
|
+
"minLength": 1,
|
|
188
|
+
"description": "A description of the component."
|
|
189
|
+
},
|
|
190
|
+
"tasks": {
|
|
191
|
+
"type": "array",
|
|
192
|
+
"items": {
|
|
193
|
+
"$ref": "#/$defs/task"
|
|
194
|
+
}
|
|
179
195
|
}
|
|
180
|
-
|
|
196
|
+
},
|
|
197
|
+
"additionalProperties": false
|
|
181
198
|
},
|
|
182
199
|
"flavor": {
|
|
183
200
|
"type": "object",
|
|
@@ -5,18 +5,20 @@ export type IProjectConfig = {
|
|
|
5
5
|
rootDir: string;
|
|
6
6
|
};
|
|
7
7
|
export type ComponentConfig = {
|
|
8
|
-
buildArgs?: Record<PropertyKey, string>;
|
|
9
|
-
context?: string;
|
|
10
|
-
dependencies?: Array<string>;
|
|
11
|
-
dockerfile?: string;
|
|
12
|
-
labels?: Record<string, string>;
|
|
13
8
|
name: string;
|
|
14
|
-
|
|
9
|
+
docker?: {
|
|
10
|
+
buildArgs?: Record<string, string>;
|
|
11
|
+
context?: string;
|
|
12
|
+
dependencies?: Array<string>;
|
|
13
|
+
dockerfile?: string;
|
|
14
|
+
labels?: Record<string, string>;
|
|
15
|
+
target?: string;
|
|
16
|
+
};
|
|
15
17
|
tasks?: Array<Task>;
|
|
16
18
|
};
|
|
17
19
|
export type DefaultSettings = {
|
|
18
20
|
docker?: {
|
|
19
|
-
buildArgs?: Record<string,
|
|
21
|
+
buildArgs?: Record<string, string>;
|
|
20
22
|
labels?: Record<string, string>;
|
|
21
23
|
tag?: string;
|
|
22
24
|
target?: string;
|
|
@@ -33,11 +35,13 @@ export type PluginConfig = {
|
|
|
33
35
|
name: string;
|
|
34
36
|
};
|
|
35
37
|
export type IMonorepoConfig = {
|
|
38
|
+
currentFlavor?: string;
|
|
36
39
|
components: Array<ComponentConfig>;
|
|
37
40
|
defaults?: DefaultSettings;
|
|
38
41
|
env?: Record<string, string>;
|
|
39
42
|
flavors?: Array<FlavorConfig>;
|
|
40
43
|
plugins?: Array<PluginConfig>;
|
|
41
44
|
project: IProjectConfig;
|
|
45
|
+
tasks?: Array<Task>;
|
|
42
46
|
vars?: Record<string, unknown>;
|
|
43
47
|
};
|
|
@@ -3,8 +3,9 @@ import { readFile, stat } from 'node:fs/promises';
|
|
|
3
3
|
import yaml from 'yaml';
|
|
4
4
|
import { toProjectConfig } from './convert.js';
|
|
5
5
|
import configSchema from './schema.json' with { type: 'json' };
|
|
6
|
+
const ajv = new Ajv();
|
|
7
|
+
ajv.addSchema(configSchema);
|
|
6
8
|
export const validateUserConfig = async (pathOrObject) => {
|
|
7
|
-
const ajv = new Ajv();
|
|
8
9
|
let userConfig;
|
|
9
10
|
if (typeof pathOrObject === 'string') {
|
|
10
11
|
if (await stat(pathOrObject)) {
|
|
@@ -24,3 +25,27 @@ export const validateUserConfig = async (pathOrObject) => {
|
|
|
24
25
|
}
|
|
25
26
|
return toProjectConfig(userConfig);
|
|
26
27
|
};
|
|
28
|
+
export const validateEmbfile = async (pathOrObject) => {
|
|
29
|
+
let component;
|
|
30
|
+
if (typeof pathOrObject === 'string') {
|
|
31
|
+
if (await stat(pathOrObject)) {
|
|
32
|
+
const cfgYaml = (await readFile(pathOrObject)).toString();
|
|
33
|
+
component = yaml.parse(cfgYaml.toString());
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
throw new Error(`Could not find file: ${pathOrObject}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
component = pathOrObject;
|
|
41
|
+
}
|
|
42
|
+
const validate = ajv.getSchema('/schemas/config#/$defs/component');
|
|
43
|
+
if (!validate) {
|
|
44
|
+
throw new Error('Could not find the JSON schema validator for Embfile');
|
|
45
|
+
}
|
|
46
|
+
if (!validate(component)) {
|
|
47
|
+
ajv.errors.forEach((err) => console.error(err));
|
|
48
|
+
throw new Error(`Your .emb.yml is incorrect`);
|
|
49
|
+
}
|
|
50
|
+
return component;
|
|
51
|
+
};
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
export
|
|
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>;
|
|
1
|
+
export * from './operations/index.js';
|
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
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
|
-
};
|
|
1
|
+
export * from './operations/index.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Readable } from 'node:stream';
|
|
2
|
+
import * as z from 'zod';
|
|
3
|
+
import { AbstractOperation } from '../../../operations/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* https://docs.docker.com/reference/cli/docker/compose/down/
|
|
6
|
+
*/
|
|
7
|
+
declare const schema: z.ZodOptional<z.ZodObject<{}, z.core.$strip>>;
|
|
8
|
+
export declare class ComposeDownOperation extends AbstractOperation<typeof schema, Readable> {
|
|
9
|
+
constructor();
|
|
10
|
+
protected _run(_input: z.input<typeof schema>): Promise<Readable>;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getContext } from '../../../index.js';
|
|
2
|
+
import * as z from 'zod';
|
|
3
|
+
import { ExecuteLocalCommandOperation } from '../../../monorepo/index.js';
|
|
4
|
+
import { AbstractOperation } from '../../../operations/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* https://docs.docker.com/reference/cli/docker/compose/down/
|
|
7
|
+
*/
|
|
8
|
+
const schema = z.object({}).optional();
|
|
9
|
+
export class ComposeDownOperation extends AbstractOperation {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(schema);
|
|
12
|
+
}
|
|
13
|
+
async _run(_input) {
|
|
14
|
+
const { monorepo } = getContext();
|
|
15
|
+
const command = ['docker', 'compose', 'down'];
|
|
16
|
+
return monorepo.run(new ExecuteLocalCommandOperation(), {
|
|
17
|
+
script: command.join(' '),
|
|
18
|
+
workingDir: monorepo.rootDir,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import { AbstractOperation } from '../../../operations/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* https://docs.docker.com/reference/cli/docker/compose/up/
|
|
5
|
+
*/
|
|
6
|
+
declare const schema: z.ZodOptional<z.ZodObject<{
|
|
7
|
+
forceRecreate: z.ZodOptional<z.ZodBoolean>;
|
|
8
|
+
}, z.core.$strip>>;
|
|
9
|
+
export declare class ComposeUpOperation extends AbstractOperation<typeof schema, void> {
|
|
10
|
+
constructor();
|
|
11
|
+
protected _run(input: z.input<typeof schema>): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getContext } from '../../../index.js';
|
|
2
|
+
import { Listr } from 'listr2';
|
|
3
|
+
import * as z from 'zod';
|
|
4
|
+
import { ExecuteLocalCommandOperation } from '../../../monorepo/index.js';
|
|
5
|
+
import { AbstractOperation } from '../../../operations/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* https://docs.docker.com/reference/cli/docker/compose/up/
|
|
8
|
+
*/
|
|
9
|
+
const schema = z
|
|
10
|
+
.object({
|
|
11
|
+
forceRecreate: z
|
|
12
|
+
.boolean()
|
|
13
|
+
.optional()
|
|
14
|
+
.describe("Recreate containers even if their configuration and image haven't changed"),
|
|
15
|
+
})
|
|
16
|
+
.optional();
|
|
17
|
+
export class ComposeUpOperation extends AbstractOperation {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(schema);
|
|
20
|
+
}
|
|
21
|
+
async _run(input) {
|
|
22
|
+
const { monorepo } = getContext();
|
|
23
|
+
const command = ['docker', 'compose', 'up', '-d'];
|
|
24
|
+
if (input?.forceRecreate) {
|
|
25
|
+
command.push('--force-recreate');
|
|
26
|
+
}
|
|
27
|
+
const task = new Listr({
|
|
28
|
+
rendererOptions: { persistentOutput: true },
|
|
29
|
+
async task() {
|
|
30
|
+
return monorepo.run(new ExecuteLocalCommandOperation(), {
|
|
31
|
+
script: command.join(' '),
|
|
32
|
+
workingDir: monorepo.rootDir,
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
title: 'Starting project',
|
|
36
|
+
});
|
|
37
|
+
await task.run();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Writable } from 'node:stream';
|
|
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/Exec/operation/ContainerExec
|
|
6
|
+
*/
|
|
7
|
+
declare const schema: z.ZodObject<{
|
|
8
|
+
attachStderr: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
9
|
+
attachStdin: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
10
|
+
attachStdout: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
11
|
+
container: z.ZodString;
|
|
12
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
13
|
+
script: z.ZodString;
|
|
14
|
+
tty: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
15
|
+
workingDir: z.ZodOptional<z.ZodString>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
export declare class ContainerExecOperation extends AbstractOperation<typeof schema, void> {
|
|
18
|
+
protected out?: Writable | undefined;
|
|
19
|
+
constructor(out?: Writable | undefined);
|
|
20
|
+
protected _run(input: z.input<typeof schema>): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
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/Exec/operation/ContainerExec
|
|
5
|
+
*/
|
|
6
|
+
const schema = z.object({
|
|
7
|
+
attachStderr: z
|
|
8
|
+
.boolean()
|
|
9
|
+
.default(false)
|
|
10
|
+
.optional()
|
|
11
|
+
.describe('Attach to `stderr` of the exec command.'),
|
|
12
|
+
attachStdin: z
|
|
13
|
+
.boolean()
|
|
14
|
+
.default(false)
|
|
15
|
+
.optional()
|
|
16
|
+
.describe('Attach to `stdin` of the exec command.'),
|
|
17
|
+
attachStdout: z
|
|
18
|
+
.boolean()
|
|
19
|
+
.default(false)
|
|
20
|
+
.optional()
|
|
21
|
+
.describe('Attach to `stdout` of the exec command.'),
|
|
22
|
+
container: z.string().describe('ID or name of the container'),
|
|
23
|
+
env: z
|
|
24
|
+
.record(z.string(), z.string())
|
|
25
|
+
.optional()
|
|
26
|
+
.describe('A list of environment variables in the form'),
|
|
27
|
+
script: z.string().describe('Command to run, as a string'),
|
|
28
|
+
tty: z.boolean().default(false).optional().describe('Allocate a pseudo-TTY'),
|
|
29
|
+
workingDir: z
|
|
30
|
+
.string()
|
|
31
|
+
.optional()
|
|
32
|
+
.describe('The working directory for the exec process inside the container'),
|
|
33
|
+
});
|
|
34
|
+
export class ContainerExecOperation extends AbstractOperation {
|
|
35
|
+
out;
|
|
36
|
+
constructor(out) {
|
|
37
|
+
super(schema);
|
|
38
|
+
this.out = out;
|
|
39
|
+
}
|
|
40
|
+
async _run(input) {
|
|
41
|
+
const container = await this.context.docker.getContainer(input.container);
|
|
42
|
+
const envVars = Object.entries(input.env || {}).reduce((arr, [key, value]) => {
|
|
43
|
+
return [...arr, `${key}=${value}`];
|
|
44
|
+
}, []);
|
|
45
|
+
const options = {
|
|
46
|
+
AttachStderr: input.attachStderr,
|
|
47
|
+
AttachStdin: input.attachStdin,
|
|
48
|
+
AttachStdout: input.attachStdout,
|
|
49
|
+
Cmd: ['bash', '-eu', '-o', 'pipefail', '-c', input.script],
|
|
50
|
+
Env: envVars,
|
|
51
|
+
Tty: input.tty,
|
|
52
|
+
WorkingDir: input.workingDir,
|
|
53
|
+
};
|
|
54
|
+
const exec = await container.exec(options);
|
|
55
|
+
const stream = await exec.start({});
|
|
56
|
+
container.modem.demuxStream(stream, this.out || process.stdout, this.out || process.stderr);
|
|
57
|
+
await new Promise((resolve, reject) => {
|
|
58
|
+
const onError = (err) => reject(err);
|
|
59
|
+
const onEnd = async () => {
|
|
60
|
+
exec.inspect((error, res) => {
|
|
61
|
+
if (error)
|
|
62
|
+
return reject(error);
|
|
63
|
+
const code = res?.ExitCode ?? 0;
|
|
64
|
+
if (code !== 0) {
|
|
65
|
+
const msg = res?.ProcessConfig?.entrypoint
|
|
66
|
+
? `container exec failed (exit ${code})`
|
|
67
|
+
: `command failed (exit ${code})`;
|
|
68
|
+
return reject(new Error(msg));
|
|
69
|
+
}
|
|
70
|
+
resolve();
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
stream.on('error', onError);
|
|
74
|
+
stream.on('end', onEnd);
|
|
75
|
+
stream.on('close', onEnd); // some engines emit 'close' not 'end'
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -7,8 +7,8 @@ export declare class Component {
|
|
|
7
7
|
protected monorepo: Monorepo;
|
|
8
8
|
constructor(_config: ComponentConfig, monorepo: Monorepo);
|
|
9
9
|
get config(): ComponentConfig;
|
|
10
|
-
get context(): string
|
|
11
|
-
get dependencies():
|
|
10
|
+
get context(): string;
|
|
11
|
+
get dependencies(): string[];
|
|
12
12
|
get imageName(): string;
|
|
13
13
|
get imageTag(): string;
|
|
14
14
|
get labels(): {
|
|
@@ -12,10 +12,10 @@ export class Component {
|
|
|
12
12
|
return structuredClone(this._config);
|
|
13
13
|
}
|
|
14
14
|
get context() {
|
|
15
|
-
return this.config.context;
|
|
15
|
+
return this.config.docker?.context || this.name;
|
|
16
16
|
}
|
|
17
17
|
get dependencies() {
|
|
18
|
-
return this.
|
|
18
|
+
return this.config.docker?.dependencies || [];
|
|
19
19
|
}
|
|
20
20
|
get imageName() {
|
|
21
21
|
return join(this.monorepo.name, this.name);
|
|
@@ -26,7 +26,7 @@ export class Component {
|
|
|
26
26
|
get labels() {
|
|
27
27
|
return {
|
|
28
28
|
'emb/component': this.name,
|
|
29
|
-
...this._config.labels,
|
|
29
|
+
...this._config.docker?.labels,
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
get name() {
|
|
@@ -60,9 +60,9 @@ export class Component {
|
|
|
60
60
|
}
|
|
61
61
|
async toDockerBuild() {
|
|
62
62
|
return {
|
|
63
|
-
buildArgs: await this.monorepo.expand(deepmerge()(this.monorepo.defaults.docker?.buildArgs || {}, this.config.buildArgs || {})),
|
|
63
|
+
buildArgs: await this.monorepo.expand(deepmerge()(this.monorepo.defaults.docker?.buildArgs || {}, this.config.docker?.buildArgs || {})),
|
|
64
64
|
context: this.rootdir,
|
|
65
|
-
dockerfile: this.config.dockerfile || 'Dockerfile',
|
|
65
|
+
dockerfile: this.config.docker?.dockerfile || 'Dockerfile',
|
|
66
66
|
labels: deepmerge()({
|
|
67
67
|
...this.monorepo.defaults.docker?.labels,
|
|
68
68
|
}, this.labels),
|
|
@@ -71,7 +71,7 @@ export class Component {
|
|
|
71
71
|
tag: this.imageTag
|
|
72
72
|
? await this.monorepo.expand(this.imageTag)
|
|
73
73
|
: 'latest',
|
|
74
|
-
target: this.config.target || this.monorepo.defaults?.docker?.target,
|
|
74
|
+
target: this.config.docker?.target || this.monorepo.defaults?.docker?.target,
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import { ComponentConfig, DefaultSettings, FlavorConfig, IMonorepoConfig, IProjectConfig, PluginConfig } from '../config/index.js';
|
|
1
|
+
import { ComponentConfig, DefaultSettings, FlavorConfig, IMonorepoConfig, IProjectConfig, PluginConfig, Task } from '../config/index.js';
|
|
2
2
|
export declare class MonorepoConfig implements IMonorepoConfig {
|
|
3
|
-
|
|
3
|
+
currentFlavor: string;
|
|
4
4
|
defaults: DefaultSettings;
|
|
5
5
|
env: Record<string, string>;
|
|
6
6
|
flavors: Array<FlavorConfig>;
|
|
7
7
|
plugins: Array<PluginConfig>;
|
|
8
8
|
project: IProjectConfig;
|
|
9
9
|
vars: Record<string, unknown>;
|
|
10
|
+
tasks: Array<Task>;
|
|
11
|
+
private _components;
|
|
10
12
|
constructor(config: IMonorepoConfig);
|
|
13
|
+
get components(): ComponentConfig[];
|
|
11
14
|
component(name: string): ComponentConfig;
|
|
12
15
|
flavor(name: string): FlavorConfig;
|
|
13
|
-
toJSON():
|
|
16
|
+
toJSON(): IMonorepoConfig;
|
|
14
17
|
with(overrides: Partial<IMonorepoConfig>): MonorepoConfig;
|
|
15
18
|
withFlavor(name: string): MonorepoConfig;
|
|
16
19
|
}
|