@nx/docker 21.4.0-beta.3 → 21.4.0-beta.5
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/generators.d.ts +2 -0
- package/generators.d.ts.map +1 -0
- package/generators.js +4 -0
- package/package.json +7 -3
- package/src/executors/release-publish/release-publish.impl.d.ts.map +1 -1
- package/src/executors/release-publish/release-publish.impl.js +56 -14
- package/src/generators/init/schema.d.ts +0 -1
- package/src/generators/init/schema.json +0 -5
- package/src/plugins/plugin.js +10 -1
package/generators.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators.d.ts","sourceRoot":"","sources":["../../../packages/docker/generators.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC"}
|
package/generators.js
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/docker",
|
|
3
3
|
"description": "The Nx Plugin for Docker to aid in containerizing projects.",
|
|
4
|
-
"version": "21.4.0-beta.
|
|
4
|
+
"version": "21.4.0-beta.5",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -32,6 +32,10 @@
|
|
|
32
32
|
"types": "./src/release/version-utils.d.ts",
|
|
33
33
|
"default": "./src/release/version-utils.js"
|
|
34
34
|
},
|
|
35
|
+
"./generators": {
|
|
36
|
+
"types": "./generators.d.ts",
|
|
37
|
+
"default": "./generators.js"
|
|
38
|
+
},
|
|
35
39
|
"./package.json": "./package.json",
|
|
36
40
|
"./generators.json": "./generators.json",
|
|
37
41
|
"./executors.json": "./executors.json",
|
|
@@ -43,12 +47,12 @@
|
|
|
43
47
|
"executors": "./executors.json",
|
|
44
48
|
"generators": "./generators.json",
|
|
45
49
|
"dependencies": {
|
|
46
|
-
"@nx/devkit": "21.4.0-beta.
|
|
50
|
+
"@nx/devkit": "21.4.0-beta.5",
|
|
47
51
|
"enquirer": "~2.3.6",
|
|
48
52
|
"tslib": "^2.3.0"
|
|
49
53
|
},
|
|
50
54
|
"devDependencies": {
|
|
51
|
-
"nx": "21.4.0-beta.
|
|
55
|
+
"nx": "21.4.0-beta.5"
|
|
52
56
|
},
|
|
53
57
|
"types": "./src/index.d.ts"
|
|
54
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"release-publish.impl.d.ts","sourceRoot":"","sources":["../../../../../../packages/docker/src/executors/release-publish/release-publish.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AAI3D,MAAM,WAAW,oCAAoC;IACnD,KAAK,EAAE,OAAO,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,eAAO,MAAM,YAAY,QAAiB,CAAC;AAE3C,wBAA8B,oBAAoB,CAChD,MAAM,EAAE,0BAA0B,EAClC,OAAO,EAAE,eAAe;;
|
|
1
|
+
{"version":3,"file":"release-publish.impl.d.ts","sourceRoot":"","sources":["../../../../../../packages/docker/src/executors/release-publish/release-publish.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AAI3D,MAAM,WAAW,oCAAoC;IACnD,KAAK,EAAE,OAAO,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,eAAO,MAAM,YAAY,QAAiB,CAAC;AAE3C,wBAA8B,oBAAoB,CAChD,MAAM,EAAE,0BAA0B,EAClC,OAAO,EAAE,eAAe;;GAmBzB"}
|
|
@@ -9,10 +9,10 @@ const version_utils_1 = require("../../release/version-utils");
|
|
|
9
9
|
exports.LARGE_BUFFER = 1024 * 1000000;
|
|
10
10
|
async function dockerReleasePublish(schema, context) {
|
|
11
11
|
const projectConfig = context.projectGraph.nodes[context.projectName];
|
|
12
|
-
const options = normalizeOptions(projectConfig, schema);
|
|
12
|
+
const options = await normalizeOptions(projectConfig, schema);
|
|
13
13
|
if (!options.dryRun) {
|
|
14
|
-
const digest = dockerPush(options.imageReference, options.quiet);
|
|
15
|
-
devkit_1.logger.log(`Successfully pushed ${options.imageReference}. Digest: ${digest}`);
|
|
14
|
+
const digest = await dockerPush(options.imageReference, options.quiet);
|
|
15
|
+
devkit_1.logger.log(`Successfully pushed ${options.imageReference}${options.quiet ? `. Digest: ${digest}` : ''}`);
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
18
18
|
devkit_1.logger.log(`Docker Image ${options.imageReference} was not pushed as --dry-run is enabled.`);
|
|
@@ -21,17 +21,17 @@ async function dockerReleasePublish(schema, context) {
|
|
|
21
21
|
success: true,
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
function normalizeOptions(projectConfig, schema) {
|
|
24
|
+
async function normalizeOptions(projectConfig, schema) {
|
|
25
25
|
return {
|
|
26
26
|
quiet: schema.quiet ?? false,
|
|
27
|
-
imageReference: findImageReference(projectConfig, schema),
|
|
27
|
+
imageReference: await findImageReference(projectConfig, schema),
|
|
28
28
|
dryRun: process.env.NX_DRY_RUN === 'true' || schema.dryRun || false,
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
-
function findImageReference(projectConfig, schema) {
|
|
31
|
+
async function findImageReference(projectConfig, schema) {
|
|
32
32
|
let imageRef = readVersionFromFile(projectConfig.data.root);
|
|
33
33
|
if (imageRef) {
|
|
34
|
-
if (checkDockerImageExistsLocally(imageRef)) {
|
|
34
|
+
if (await checkDockerImageExistsLocally(imageRef)) {
|
|
35
35
|
return imageRef;
|
|
36
36
|
}
|
|
37
37
|
throw new Error(`Could not find Docker Image ${imageRef}. Did you run 'nx release version'?`);
|
|
@@ -45,21 +45,63 @@ function readVersionFromFile(projectRoot) {
|
|
|
45
45
|
const version = (0, fs_1.readFileSync)(versionFilePath, { encoding: 'utf8' });
|
|
46
46
|
return version.trim();
|
|
47
47
|
}
|
|
48
|
-
function checkDockerImageExistsLocally(imageRef) {
|
|
48
|
+
async function checkDockerImageExistsLocally(imageRef) {
|
|
49
49
|
try {
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
return await new Promise((res) => {
|
|
51
|
+
// If the ref starts with 'docker.io/', then we need to strip it since it is the default value and Docker CLI will not find it.
|
|
52
|
+
const normalizedImageRef = imageRef.startsWith('docker.io/')
|
|
53
|
+
? imageRef.split('docker.io/')[1]
|
|
54
|
+
: imageRef;
|
|
55
|
+
const childProcess = (0, child_process_1.exec)(`docker images --filter "reference=${normalizedImageRef}" --quiet`, { encoding: 'utf8' });
|
|
56
|
+
let result = '';
|
|
57
|
+
childProcess.stdout?.on('data', (data) => {
|
|
58
|
+
result += data;
|
|
59
|
+
});
|
|
60
|
+
childProcess.stderr?.on('data', (data) => {
|
|
61
|
+
console.error(data);
|
|
62
|
+
});
|
|
63
|
+
childProcess.on('error', (error) => {
|
|
64
|
+
console.error('Docker command failed:', error);
|
|
65
|
+
res(false);
|
|
66
|
+
});
|
|
67
|
+
childProcess.on('exit', () => {
|
|
68
|
+
res(result.trim().length > 0);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
52
71
|
}
|
|
53
72
|
catch {
|
|
54
73
|
return false;
|
|
55
74
|
}
|
|
56
75
|
}
|
|
57
|
-
function dockerPush(imageReference, quiet) {
|
|
76
|
+
async function dockerPush(imageReference, quiet) {
|
|
58
77
|
try {
|
|
59
|
-
|
|
60
|
-
|
|
78
|
+
return await new Promise((res, rej) => {
|
|
79
|
+
const childProcess = (0, child_process_1.exec)(`docker push ${imageReference}${quiet ? ' --quiet' : ''}`, {
|
|
80
|
+
encoding: 'utf8',
|
|
81
|
+
maxBuffer: exports.LARGE_BUFFER,
|
|
82
|
+
});
|
|
83
|
+
let result = '';
|
|
84
|
+
childProcess.stdout?.on('data', (data) => {
|
|
85
|
+
result += data;
|
|
86
|
+
if (!quiet) {
|
|
87
|
+
console.log(data);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
childProcess.stderr?.on('data', (data) => {
|
|
91
|
+
console.error(data);
|
|
92
|
+
});
|
|
93
|
+
childProcess.on('error', (error) => {
|
|
94
|
+
rej(error);
|
|
95
|
+
});
|
|
96
|
+
childProcess.on('exit', (code) => {
|
|
97
|
+
if (code === 0) {
|
|
98
|
+
res(result.trim());
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
rej(new Error(`Docker push failed with exit code ${code}`));
|
|
102
|
+
}
|
|
103
|
+
});
|
|
61
104
|
});
|
|
62
|
-
return result.trim();
|
|
63
105
|
}
|
|
64
106
|
catch (e) {
|
|
65
107
|
devkit_1.logger.error(`Failed to push ${imageReference}`);
|
|
@@ -30,11 +30,6 @@
|
|
|
30
30
|
"description": "Do not add dependencies to `package.json`.",
|
|
31
31
|
"type": "boolean",
|
|
32
32
|
"default": false
|
|
33
|
-
},
|
|
34
|
-
"addPlugin": {
|
|
35
|
-
"type": "boolean",
|
|
36
|
-
"description": "Add the plugin to the nx.json file.",
|
|
37
|
-
"default": true
|
|
38
33
|
}
|
|
39
34
|
},
|
|
40
35
|
"required": []
|
package/src/plugins/plugin.js
CHANGED
|
@@ -51,6 +51,15 @@ async function createDockerTargets(projectRoot, options, context) {
|
|
|
51
51
|
const imageRef = projectRoot.replace(/^[\\/]/, '').replace(/[\\/\s]+/g, '-');
|
|
52
52
|
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
|
|
53
53
|
const targets = {};
|
|
54
|
+
const metadata = {
|
|
55
|
+
targetGroups: {
|
|
56
|
+
['Docker']: [
|
|
57
|
+
`${options.buildTarget}`,
|
|
58
|
+
`${options.runTarget}`,
|
|
59
|
+
'nx-release-publish',
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
};
|
|
54
63
|
targets[options.buildTarget] = {
|
|
55
64
|
command: `docker build .`,
|
|
56
65
|
options: {
|
|
@@ -103,7 +112,7 @@ async function createDockerTargets(projectRoot, options, context) {
|
|
|
103
112
|
targets['nx-release-publish'] = {
|
|
104
113
|
executor: '@nx/docker:release-publish',
|
|
105
114
|
};
|
|
106
|
-
return { targets, metadata
|
|
115
|
+
return { targets, metadata };
|
|
107
116
|
}
|
|
108
117
|
function normalizePluginOptions(options) {
|
|
109
118
|
return {
|