fix(node): Ensure docker file is generated when nest framework is supplied (#27153)
When we generate a nest application and supply the `--docker` flag it should generate a DockerFile. <!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> Currently, no DockerFile is created. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> A DockerFile to be created. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #17343
This commit is contained in:
parent
2d2c0b5acb
commit
bff23d1b75
29
e2e/node/src/__snapshots__/node.test.ts.snap
Normal file
29
e2e/node/src/__snapshots__/node.test.ts.snap
Normal file
@ -0,0 +1,29 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Node Applications should generate a nest application with docker 1`] = `
|
||||
"# This file is generated by Nx.
|
||||
#
|
||||
# Build the docker image with \`npx nx docker-build node-nest-docker-test\`.
|
||||
# Tip: Modify "docker-build" options in project.json to change docker build args.
|
||||
#
|
||||
# Run the container with \`docker run -p 3000:3000 -t node-nest-docker-test\`.
|
||||
FROM docker.io/node:lts-alpine
|
||||
|
||||
ENV HOST=0.0.0.0
|
||||
ENV PORT=3000
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN addgroup --system node-nest-docker-test && \\
|
||||
adduser --system -G node-nest-docker-test node-nest-docker-test
|
||||
|
||||
COPY dist/node-nest-docker-test node-nest-docker-test/
|
||||
RUN chown -R node-nest-docker-test:node-nest-docker-test .
|
||||
|
||||
# You can remove this install step if you build with \`--bundle\` option.
|
||||
# The bundled output will include external dependencies.
|
||||
RUN npm --prefix node-nest-docker-test --omit=dev -f install
|
||||
|
||||
CMD [ "node", "node-nest-docker-test" ]
|
||||
"
|
||||
`;
|
||||
@ -23,7 +23,7 @@ import {
|
||||
updateFile,
|
||||
updateJson,
|
||||
} from '@nx/e2e/utils';
|
||||
import { exec, execSync } from 'child_process';
|
||||
import { execSync } from 'child_process';
|
||||
import * as http from 'http';
|
||||
import { getLockFileName } from '@nx/js';
|
||||
import { satisfies } from 'semver';
|
||||
@ -58,7 +58,7 @@ describe('Node Applications', () => {
|
||||
beforeAll(() => {
|
||||
originalEnvPort = process.env.PORT;
|
||||
newProject({
|
||||
packages: ['@nx/node', '@nx/express', '@nx/nest'],
|
||||
packages: ['@nx/node', '@nx/express', '@nx/nest', '@nx/webpack'],
|
||||
});
|
||||
});
|
||||
|
||||
@ -340,6 +340,19 @@ module.exports = {
|
||||
await promisifiedTreeKill(p.pid, 'SIGKILL');
|
||||
}, 120000);
|
||||
|
||||
it('should generate a nest application with docker', async () => {
|
||||
const nestapp = 'node-nest-docker-test';
|
||||
|
||||
runCLI(
|
||||
`generate @nx/node:app ${nestapp} --project-name-and-root-format=as-provided --bundler=webpack --framework=nest --docker`
|
||||
);
|
||||
|
||||
checkFilesExist(`${nestapp}/Dockerfile`);
|
||||
|
||||
const dockerFile = readFile(`${nestapp}/Dockerfile`);
|
||||
expect(dockerFile).toMatchSnapshot();
|
||||
});
|
||||
|
||||
// TODO(crystal, @ndcunningham): how do we handle this now?
|
||||
// Revisit when NxWebpackPlugin({}) outputFilename is working.
|
||||
xit('should be able to run ESM applications', async () => {
|
||||
|
||||
@ -396,9 +396,19 @@ export async function applicationGeneratorInternal(tree: Tree, schema: Schema) {
|
||||
...options,
|
||||
skipFormat: true,
|
||||
});
|
||||
tasks.push(nestTasks);
|
||||
|
||||
if (options.docker) {
|
||||
const dockerTask = await setupDockerGenerator(tree, {
|
||||
...options,
|
||||
project: options.name,
|
||||
skipFormat: true,
|
||||
});
|
||||
tasks.push(dockerTask);
|
||||
}
|
||||
return runTasksInSerial(
|
||||
...[
|
||||
nestTasks,
|
||||
...tasks,
|
||||
() => {
|
||||
logShowProjectCommand(options.name);
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user