-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix(docker): enhance docker project filtering and configuration handling #33288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AndriiTsok
wants to merge
1
commit into
nrwl:master
Choose a base branch
from
AndriiTsok:nx-docker
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1866,4 +1866,205 @@ describe('ReleaseGroupProcessor', () => { | |
| `); | ||
| }); | ||
| }); | ||
|
|
||
| describe('docker project filtering', () => { | ||
| beforeEach(() => { | ||
| // Set dry-run mode to avoid actual docker command execution in tests | ||
| process.env.NX_DRY_RUN = 'true'; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| // Clean up dry-run mode | ||
| delete process.env.NX_DRY_RUN; | ||
| }); | ||
|
|
||
| it('should only process projects with docker targets when group has docker config', async () => { | ||
| const { nxReleaseConfig, projectGraph, filters } = | ||
| await createNxReleaseConfigAndPopulateWorkspace( | ||
| tree, | ||
| ` | ||
| __default__ ({ "projectsRelationship": "independent", "docker": { "preVersionCommand": "npx nx run-many -t docker:build", "versionSchemes": { "production": "{currentDate|YYMM.DD}.{shortCommitSha}" } } }): | ||
| - [email protected] [js] ({ "targets": { "nx-release-publish": { "executor": "@nx/docker:release-publish" } } }) | ||
| - [email protected] [js] ({ "targets": { "nx-release-publish": { "executor": "@nx/docker:release-publish" } } }) | ||
| - [email protected] [js] | ||
| `, | ||
| { | ||
| version: { | ||
| conventionalCommits: true, | ||
| }, | ||
| }, | ||
| mockResolveCurrentVersion | ||
| ); | ||
|
|
||
| const processor = await createTestReleaseGroupProcessor( | ||
| tree, | ||
| projectGraph, | ||
| nxReleaseConfig, | ||
| filters | ||
| ); | ||
|
|
||
| // Check that only docker projects got dockerOptions | ||
| const apiConfig = | ||
| processor['releaseGraph'].finalConfigsByProject.get('api'); | ||
| const webAppConfig = | ||
| processor['releaseGraph'].finalConfigsByProject.get('web-app'); | ||
| const sharedLibConfig = | ||
| processor['releaseGraph'].finalConfigsByProject.get('shared-lib'); | ||
|
|
||
| // api and web-app should have docker options | ||
| expect(apiConfig).toBeDefined(); | ||
| expect(webAppConfig).toBeDefined(); | ||
| expect(Object.keys(apiConfig!.dockerOptions).length).toBeGreaterThan(0); | ||
| expect(Object.keys(webAppConfig!.dockerOptions).length).toBeGreaterThan( | ||
| 0 | ||
| ); | ||
|
|
||
| // shared-lib should NOT have docker options (empty object) | ||
| expect(sharedLibConfig).toBeDefined(); | ||
| expect(Object.keys(sharedLibConfig!.dockerOptions).length).toBe(0); | ||
| }); | ||
|
|
||
| it('should not apply docker options to projects without docker targets', async () => { | ||
| const { nxReleaseConfig, projectGraph, filters } = | ||
| await createNxReleaseConfigAndPopulateWorkspace( | ||
| tree, | ||
| ` | ||
| __default__ ({ "projectsRelationship": "independent", "docker": { "preVersionCommand": "npx nx run-many -t docker:build", "skipVersionActions": ["docker-app"] } }): | ||
| - [email protected] [js] ({ "targets": { "docker:build": { "executor": "@nx/docker:build" }, "nx-release-publish": { "executor": "@nx/docker:release-publish" } } }) | ||
| - [email protected] [js] | ||
| `, | ||
| { | ||
| version: { | ||
| conventionalCommits: true, | ||
| }, | ||
| }, | ||
| mockResolveCurrentVersion | ||
| ); | ||
|
|
||
| const processor = await createTestReleaseGroupProcessor( | ||
| tree, | ||
| projectGraph, | ||
| nxReleaseConfig, | ||
| filters | ||
| ); | ||
|
|
||
| // Check finalConfigsByProject to ensure npm-package doesn't have docker options | ||
| const dockerAppConfig = | ||
| processor['releaseGraph'].finalConfigsByProject.get('docker-app'); | ||
| const npmPackageConfig = | ||
| processor['releaseGraph'].finalConfigsByProject.get('npm-package'); | ||
|
|
||
| // docker-app should have docker options | ||
| expect(dockerAppConfig).toBeDefined(); | ||
| expect( | ||
| Object.keys(dockerAppConfig!.dockerOptions).length | ||
| ).toBeGreaterThan(0); | ||
|
|
||
| // npm-package should NOT have docker options (empty object) | ||
| expect(npmPackageConfig).toBeDefined(); | ||
| expect(Object.keys(npmPackageConfig!.dockerOptions).length).toBe(0); | ||
| }); | ||
|
|
||
| it('should handle mixed release group with npm and docker projects correctly', async () => { | ||
| const { nxReleaseConfig, projectGraph, filters } = | ||
| await createNxReleaseConfigAndPopulateWorkspace( | ||
| tree, | ||
| ` | ||
| backend-apps ({ "projectsRelationship": "fixed", "docker": { "preVersionCommand": "npx nx affected -t docker:build", "versionSchemes": { "production": "{currentDate|YYMM.DD}.{shortCommitSha}" } } }): | ||
| - [email protected] [js] ({ "targets": { "docker:build": { "executor": "@nx/docker:build" }, "nx-release-publish": { "executor": "@nx/docker:release-publish" } } }) | ||
| - [email protected] [js] ({ "targets": { "docker:build": { "executor": "@nx/docker:build" }, "nx-release-publish": { "executor": "@nx/docker:release-publish" } } }) | ||
| - [email protected] [js] | ||
| `, | ||
| { | ||
| version: { | ||
| conventionalCommits: true, | ||
| }, | ||
| }, | ||
| mockResolveCurrentVersion | ||
| ); | ||
|
|
||
| const processor = await createTestReleaseGroupProcessor( | ||
| tree, | ||
| projectGraph, | ||
| nxReleaseConfig, | ||
| filters | ||
| ); | ||
|
|
||
| // Verify that only docker projects got dockerOptions | ||
| const apiGatewayConfig = | ||
| processor['releaseGraph'].finalConfigsByProject.get('api-gateway'); | ||
| const authServiceConfig = | ||
| processor['releaseGraph'].finalConfigsByProject.get('auth-service'); | ||
| const sharedUtilsConfig = | ||
| processor['releaseGraph'].finalConfigsByProject.get('shared-utils'); | ||
|
|
||
| expect(apiGatewayConfig).toBeDefined(); | ||
| expect(authServiceConfig).toBeDefined(); | ||
| expect(sharedUtilsConfig).toBeDefined(); | ||
|
|
||
| // Docker projects should have docker options | ||
| expect( | ||
| Object.keys(apiGatewayConfig!.dockerOptions).length | ||
| ).toBeGreaterThan(0); | ||
| expect( | ||
| Object.keys(authServiceConfig!.dockerOptions).length | ||
| ).toBeGreaterThan(0); | ||
|
|
||
| // shared-utils should NOT have docker options (empty object) | ||
| expect(Object.keys(sharedUtilsConfig!.dockerOptions).length).toBe(0); | ||
| }); | ||
|
|
||
| it('should skip docker projects that have no new version (no changes)', async () => { | ||
| const { nxReleaseConfig, projectGraph, filters } = | ||
| await createNxReleaseConfigAndPopulateWorkspace( | ||
| tree, | ||
| ` | ||
| __default__ ({ "projectsRelationship": "independent", "docker": { "preVersionCommand": "npx nx run-many -t docker:build", "versionSchemes": { "production": "{currentDate|YYMM.DD}.{shortCommitSha}" } } }): | ||
| - [email protected] [js] ({ "targets": { "nx-release-publish": { "executor": "@nx/docker:release-publish" } } }) | ||
| - [email protected] [js] ({ "targets": { "nx-release-publish": { "executor": "@nx/docker:release-publish" } } }) | ||
| `, | ||
| { | ||
| version: { | ||
| conventionalCommits: true, | ||
| }, | ||
| }, | ||
| mockResolveCurrentVersion | ||
| ); | ||
|
|
||
| const processor = await createTestReleaseGroupProcessor( | ||
| tree, | ||
| projectGraph, | ||
| nxReleaseConfig, | ||
| filters | ||
| ); | ||
|
|
||
| // Simulate that only app-with-changes has a new version | ||
| // Set up mock BEFORE calling processGroups | ||
| mockDeriveSpecifierFromConventionalCommits.mockImplementation( | ||
| (_, __, ___, ____, { name: projectName }) => { | ||
| if (projectName === 'app-with-changes') { | ||
| return 'patch'; | ||
| } | ||
| return 'none'; // app-no-changes has no changes | ||
| } | ||
| ); | ||
|
|
||
| await processor.processGroups(); | ||
|
|
||
| // Verify that processDockerProjects doesn't throw when a project has no new version | ||
| await processor.processDockerProjects('production', '2024.10.test'); | ||
|
|
||
| const versionData = processor.getVersionData(); | ||
|
|
||
| // app-with-changes should have both semver and docker version | ||
| expect(versionData['app-with-changes'].newVersion).toBe('1.0.1'); | ||
| expect(versionData['app-with-changes'].dockerVersion).toBe( | ||
| '2024.10.test' | ||
| ); | ||
|
|
||
| // app-no-changes should have neither (newVersion is null, dockerVersion stays null) | ||
| expect(versionData['app-no-changes'].newVersion).toBeNull(); | ||
| expect(versionData['app-no-changes'].dockerVersion).toBeNull(); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this break the current behavior for projects that have
skipVersionActionsset totrue?