-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nx-container): revamped configuration generator
init generator was replaced by the new configuration generator fix #881
- Loading branch information
Showing
16 changed files
with
109 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
3 changes: 3 additions & 0 deletions
3
packages/nx-container/src/generators/configuration/constants.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const DEFAULT_ENGINE = 'docker'; | ||
|
||
export const DEFAULT_TEMPLATE = 'empty'; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
.../react-angular-spa/Dockerfile__template__ → .../react-angular-spa/Dockerfile__template__
This file contains 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM docker.io/nginx:stable-alpine | ||
COPY dist/apps/<%= projectName %>/* /usr/share/nginx/html/ | ||
COPY dist/apps/<%= projectName %>/* /usr/share/nginx/html/ | ||
EXPOSE 80 | ||
CMD ["nginx", "-g", "daemon off;"] |
54 changes: 54 additions & 0 deletions
54
packages/nx-container/src/generators/configuration/generator.spec.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Tree, addProjectConfiguration, readProjectConfiguration } from '@nx/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import { configurationGenerator } from './generator'; | ||
import { ConfigurationSchema } from './schema'; | ||
|
||
describe('configuration generator', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
test.each([ | ||
[1, 'myapp', 'docker', undefined, 'docker', undefined], | ||
[2, 'myapp', 'docker', 'nest', 'docker', 'CMD ["dumb-init", "node", "main.js"]'], | ||
[3, 'myapp', 'docker', 'next', 'docker', 'ENV NEXT_TELEMETRY_DISABLED 1'], | ||
[4, 'myapp', 'docker', 'react-angular-spa', 'docker', 'FROM docker.io/nginx:stable-alpine'], | ||
[5, 'myapp', 'podman', undefined, 'podman', undefined], | ||
[6, 'myapp', 'podman', 'nest', 'podman', 'CMD ["dumb-init", "node", "main.js"]'], | ||
[7, 'myapp', 'podman', 'next', 'podman', 'ENV NEXT_TELEMETRY_DISABLED 1'], | ||
[8, 'myapp', 'podman', 'react-angular-spa', 'podman', 'FROM docker.io/nginx:stable-alpine'], | ||
[9, 'myapp', 'kaniko', undefined, 'kaniko', undefined], | ||
[10, 'myapp', 'kaniko', 'nest', 'kaniko', 'CMD ["dumb-init", "node", "main.js"]'], | ||
[11, 'myapp', 'kaniko', 'next', 'kaniko', 'ENV NEXT_TELEMETRY_DISABLED 1'], | ||
[12, 'myapp', 'kaniko', 'react-angular-spa', 'kaniko', 'FROM docker.io/nginx:stable-alpine'], | ||
])( | ||
'%d - given projectName=%s, engine=%s and template=%s - should generate configuration for %s executor and proper dockerfile', | ||
async (_, projectName, engine, template, executor, text) => { | ||
const options: ConfigurationSchema = { project: projectName, engine, template }; | ||
|
||
addProjectConfiguration(tree, projectName, { root: `apps/${projectName}` }); | ||
|
||
await configurationGenerator(tree, options); | ||
|
||
const project = readProjectConfiguration(tree, projectName); | ||
expect(tree.exists('./apps/myapp/Dockerfile')).toBeTruthy(); | ||
|
||
const contents = tree.read('./apps/myapp/Dockerfile', 'utf-8'); | ||
|
||
if (text) { | ||
expect(contents.includes(text)).toBeTruthy(); | ||
expect(contents.includes(`COPY dist/apps/${projectName}/`)).toBeTruthy(); | ||
} else { | ||
expect(contents).toBe(''); | ||
} | ||
|
||
expect(project.targets).toMatchObject({ | ||
container: { | ||
executor: `@nx-tools/nx-container:${executor}`, | ||
}, | ||
}); | ||
} | ||
); | ||
}); |
This file contains 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
25 changes: 25 additions & 0 deletions
25
packages/nx-container/src/generators/configuration/schema.d.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* eslint-disable */ | ||
/** | ||
* This file was automatically generated by json-schema-to-typescript. | ||
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, | ||
* and run json-schema-to-typescript to regenerate this file. | ||
*/ | ||
|
||
export interface ConfigurationSchema { | ||
/** | ||
* The name of the project to add the Container setup to. | ||
*/ | ||
project: string; | ||
/** | ||
* Provide the container engine to be used. | ||
*/ | ||
engine?: string; | ||
/** | ||
* Which type of app you are building?. | ||
*/ | ||
template?: string; | ||
/** | ||
* Skips formatting the workspace after the generator completes. | ||
*/ | ||
skipFormat?: boolean; | ||
} |
2 changes: 1 addition & 1 deletion
2
...container/src/generators/init/schema.json → .../src/generators/configuration/schema.json
This file contains 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 was deleted.
Oops, something went wrong.