@nx/docker 23.2.0-beta.1 → 23.2.0-beta.11

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 CHANGED
@@ -7,9 +7,9 @@
7
7
 
8
8
  <div style="text-align: center;">
9
9
 
10
- [![License](https://img.shields.io/npm/l/@nx/workspace.svg?style=flat-square)]()
10
+ [![License](https://img.shields.io/npm/l/@nx/workspace.svg?style=flat-square)](<>)
11
11
  [![NPM Version](https://badge.fury.io/js/nx.svg)](https://www.npmjs.com/package/nx)
12
- [![Semantic Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)]()
12
+ [![Semantic Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](<>)
13
13
  [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
14
14
  [![Join us on the Official Nx Discord Server](https://img.shields.io/discord/1143497901675401286?label=discord)](https://go.nx.dev/community)
15
15
  [![Nx Sandboxing](https://staging.nx.app/workspaces/62d013ea0852fe0a2df74438/sandbox-badge.svg)](https://nx.dev/docs/features/ci-features/sandboxing)
@@ -9,6 +9,13 @@ const fs_1 = require("fs");
9
9
  const version_utils_1 = require("../../release/version-utils");
10
10
  exports.LARGE_BUFFER = 1024 * 1000000;
11
11
  async function dockerReleasePublish(schema, context) {
12
+ const projectVersionData = schema.nxReleaseVersionData?.[context.projectName];
13
+ if (projectVersionData?.dockerVersion === null) {
14
+ console.warn(`Skipped Docker image for project "${context.projectName}", because no new Docker version was resolved for this project.`);
15
+ return {
16
+ success: true,
17
+ };
18
+ }
12
19
  const projectConfig = context.projectGraph.nodes[context.projectName];
13
20
  const options = await normalizeOptions(projectConfig, schema);
14
21
  if (!options.dryRun) {
@@ -53,7 +60,9 @@ async function checkDockerImageExistsLocally(imageRef) {
53
60
  const normalizedImageRef = imageRef.startsWith('docker.io/')
54
61
  ? imageRef.split('docker.io/')[1]
55
62
  : imageRef;
56
- const childProcess = (0, child_process_1.exec)(`docker images --filter "reference=${normalizedImageRef}" --quiet`, { encoding: 'utf8', windowsHide: true });
63
+ // Pass args as an array (no shell) so the reference read back from the
64
+ // .docker-version file can't break out into command injection.
65
+ const childProcess = (0, child_process_1.execFile)('docker', ['images', '--filter', `reference=${normalizedImageRef}`, '--quiet'], { encoding: 'utf8', windowsHide: true });
57
66
  let result = '';
58
67
  childProcess.stdout?.on('data', (data) => {
59
68
  result += data;
@@ -77,7 +86,7 @@ async function checkDockerImageExistsLocally(imageRef) {
77
86
  async function dockerPush(imageReference, quiet) {
78
87
  try {
79
88
  return await new Promise((res, rej) => {
80
- const childProcess = (0, child_process_1.exec)(`docker push ${imageReference}${quiet ? ' --quiet' : ''}`, {
89
+ const childProcess = (0, child_process_1.execFile)('docker', ['push', imageReference, ...(quiet ? ['--quiet'] : [])], {
81
90
  encoding: 'utf8',
82
91
  maxBuffer: exports.LARGE_BUFFER,
83
92
  windowsHide: true,
@@ -1,4 +1,13 @@
1
1
  export interface DockerReleasePublishSchema {
2
2
  dryRun?: boolean;
3
3
  quiet?: boolean;
4
+ nxReleaseVersionData?: Record<
5
+ string,
6
+ {
7
+ currentVersion: string | null;
8
+ newVersion: string | null;
9
+ dockerVersion: string | null;
10
+ [key: string]: any;
11
+ }
12
+ >;
4
13
  }
@@ -4,18 +4,15 @@ exports.createNodesV2 = exports.createNodes = void 0;
4
4
  exports.getProjectNameFromPath = getProjectNameFromPath;
5
5
  const internal_1 = require("@nx/devkit/internal");
6
6
  const devkit_1 = require("@nx/devkit");
7
- const file_hasher_1 = require("nx/src/hasher/file-hasher");
8
- const cache_directory_1 = require("nx/src/utils/cache-directory");
9
7
  const fs_1 = require("fs");
10
8
  const path_1 = require("path");
11
- const git_utils_1 = require("nx/src/utils/git-utils");
12
9
  const interpolate_pattern_1 = require("../utils/interpolate-pattern");
13
10
  const dockerfileGlob = '**/Dockerfile';
14
11
  exports.createNodes = [
15
12
  dockerfileGlob,
16
13
  async (configFilePaths, options, context) => {
17
- const optionsHash = (0, file_hasher_1.hashObject)(options);
18
- const cachePath = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, `docker-${optionsHash}.hash`);
14
+ const optionsHash = (0, internal_1.hashObject)(options);
15
+ const cachePath = (0, path_1.join)(internal_1.workspaceDataDirectory, `docker-${optionsHash}.hash`);
19
16
  const targetsCache = new internal_1.PluginCache(cachePath);
20
17
  const projectRoots = configFilePaths.map((c) => (0, path_1.dirname)(c));
21
18
  const normalizedOptions = normalizePluginOptions(options);
@@ -50,7 +47,7 @@ async function createNodesInternal(configFilePath, hash, normalizedOptions, cont
50
47
  };
51
48
  }
52
49
  function interpolateDockerTargetOptions(options, projectRoot, imageRef, context) {
53
- const commitSha = (0, git_utils_1.getLatestCommitSha)();
50
+ const commitSha = (0, internal_1.getLatestCommitSha)();
54
51
  const projectName = getProjectName(projectRoot, context.workspaceRoot);
55
52
  const tokens = {
56
53
  projectRoot,
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.interpolateVersionPattern = interpolateVersionPattern;
4
- const git_utils_1 = require("nx/src/utils/git-utils");
4
+ const internal_1 = require("@nx/devkit/internal");
5
5
  const interpolate_pattern_1 = require("../utils/interpolate-pattern");
6
6
  function interpolateVersionPattern(versionPattern, data) {
7
- const commitSha = (0, git_utils_1.getLatestCommitSha)();
7
+ const commitSha = (0, internal_1.getLatestCommitSha)();
8
8
  const substitutions = {
9
9
  projectName: data.projectName ?? '',
10
10
  currentDate: data.currentDate ?? new Date(),
@@ -1,7 +1,7 @@
1
1
  import { ProjectGraphProjectNode } from '@nx/devkit';
2
- import type { FinalConfigForProject } from 'nx/src/command-line/release/utils/release-graph';
2
+ import { type FinalConfigForProject } from '@nx/devkit/internal';
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, versionActionsVersion?: string): Promise<{
4
+ export declare function handleDockerVersion(workspaceRoot: string, projectGraphNode: ProjectGraphProjectNode, finalConfigForProject: FinalConfigForProject, dockerVersionScheme?: string, dockerVersion?: string, versionActionsVersion?: string | null): Promise<{
5
5
  newVersion: string;
6
6
  logs: string[];
7
7
  }>;
@@ -5,9 +5,9 @@ exports.handleDockerVersion = handleDockerVersion;
5
5
  const child_process_1 = require("child_process");
6
6
  const fs_1 = require("fs");
7
7
  const path_1 = require("path");
8
- const enquirer_1 = require("enquirer");
9
8
  const devkit_1 = require("@nx/devkit");
10
9
  const version_pattern_utils_1 = require("./version-pattern-utils");
10
+ const internal_1 = require("@nx/devkit/internal");
11
11
  const DEFAULT_VERSION_SCHEMES = {
12
12
  production: '{currentDate|YYMM.DD}.{shortCommitSha}',
13
13
  hotfix: '{currentDate|YYMM.DD}.{shortCommitSha}-hotfix',
@@ -33,6 +33,15 @@ async function handleDockerVersion(workspaceRoot, projectGraphNode, finalConfigF
33
33
  : Object.keys(availableVersionSchemes).length === 1
34
34
  ? Object.keys(availableVersionSchemes)[0]
35
35
  : await promptForNewVersion(availableVersionSchemes, projectGraphNode.name);
36
+ if (availableVersionSchemes[versionScheme].includes('{versionActionsVersion}') &&
37
+ versionActionsVersion == null) {
38
+ return {
39
+ newVersion: null,
40
+ logs: [
41
+ `Skipped ${projectGraphNode.name}, because no new version was resolved for this project.`,
42
+ ],
43
+ };
44
+ }
36
45
  newVersion = calculateNewVersion(projectGraphNode.name, versionScheme, availableVersionSchemes, versionActionsVersion);
37
46
  }
38
47
  }
@@ -43,27 +52,16 @@ async function handleDockerVersion(workspaceRoot, projectGraphNode, finalConfigF
43
52
  };
44
53
  }
45
54
  async function promptForNewVersion(versionSchemes, projectName) {
46
- const { versionScheme } = await (0, enquirer_1.prompt)({
47
- name: 'versionScheme',
48
- type: 'select',
55
+ // Each scheme's resolved pattern renders as its own hint.
56
+ return (0, internal_1.selectPrompt)({
49
57
  message: `What type of docker release would you like to make for project "${projectName}"?`,
50
58
  choices: Object.keys(versionSchemes).map((vs) => ({
51
- name: vs,
52
- message: vs,
53
59
  value: vs,
54
- description: (0, version_pattern_utils_1.interpolateVersionPattern)(versionSchemes[vs], {
60
+ hint: (0, version_pattern_utils_1.interpolateVersionPattern)(versionSchemes[vs], {
55
61
  projectName,
56
62
  }),
57
63
  })),
58
- // Show only the focused scheme's resolved pattern, not every row's at once.
59
- footer: function () {
60
- const focused = this.focused;
61
- return focused?.description
62
- ? this.styles.muted(` ${focused.description}`)
63
- : '';
64
- },
65
64
  });
66
- return versionScheme;
67
65
  }
68
66
  function calculateNewVersion(projectName, versionScheme, versionSchemes, versionActionsVersion) {
69
67
  if (!(versionScheme in versionSchemes)) {
@@ -80,7 +78,9 @@ function updateProjectVersion(newVersion, nxDockerImageRefEnvOverride, workspace
80
78
  const newImageRef = getImageReference(projectRoot, repositoryName, registry);
81
79
  const fullImageRef = nxDockerImageRefEnvOverride ?? `${newImageRef}:${newVersion}`;
82
80
  if (!isDryRun) {
83
- (0, child_process_1.execSync)(`docker tag ${imageRef} ${fullImageRef}`, {
81
+ // argv array, not a shell string - the image ref is assembled from workspace
82
+ // config, CLI flags and env, so it can't be trusted as shell input.
83
+ (0, child_process_1.execFileSync)('docker', ['tag', imageRef, fullImageRef], {
84
84
  windowsHide: true,
85
85
  });
86
86
  }
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": "23.2.0-beta.1",
4
+ "version": "23.2.0-beta.11",
5
5
  "type": "commonjs",
6
6
  "files": [
7
7
  "dist",
@@ -85,11 +85,10 @@
85
85
  "executors": "./executors.json",
86
86
  "generators": "./generators.json",
87
87
  "dependencies": {
88
- "enquirer": "~2.3.6",
89
88
  "tslib": "^2.3.0",
90
- "@nx/devkit": "23.2.0-beta.1"
89
+ "@nx/devkit": "23.2.0-beta.11"
91
90
  },
92
91
  "devDependencies": {
93
- "nx": "23.2.0-beta.1"
92
+ "nx": "23.2.0-beta.11"
94
93
  }
95
94
  }