Skip to content

Commit

Permalink
feat(nx-container): improved configuration generator
Browse files Browse the repository at this point in the history
  • Loading branch information
gperdomor committed Oct 28, 2023
1 parent 83742ed commit eb88944
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 30 deletions.
Empty file removed packages/.gitkeep
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ describe('configuration generator', () => {
[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'],
[4, 'myapp', 'docker', 'nginx', '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'],
[8, 'myapp', 'podman', 'nginx', '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'],
[12, 'myapp', 'kaniko', 'nginx', '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) => {
async (_, projectName, engine: any, template: any, executor, text) => {
const options: ConfigurationSchema = { project: projectName, engine, template };

addProjectConfiguration(tree, projectName, { root: `apps/${projectName}` });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Tree,
updateProjectConfiguration,
} from '@nx/devkit';
import * as path from 'path';
import * as path from 'node:path';
import { DEFAULT_ENGINE, DEFAULT_TEMPLATE } from './constants';
import { ConfigurationSchema } from './schema';

Expand Down Expand Up @@ -51,3 +51,5 @@ export async function configurationGenerator(tree: Tree, options: ConfigurationS
await formatFiles(tree);
}
}

export default configurationGenerator;
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export interface ConfigurationSchema {
/**
* Provide the container engine to be used.
*/
engine?: string;
engine?: 'docker' | 'podman' | 'kaniko';
/**
* Which type of app you are building?.
*/
template?: string;
template?: 'empty' | 'nest' | 'next' | 'nginx';
/**
* Skips formatting the workspace after the generator completes.
*/
Expand Down
41 changes: 18 additions & 23 deletions packages/nx-container/src/generators/configuration/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,72 +7,67 @@
"project": {
"type": "string",
"description": "The name of the project to add the Container setup to.",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "What project would you like to add the Container setup to?"
"x-prompt": "What project would you like to add the Container setup to?",
"x-dropdown": "projects"
},
"engine": {
"type": "string",
"description": "Provide the container engine to be used.",
"$default": {
"index": 1
},
"default": "docker",
"enum": ["docker", "podman", "kaniko"],
"x-prompt": {
"message": "Which type of engine would you like to use?",
"type": "list",
"items": [
{
"value": "docker",
"label": "docker"
"label": "Docker"
},
{
"value": "podman",
"label": "podman"
"label": "Podman"
},
{
"value": "kaniko",
"label": "kaniko"
"label": "Kaniko"
}
]
},
"default": "docker",
"alias": "e"
},
"template": {
"type": "string",
"description": "Which type of app you are building?.",
"$default": {
"index": 2
},
"default": "empty",
"enum": ["empty", "nest", "next", "nginx"],
"x-prompt": {
"message": "Which type of app you are building?",
"type": "list",
"items": [
{
"value": "empty",
"label": "Empty Dockerfile"
},
{
"value": "nest",
"label": "nest"
"label": "Nest Application"
},
{
"value": "next",
"label": "next"
"label": "Next Application"
},
{
"value": "react-angular-spa",
"label": "react-angular-spa"
"value": "nginx",
"label": "Single Page Application"
}
]
},
"default": "",
"alias": "t"
},
"skipFormat": {
"type": "boolean",
"description": "Skips formatting the workspace after the generator completes.",
"$default": {
"index": 3
}
"default": false
}
},
"required": ["project"]
Expand Down

0 comments on commit eb88944

Please sign in to comment.