@nx/docker 22.0.1 → 22.0.2
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/package.json +3 -3
- package/src/executors/release-publish/release-publish.impl.d.ts.map +1 -1
- package/src/executors/release-publish/release-publish.impl.js +4 -1
- package/src/generators/init/init.d.ts.map +1 -1
- package/src/generators/init/init.js +30 -8
- package/src/plugins/plugin.d.ts +11 -2
- package/src/plugins/plugin.d.ts.map +1 -1
- package/src/plugins/plugin.js +101 -15
- package/src/release/version-pattern-utils.d.ts +2 -0
- package/src/release/version-pattern-utils.d.ts.map +1 -1
- package/src/release/version-pattern-utils.js +3 -39
- package/src/release/version-utils.d.ts +2 -2
- package/src/release/version-utils.d.ts.map +1 -1
- package/src/release/version-utils.js +11 -4
- package/src/utils/interpolate-pattern.d.ts +23 -0
- package/src/utils/interpolate-pattern.d.ts.map +1 -0
- package/src/utils/interpolate-pattern.js +81 -0
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": "22.0.
|
|
4
|
+
"version": "22.0.2",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
"executors": "./executors.json",
|
|
48
48
|
"generators": "./generators.json",
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@nx/devkit": "22.0.
|
|
50
|
+
"@nx/devkit": "22.0.2",
|
|
51
51
|
"enquirer": "~2.3.6",
|
|
52
52
|
"tslib": "^2.3.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"nx": "22.0.
|
|
55
|
+
"nx": "22.0.2"
|
|
56
56
|
},
|
|
57
57
|
"types": "./src/index.d.ts"
|
|
58
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;
|
|
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;AAGpB,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"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.LARGE_BUFFER = void 0;
|
|
4
4
|
exports.default = dockerReleasePublish;
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
6
7
|
const child_process_1 = require("child_process");
|
|
7
8
|
const fs_1 = require("fs");
|
|
8
9
|
const version_utils_1 = require("../../release/version-utils");
|
|
@@ -93,7 +94,9 @@ async function dockerPush(imageReference, quiet) {
|
|
|
93
94
|
childProcess.on('error', (error) => {
|
|
94
95
|
rej(error);
|
|
95
96
|
});
|
|
96
|
-
childProcess.on('exit', (code) => {
|
|
97
|
+
childProcess.on('exit', (code, signal) => {
|
|
98
|
+
if (code === null)
|
|
99
|
+
code = (0, internal_1.signalToCode)(signal);
|
|
97
100
|
if (code === 0) {
|
|
98
101
|
res(result.trim());
|
|
99
102
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../../../packages/docker/src/generators/init/init.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,IAAI,EACT,KAAK,iBAAiB,
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../../../packages/docker/src/generators/init/init.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,IAAI,EACT,KAAK,iBAAiB,EAQvB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAI/C,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,mBAAmB,qBAUzE;AAwCD,wBAAsB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,mBAAmB,8BAiB1E;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -3,25 +3,47 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.updateDependencies = updateDependencies;
|
|
4
4
|
exports.initGenerator = initGenerator;
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const add_plugin_1 = require("@nx/devkit/src/utils/add-plugin");
|
|
7
|
-
const plugin_1 = require("../../plugins/plugin");
|
|
8
6
|
const versions_1 = require("../../utils/versions");
|
|
9
7
|
function updateDependencies(tree, schema) {
|
|
10
8
|
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
11
9
|
'@nx/docker': versions_1.nxVersion,
|
|
12
10
|
}, undefined, schema.keepExistingVersions);
|
|
13
11
|
}
|
|
12
|
+
function addPluginToNxJson(tree, updatePackageScripts) {
|
|
13
|
+
if (!tree.exists('nx.json')) {
|
|
14
|
+
devkit_1.logger.warn('"nx.json" not found. Skipping "@nx/docker" plugin registration.');
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
18
|
+
if (!nxJson) {
|
|
19
|
+
devkit_1.logger.warn('Unable to read "nx.json" content. Skipping "@nx/docker" plugin registration.');
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
nxJson.plugins ??= [];
|
|
23
|
+
const pluginExists = nxJson.plugins.some((plugin) => typeof plugin === 'string'
|
|
24
|
+
? plugin === '@nx/docker'
|
|
25
|
+
: plugin?.plugin === '@nx/docker');
|
|
26
|
+
if (pluginExists) {
|
|
27
|
+
devkit_1.logger.info('"@nx/docker" plugin is already registered in "nx.json".');
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
nxJson.plugins.push({
|
|
31
|
+
plugin: '@nx/docker',
|
|
32
|
+
options: {
|
|
33
|
+
buildTarget: { name: 'docker:build' },
|
|
34
|
+
runTarget: { name: 'docker:run' },
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
38
|
+
devkit_1.logger.info('Added "@nx/docker" to plugins array in "nx.json".');
|
|
39
|
+
}
|
|
14
40
|
async function initGenerator(tree, schema) {
|
|
15
41
|
devkit_1.logger.warn(`Docker support is experimental. Breaking changes may occur and not adhere to semver versioning.`);
|
|
16
|
-
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
17
|
-
await (0, add_plugin_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/docker', plugin_1.createNodesV2, {
|
|
18
|
-
buildTarget: ['docker:build', 'docker-build', 'build-docker'],
|
|
19
|
-
runTarget: ['docker:run', 'docker-run', 'run-docker'],
|
|
20
|
-
}, schema.updatePackageScripts);
|
|
21
42
|
const tasks = [];
|
|
22
|
-
if (!schema.skipPackageJson) {
|
|
43
|
+
if (!schema.skipPackageJson && tree.exists('package.json')) {
|
|
23
44
|
tasks.push(updateDependencies(tree, schema));
|
|
24
45
|
}
|
|
46
|
+
addPluginToNxJson(tree, schema.updatePackageScripts);
|
|
25
47
|
if (!schema.skipFormat) {
|
|
26
48
|
await (0, devkit_1.formatFiles)(tree);
|
|
27
49
|
}
|
package/src/plugins/plugin.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { type CreateNodesV2 } from '@nx/devkit';
|
|
2
|
+
export interface DockerTargetOptions {
|
|
3
|
+
name: string;
|
|
4
|
+
args?: string[];
|
|
5
|
+
env?: Record<string, string>;
|
|
6
|
+
envFile?: string;
|
|
7
|
+
cwd?: string;
|
|
8
|
+
configurations?: Record<string, Omit<DockerTargetOptions, 'configurations' | 'name'>>;
|
|
9
|
+
}
|
|
2
10
|
export interface DockerPluginOptions {
|
|
3
|
-
buildTarget?: string;
|
|
4
|
-
runTarget?: string;
|
|
11
|
+
buildTarget?: string | DockerTargetOptions;
|
|
12
|
+
runTarget?: string | DockerTargetOptions;
|
|
5
13
|
}
|
|
6
14
|
export declare const createNodesV2: CreateNodesV2<DockerPluginOptions>;
|
|
15
|
+
export declare function getProjectNameFromPath(projectRoot: string, workspaceRoot: string): string;
|
|
7
16
|
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../../packages/docker/src/plugins/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../../packages/docker/src/plugins/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAQnB,MAAM,YAAY,CAAC;AAUpB,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,MAAM,CACrB,MAAM,EACN,IAAI,CAAC,mBAAmB,EAAE,gBAAgB,GAAG,MAAM,CAAC,CACrD,CAAC;CACH;AAED,MAAM,WAAW,mBAAmB;IAClC,WAAW,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAAC;IAC3C,SAAS,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAAC;CAC1C;AAsBD,eAAO,MAAM,aAAa,EAAE,aAAa,CAAC,mBAAmB,CAmC5D,CAAC;AAmDF,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,GACpB,MAAM,CAOR"}
|
package/src/plugins/plugin.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createNodesV2 = void 0;
|
|
4
|
+
exports.getProjectNameFromPath = getProjectNameFromPath;
|
|
4
5
|
const devkit_1 = require("@nx/devkit");
|
|
5
6
|
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
|
6
7
|
const file_hasher_1 = require("nx/src/hasher/file-hasher");
|
|
@@ -8,6 +9,8 @@ const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
|
8
9
|
const fs_1 = require("fs");
|
|
9
10
|
const path_1 = require("path");
|
|
10
11
|
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
12
|
+
const git_utils_1 = require("nx/src/utils/git-utils");
|
|
13
|
+
const interpolate_pattern_1 = require("../utils/interpolate-pattern");
|
|
11
14
|
function readTargetsCache(cachePath) {
|
|
12
15
|
return (0, fs_1.existsSync)(cachePath) ? (0, devkit_1.readJsonFile)(cachePath) : {};
|
|
13
16
|
}
|
|
@@ -47,26 +50,99 @@ async function createNodesInternal(configFilePath, hash, normalizedOptions, cont
|
|
|
47
50
|
},
|
|
48
51
|
};
|
|
49
52
|
}
|
|
53
|
+
function interpolateDockerTargetOptions(options, projectRoot, imageRef, context) {
|
|
54
|
+
const commitSha = (0, git_utils_1.getLatestCommitSha)();
|
|
55
|
+
const projectName = getProjectName(projectRoot, context.workspaceRoot);
|
|
56
|
+
const tokens = {
|
|
57
|
+
projectRoot,
|
|
58
|
+
projectName,
|
|
59
|
+
imageRef,
|
|
60
|
+
currentDate: new Date(),
|
|
61
|
+
commitSha,
|
|
62
|
+
shortCommitSha: commitSha ? commitSha.slice(0, 7) : null,
|
|
63
|
+
};
|
|
64
|
+
return (0, interpolate_pattern_1.interpolateObject)(options, tokens);
|
|
65
|
+
}
|
|
66
|
+
function getProjectNameFromPath(projectRoot, workspaceRoot) {
|
|
67
|
+
const root = projectRoot === '.' ? workspaceRoot : projectRoot;
|
|
68
|
+
const normalized = root
|
|
69
|
+
.replace(/^[\\/]/, '')
|
|
70
|
+
.replace(/[\\/\s]+/g, '-')
|
|
71
|
+
.toLowerCase();
|
|
72
|
+
return normalized.length > 128 ? normalized.slice(-128) : normalized;
|
|
73
|
+
}
|
|
74
|
+
function getProjectName(projectRoot, workspaceRoot) {
|
|
75
|
+
const projectJsonPath = (0, path_1.join)(workspaceRoot, projectRoot, 'project.json');
|
|
76
|
+
if ((0, fs_1.existsSync)(projectJsonPath)) {
|
|
77
|
+
const projectJson = (0, devkit_1.readJsonFile)(projectJsonPath);
|
|
78
|
+
if (projectJson.name) {
|
|
79
|
+
return projectJson.name;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const packageJsonPath = (0, path_1.join)(workspaceRoot, projectRoot, 'package.json');
|
|
83
|
+
if ((0, fs_1.existsSync)(packageJsonPath)) {
|
|
84
|
+
const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
|
|
85
|
+
if (packageJson.name) {
|
|
86
|
+
return packageJson.name;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return getProjectNameFromPath(projectRoot, workspaceRoot);
|
|
90
|
+
}
|
|
91
|
+
function buildTargetOptions(interpolatedTarget, projectRoot, imageRef, isRunTarget = false) {
|
|
92
|
+
const options = {
|
|
93
|
+
cwd: interpolatedTarget.cwd ?? projectRoot,
|
|
94
|
+
};
|
|
95
|
+
if (isRunTarget) {
|
|
96
|
+
// Run target doesn't have default args
|
|
97
|
+
if (interpolatedTarget.args) {
|
|
98
|
+
options.args = interpolatedTarget.args;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// Build target always includes --tag default
|
|
103
|
+
options.args = [`--tag ${imageRef}`, ...(interpolatedTarget.args ?? [])];
|
|
104
|
+
}
|
|
105
|
+
if (interpolatedTarget.env) {
|
|
106
|
+
options.env = interpolatedTarget.env;
|
|
107
|
+
}
|
|
108
|
+
if (interpolatedTarget.envFile) {
|
|
109
|
+
options.envFile = interpolatedTarget.envFile;
|
|
110
|
+
}
|
|
111
|
+
return options;
|
|
112
|
+
}
|
|
113
|
+
function buildTargetConfigurations(interpolatedTarget, projectRoot, imageRef, isRunTarget = false) {
|
|
114
|
+
if (!interpolatedTarget.configurations) {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
const configurations = {};
|
|
118
|
+
for (const [configName, configOptions] of Object.entries(interpolatedTarget.configurations)) {
|
|
119
|
+
// Each configuration gets the full treatment with defaults
|
|
120
|
+
configurations[configName] = buildTargetOptions({ ...configOptions, name: interpolatedTarget.name }, projectRoot, imageRef, isRunTarget);
|
|
121
|
+
}
|
|
122
|
+
return configurations;
|
|
123
|
+
}
|
|
50
124
|
async function createDockerTargets(projectRoot, options, context) {
|
|
51
|
-
const imageRef = projectRoot
|
|
125
|
+
const imageRef = getProjectNameFromPath(projectRoot, devkit_1.workspaceRoot);
|
|
126
|
+
const interpolatedBuildTarget = interpolateDockerTargetOptions(options.buildTarget, projectRoot, imageRef, context);
|
|
127
|
+
const interpolatedRunTarget = interpolateDockerTargetOptions(options.runTarget, projectRoot, imageRef, context);
|
|
52
128
|
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
|
|
53
129
|
const targets = {};
|
|
54
130
|
const metadata = {
|
|
55
131
|
targetGroups: {
|
|
56
132
|
['Docker']: [
|
|
57
|
-
|
|
58
|
-
|
|
133
|
+
interpolatedBuildTarget.name,
|
|
134
|
+
interpolatedRunTarget.name,
|
|
59
135
|
'nx-release-publish',
|
|
60
136
|
],
|
|
61
137
|
},
|
|
62
138
|
};
|
|
63
|
-
|
|
139
|
+
const buildOptions = buildTargetOptions(interpolatedBuildTarget, projectRoot, imageRef, false);
|
|
140
|
+
const buildConfigurations = buildTargetConfigurations(interpolatedBuildTarget, projectRoot, imageRef, false);
|
|
141
|
+
targets[interpolatedBuildTarget.name] = {
|
|
64
142
|
dependsOn: ['build', '^build'],
|
|
65
143
|
command: `docker build .`,
|
|
66
|
-
options:
|
|
67
|
-
|
|
68
|
-
args: [`--tag ${imageRef}`],
|
|
69
|
-
},
|
|
144
|
+
options: buildOptions,
|
|
145
|
+
...(buildConfigurations && { configurations: buildConfigurations }),
|
|
70
146
|
inputs: [
|
|
71
147
|
...('production' in namedInputs
|
|
72
148
|
? ['production', '^production']
|
|
@@ -86,12 +162,13 @@ async function createDockerTargets(projectRoot, options, context) {
|
|
|
86
162
|
},
|
|
87
163
|
},
|
|
88
164
|
};
|
|
89
|
-
|
|
90
|
-
|
|
165
|
+
const runOptions = buildTargetOptions(interpolatedRunTarget, projectRoot, imageRef, true);
|
|
166
|
+
const runConfigurations = buildTargetConfigurations(interpolatedRunTarget, projectRoot, imageRef, true);
|
|
167
|
+
targets[interpolatedRunTarget.name] = {
|
|
168
|
+
dependsOn: [interpolatedBuildTarget.name],
|
|
91
169
|
command: `docker run {args} ${imageRef}`,
|
|
92
|
-
options:
|
|
93
|
-
|
|
94
|
-
},
|
|
170
|
+
options: runOptions,
|
|
171
|
+
...(runConfigurations && { configurations: runConfigurations }),
|
|
95
172
|
inputs: [
|
|
96
173
|
...('production' in namedInputs
|
|
97
174
|
? ['production', '^production']
|
|
@@ -116,8 +193,17 @@ async function createDockerTargets(projectRoot, options, context) {
|
|
|
116
193
|
return { targets, metadata };
|
|
117
194
|
}
|
|
118
195
|
function normalizePluginOptions(options) {
|
|
196
|
+
const normalizeTarget = (target, defaultName) => {
|
|
197
|
+
if (typeof target === 'string') {
|
|
198
|
+
return { name: target };
|
|
199
|
+
}
|
|
200
|
+
if (target && typeof target === 'object') {
|
|
201
|
+
return { ...target, name: target.name ?? defaultName };
|
|
202
|
+
}
|
|
203
|
+
return { name: defaultName };
|
|
204
|
+
};
|
|
119
205
|
return {
|
|
120
|
-
buildTarget: options
|
|
121
|
-
runTarget: options
|
|
206
|
+
buildTarget: normalizeTarget(options?.buildTarget, 'docker:build'),
|
|
207
|
+
runTarget: normalizeTarget(options?.runTarget, 'docker:run'),
|
|
122
208
|
};
|
|
123
209
|
}
|
|
@@ -6,12 +6,14 @@
|
|
|
6
6
|
* {commitSha} - The full commit sha for the current commit
|
|
7
7
|
* {shortCommitSha} - The seven character commit sha for the current commit
|
|
8
8
|
* {env.VAR_NAME} - The value of the environment variable VAR_NAME
|
|
9
|
+
* {versionActionsVersion} - The version generated during the version actions such as "1.2.3"
|
|
9
10
|
*/
|
|
10
11
|
export interface PatternTokens {
|
|
11
12
|
projectName: string;
|
|
12
13
|
currentDate: Date;
|
|
13
14
|
commitSha: string;
|
|
14
15
|
shortCommitSha: string;
|
|
16
|
+
versionActionsVersion: string;
|
|
15
17
|
}
|
|
16
18
|
export declare function interpolateVersionPattern(versionPattern: string, data: Partial<PatternTokens>): string;
|
|
17
19
|
//# sourceMappingURL=version-pattern-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-pattern-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/docker/src/release/version-pattern-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"version-pattern-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/docker/src/release/version-pattern-utils.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,IAAI,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,qBAAqB,EAAE,MAAM,CAAC;CAC/B;AAED,wBAAgB,yBAAyB,CACvC,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,UAY7B"}
|
|
@@ -2,23 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.interpolateVersionPattern = interpolateVersionPattern;
|
|
4
4
|
const git_utils_1 = require("nx/src/utils/git-utils");
|
|
5
|
-
const
|
|
6
|
-
function formatDate(date, format) {
|
|
7
|
-
const year = String(date.getUTCFullYear());
|
|
8
|
-
const month = String(date.getUTCMonth() + 1).padStart(2, '0');
|
|
9
|
-
const day = String(date.getUTCDate()).padStart(2, '0');
|
|
10
|
-
const hours = String(date.getUTCHours()).padStart(2, '0');
|
|
11
|
-
const minutes = String(date.getUTCMinutes()).padStart(2, '0');
|
|
12
|
-
const seconds = String(date.getUTCSeconds()).padStart(2, '0');
|
|
13
|
-
return format
|
|
14
|
-
.replace(/YYYY/g, year)
|
|
15
|
-
.replace(/YY/g, year.slice(-2))
|
|
16
|
-
.replace(/MM/g, month)
|
|
17
|
-
.replace(/DD/g, day)
|
|
18
|
-
.replace(/HH/g, hours)
|
|
19
|
-
.replace(/mm/g, minutes)
|
|
20
|
-
.replace(/ss/g, seconds);
|
|
21
|
-
}
|
|
5
|
+
const interpolate_pattern_1 = require("../utils/interpolate-pattern");
|
|
22
6
|
function interpolateVersionPattern(versionPattern, data) {
|
|
23
7
|
const commitSha = (0, git_utils_1.getLatestCommitSha)();
|
|
24
8
|
const substitutions = {
|
|
@@ -26,27 +10,7 @@ function interpolateVersionPattern(versionPattern, data) {
|
|
|
26
10
|
currentDate: data.currentDate ?? new Date(),
|
|
27
11
|
commitSha: data.commitSha ?? commitSha,
|
|
28
12
|
shortCommitSha: data.shortCommitSha ?? commitSha.slice(0, 7),
|
|
13
|
+
versionActionsVersion: data.versionActionsVersion ?? '',
|
|
29
14
|
};
|
|
30
|
-
return
|
|
31
|
-
// Handle environment variables
|
|
32
|
-
if (envVarName) {
|
|
33
|
-
const envValue = process.env[envVarName];
|
|
34
|
-
return envValue !== undefined ? envValue : match;
|
|
35
|
-
}
|
|
36
|
-
// Handle other tokens
|
|
37
|
-
const value = substitutions[identifier];
|
|
38
|
-
if (value === undefined) {
|
|
39
|
-
return match; // Keep original token if no data
|
|
40
|
-
}
|
|
41
|
-
// Handle date formatting
|
|
42
|
-
if (identifier === 'currentDate') {
|
|
43
|
-
if (format) {
|
|
44
|
-
return formatDate(value, format);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
return value.toISOString();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return value;
|
|
51
|
-
});
|
|
15
|
+
return (0, interpolate_pattern_1.interpolatePattern)(versionPattern, substitutions);
|
|
52
16
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ProjectGraphProjectNode } from '@nx/devkit';
|
|
2
2
|
import type { FinalConfigForProject } from 'nx/src/command-line/release/utils/release-graph';
|
|
3
3
|
export declare const getDockerVersionPath: (workspaceRoot: string, projectRoot: string) => string;
|
|
4
|
-
export declare function handleDockerVersion(workspaceRoot: string, projectGraphNode: ProjectGraphProjectNode, finalConfigForProject: FinalConfigForProject, dockerVersionScheme?: string, dockerVersion?: string): Promise<{
|
|
4
|
+
export declare function handleDockerVersion(workspaceRoot: string, projectGraphNode: ProjectGraphProjectNode, finalConfigForProject: FinalConfigForProject, dockerVersionScheme?: string, dockerVersion?: string, versionActionsVersion?: string): Promise<{
|
|
5
5
|
newVersion: string;
|
|
6
6
|
logs: string[];
|
|
7
7
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/docker/src/release/version-utils.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"version-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/docker/src/release/version-utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,uBAAuB,EAAiB,MAAM,YAAY,CAAC;AACpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iDAAiD,CAAC;AAQ7F,eAAO,MAAM,oBAAoB,GAC/B,eAAe,MAAM,EACrB,aAAa,MAAM,WAGpB,CAAC;AAEF,wBAAsB,mBAAmB,CACvC,aAAa,EAAE,MAAM,EACrB,gBAAgB,EAAE,uBAAuB,EACzC,qBAAqB,EAAE,qBAAqB,EAC5C,mBAAmB,CAAC,EAAE,MAAM,EAC5B,aAAa,CAAC,EAAE,MAAM,EACtB,qBAAqB,CAAC,EAAE,MAAM;;;GA6C/B"}
|
|
@@ -6,6 +6,7 @@ const child_process_1 = require("child_process");
|
|
|
6
6
|
const fs_1 = require("fs");
|
|
7
7
|
const path_1 = require("path");
|
|
8
8
|
const enquirer_1 = require("enquirer");
|
|
9
|
+
const devkit_1 = require("@nx/devkit");
|
|
9
10
|
const version_pattern_utils_1 = require("./version-pattern-utils");
|
|
10
11
|
const DEFAULT_VERSION_SCHEMES = {
|
|
11
12
|
production: '{currentDate|YYMM.DD}.{shortCommitSha}',
|
|
@@ -15,7 +16,7 @@ const getDockerVersionPath = (workspaceRoot, projectRoot) => {
|
|
|
15
16
|
return (0, path_1.join)(workspaceRoot, 'tmp', projectRoot, '.docker-version');
|
|
16
17
|
};
|
|
17
18
|
exports.getDockerVersionPath = getDockerVersionPath;
|
|
18
|
-
async function handleDockerVersion(workspaceRoot, projectGraphNode, finalConfigForProject, dockerVersionScheme, dockerVersion) {
|
|
19
|
+
async function handleDockerVersion(workspaceRoot, projectGraphNode, finalConfigForProject, dockerVersionScheme, dockerVersion, versionActionsVersion) {
|
|
19
20
|
// If the full docker image reference is provided, use it directly
|
|
20
21
|
const nxDockerImageRefEnvOverride = process.env.NX_DOCKER_IMAGE_REF?.trim() || undefined;
|
|
21
22
|
// If an explicit dockerVersion is provided, use it directly
|
|
@@ -30,7 +31,7 @@ async function handleDockerVersion(workspaceRoot, projectGraphNode, finalConfigF
|
|
|
30
31
|
const versionScheme = dockerVersionScheme && dockerVersionScheme in availableVersionSchemes
|
|
31
32
|
? dockerVersionScheme
|
|
32
33
|
: await promptForNewVersion(availableVersionSchemes, projectGraphNode.name);
|
|
33
|
-
newVersion = calculateNewVersion(projectGraphNode.name, versionScheme, availableVersionSchemes);
|
|
34
|
+
newVersion = calculateNewVersion(projectGraphNode.name, versionScheme, availableVersionSchemes, versionActionsVersion);
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
const logs = updateProjectVersion(newVersion, nxDockerImageRefEnvOverride, workspaceRoot, projectGraphNode.data.root, finalConfigForProject.dockerOptions.repositoryName, finalConfigForProject.dockerOptions.registryUrl);
|
|
@@ -53,12 +54,13 @@ async function promptForNewVersion(versionSchemes, projectName) {
|
|
|
53
54
|
});
|
|
54
55
|
return versionScheme;
|
|
55
56
|
}
|
|
56
|
-
function calculateNewVersion(projectName, versionScheme, versionSchemes) {
|
|
57
|
+
function calculateNewVersion(projectName, versionScheme, versionSchemes, versionActionsVersion) {
|
|
57
58
|
if (!(versionScheme in versionSchemes)) {
|
|
58
59
|
throw new Error(`Could not find version scheme '${versionScheme}'. Available options are: ${Object.keys(versionSchemes).join(', ')}.`);
|
|
59
60
|
}
|
|
60
61
|
return (0, version_pattern_utils_1.interpolateVersionPattern)(versionSchemes[versionScheme], {
|
|
61
62
|
projectName,
|
|
63
|
+
versionActionsVersion,
|
|
62
64
|
});
|
|
63
65
|
}
|
|
64
66
|
function updateProjectVersion(newVersion, nxDockerImageRefEnvOverride, workspaceRoot, projectRoot, repositoryName, registry) {
|
|
@@ -90,5 +92,10 @@ function getImageReference(projectRoot, repositoryName, registry) {
|
|
|
90
92
|
return imageRef;
|
|
91
93
|
}
|
|
92
94
|
function getDefaultImageReference(projectRoot) {
|
|
93
|
-
|
|
95
|
+
const root = projectRoot === '.' ? devkit_1.workspaceRoot : projectRoot;
|
|
96
|
+
const normalized = root
|
|
97
|
+
.replace(/^[\\/]/, '')
|
|
98
|
+
.replace(/[\\/\s]+/g, '-')
|
|
99
|
+
.toLowerCase();
|
|
100
|
+
return normalized.length > 128 ? normalized.slice(-128) : normalized;
|
|
94
101
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interpolates pattern tokens in a string.
|
|
3
|
+
*
|
|
4
|
+
* Supported tokens:
|
|
5
|
+
* - {tokenName} - Simple token replacement
|
|
6
|
+
* - {currentDate} - Current date in ISO format
|
|
7
|
+
* - {currentDate|FORMAT} - Current date with custom format (YYYY, YY, MM, DD, HH, mm, ss)
|
|
8
|
+
* - {env.VAR_NAME} - Environment variable value
|
|
9
|
+
*
|
|
10
|
+
* @param pattern - String containing tokens to interpolate
|
|
11
|
+
* @param tokens - Record of token values
|
|
12
|
+
* @returns Interpolated string
|
|
13
|
+
*/
|
|
14
|
+
export declare function interpolatePattern(pattern: string, tokens: Record<string, any>): string;
|
|
15
|
+
/**
|
|
16
|
+
* Recursively interpolates pattern tokens in all string values within an object or array.
|
|
17
|
+
*
|
|
18
|
+
* @param obj - Object or array to process
|
|
19
|
+
* @param tokens - Record of token values
|
|
20
|
+
* @returns New object/array with interpolated values
|
|
21
|
+
*/
|
|
22
|
+
export declare function interpolateObject<T>(obj: T, tokens: Record<string, any>): T;
|
|
23
|
+
//# sourceMappingURL=interpolate-pattern.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interpolate-pattern.d.ts","sourceRoot":"","sources":["../../../../../packages/docker/src/utils/interpolate-pattern.ts"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC1B,MAAM,CA6BR;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAkB3E"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.interpolatePattern = interpolatePattern;
|
|
4
|
+
exports.interpolateObject = interpolateObject;
|
|
5
|
+
const tokenRegex = /\{(env\.([^}]+)|([^|{}]+)(?:\|([^{}]+))?)\}/g;
|
|
6
|
+
function formatDate(date, format) {
|
|
7
|
+
const year = String(date.getUTCFullYear());
|
|
8
|
+
const month = String(date.getUTCMonth() + 1).padStart(2, '0');
|
|
9
|
+
const day = String(date.getUTCDate()).padStart(2, '0');
|
|
10
|
+
const hours = String(date.getUTCHours()).padStart(2, '0');
|
|
11
|
+
const minutes = String(date.getUTCMinutes()).padStart(2, '0');
|
|
12
|
+
const seconds = String(date.getUTCSeconds()).padStart(2, '0');
|
|
13
|
+
return format
|
|
14
|
+
.replace(/YYYY/g, year)
|
|
15
|
+
.replace(/YY/g, year.slice(-2))
|
|
16
|
+
.replace(/MM/g, month)
|
|
17
|
+
.replace(/DD/g, day)
|
|
18
|
+
.replace(/HH/g, hours)
|
|
19
|
+
.replace(/mm/g, minutes)
|
|
20
|
+
.replace(/ss/g, seconds);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Interpolates pattern tokens in a string.
|
|
24
|
+
*
|
|
25
|
+
* Supported tokens:
|
|
26
|
+
* - {tokenName} - Simple token replacement
|
|
27
|
+
* - {currentDate} - Current date in ISO format
|
|
28
|
+
* - {currentDate|FORMAT} - Current date with custom format (YYYY, YY, MM, DD, HH, mm, ss)
|
|
29
|
+
* - {env.VAR_NAME} - Environment variable value
|
|
30
|
+
*
|
|
31
|
+
* @param pattern - String containing tokens to interpolate
|
|
32
|
+
* @param tokens - Record of token values
|
|
33
|
+
* @returns Interpolated string
|
|
34
|
+
*/
|
|
35
|
+
function interpolatePattern(pattern, tokens) {
|
|
36
|
+
return pattern.replace(tokenRegex, (match, fullMatch, envVarName, identifier, format) => {
|
|
37
|
+
// Handle environment variables
|
|
38
|
+
if (envVarName) {
|
|
39
|
+
const envValue = process.env[envVarName];
|
|
40
|
+
return envValue !== undefined ? envValue : match;
|
|
41
|
+
}
|
|
42
|
+
// Handle other tokens
|
|
43
|
+
const value = tokens[identifier];
|
|
44
|
+
if (value === undefined) {
|
|
45
|
+
return match; // Keep original token if no data
|
|
46
|
+
}
|
|
47
|
+
// Handle date formatting
|
|
48
|
+
if (identifier === 'currentDate') {
|
|
49
|
+
if (format) {
|
|
50
|
+
return formatDate(value, format);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return value.toISOString();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return value;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Recursively interpolates pattern tokens in all string values within an object or array.
|
|
61
|
+
*
|
|
62
|
+
* @param obj - Object or array to process
|
|
63
|
+
* @param tokens - Record of token values
|
|
64
|
+
* @returns New object/array with interpolated values
|
|
65
|
+
*/
|
|
66
|
+
function interpolateObject(obj, tokens) {
|
|
67
|
+
if (typeof obj === 'string') {
|
|
68
|
+
return interpolatePattern(obj, tokens);
|
|
69
|
+
}
|
|
70
|
+
if (Array.isArray(obj)) {
|
|
71
|
+
return obj.map((item) => interpolateObject(item, tokens));
|
|
72
|
+
}
|
|
73
|
+
if (obj !== null && typeof obj === 'object') {
|
|
74
|
+
const result = {};
|
|
75
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
76
|
+
result[key] = interpolateObject(value, tokens);
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
return obj;
|
|
81
|
+
}
|