Skip to content

Commit

Permalink
Merge pull request #933 from gperdomor/feature/nx-container-v6
Browse files Browse the repository at this point in the history
feat(nx-container): initial changes for v6
  • Loading branch information
gperdomor authored Nov 7, 2023
2 parents 83742ed + 27a1267 commit b6ad465
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 53 deletions.
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Add files here to ignore them from prettier formatting
/dist
/coverage
/.nx/cache
/tmp
/.nx/cache
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@nx-tools/source",
"description": "NX Tools plugins",
"version": "6.0.0-alpha.1",
"version": "6.0.0-alpha.2",
"license": "MIT",
"scripts": {
"commit": "cz",
Expand Down
Empty file removed packages/.gitkeep
Empty file.
4 changes: 2 additions & 2 deletions packages/ci-context/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nx-tools/ci-context",
"version": "6.0.0-alpha.1",
"version": "6.0.0-alpha.2",
"type": "commonjs",
"author": "gperdomor <[email protected]>",
"repository": "https://github.com/gperdomor/nx-tools",
Expand All @@ -9,7 +9,7 @@
"main": "./src/index.js",
"typings": "./src/index.d.ts",
"dependencies": {
"@nx-tools/core": "6.0.0-alpha.1",
"@nx-tools/core": "6.0.0-alpha.2",
"ci-info": "3.9.0",
"@octokit/openapi-types": "19.0.0",
"@actions/github": "6.0.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/container-metadata/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nx-tools/container-metadata",
"version": "6.0.0-alpha.1",
"version": "6.0.0-alpha.2",
"type": "commonjs",
"author": "gperdomor <[email protected]>",
"repository": "https://github.com/gperdomor/nx-tools",
Expand All @@ -9,8 +9,8 @@
"main": "./src/index.js",
"typings": "./src/index.d.ts",
"dependencies": {
"@nx-tools/ci-context": "6.0.0-alpha.1",
"@nx-tools/core": "6.0.0-alpha.1",
"@nx-tools/ci-context": "6.0.0-alpha.2",
"@nx-tools/core": "6.0.0-alpha.2",
"@renovate/pep440": "1.0.0",
"csv-parse": "5.5.2",
"handlebars": "4.7.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nx-tools/core",
"version": "6.0.0-alpha.1",
"version": "6.0.0-alpha.2",
"type": "commonjs",
"author": "gperdomor <[email protected]>",
"repository": "https://github.com/gperdomor/nx-tools",
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-container/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@nx/dependency-checks": [
"error",
{
"ignoredDependencies": ["dotenv"]
"ignoredDependencies": ["dotenv", "@nx-tools/container-metadata"]
}
]
}
Expand Down
7 changes: 5 additions & 2 deletions packages/nx-container/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nx-tools/nx-container",
"version": "6.0.0-alpha.1",
"version": "6.0.0-alpha.2",
"author": "gperdomor <[email protected]>",
"repository": "https://github.com/gperdomor/nx-tools",
"bugs": "https://github.com/gperdomor/nx-tools/issues",
Expand All @@ -11,7 +11,7 @@
"generators": "./generators.json",
"executors": "./executors.json",
"dependencies": {
"@nx-tools/core": "5.0.3",
"@nx-tools/core": "6.0.0-alpha.2",
"tmp": "0.2.1",
"csv-parse": "5.5.2",
"semver": "7.5.4",
Expand All @@ -21,5 +21,8 @@
"dotenv": ">=16.0.0",
"@nx/devkit": "^16.0.0 || ^17.0.0",
"tslib": "^2.5.3"
},
"optionalDependencies": {
"@nx-tools/container-metadata": "6.0.0-alpha.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM docker.io/node:lts-alpine as deps
RUN apk add --no-cache libc6-compat
WORKDIR /usr/src/app
COPY dist/apps/<%= projectName %>/package*.json ./
RUN npm install --only=production
RUN npm install --omit=dev

# Production image, copy all the files and run nest
FROM docker.io/node:lts-alpine as runner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM docker.io/node:lts-alpine as deps
RUN apk add --no-cache libc6-compat
WORKDIR /usr/src/app
COPY dist/apps/<%= projectName %>/package*.json ./
RUN npm install --only=production
RUN npm install --omit=dev

# Production image, copy all the files and run next
FROM docker.io/node:lts-alpine as runner
Expand Down
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 All @@ -46,7 +46,10 @@ describe('configuration generator', () => {

expect(project.targets).toMatchObject({
container: {
executor: `@nx-tools/nx-container:${executor}`,
executor: `@nx-tools/nx-container:build`,
options: {
engine: executor,
},
},
});
}
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 All @@ -26,9 +26,10 @@ export async function configurationGenerator(tree: Tree, options: ConfigurationS
targets: {
...project.targets,
container: {
executor: `@nx-tools/nx-container:${options.engine ?? DEFAULT_ENGINE}`,
executor: `@nx-tools/nx-container:build`,
dependsOn: ['build'],
options: {
engine: options.engine ?? DEFAULT_ENGINE,
metadata: {
images: [project.name],
load: true,
Expand All @@ -51,3 +52,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
4 changes: 2 additions & 2 deletions packages/nx-graphql-codegen/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nx-tools/nx-graphql-codegen",
"version": "6.0.0-alpha.1",
"version": "6.0.0-alpha.2",
"type": "commonjs",
"author": "Rene Bonilla <[email protected]>",
"repository": "https://github.com/gperdomor/nx-tools",
Expand All @@ -11,7 +11,7 @@
"generators": "./generators.json",
"executors": "./executors.json",
"dependencies": {
"@nx-tools/core": "6.0.0-alpha.1"
"@nx-tools/core": "6.0.0-alpha.2"
},
"peerDependencies": {
"@nx/devkit": "^16.0.0 || ^17.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/nx-prisma/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nx-tools/nx-prisma",
"version": "6.0.0-alpha.1",
"version": "6.0.0-alpha.2",
"type": "commonjs",
"author": "gperdomor <[email protected]>",
"contributors": [
Expand All @@ -14,7 +14,7 @@
"executors": "./executors.json",
"generators": "./generators.json",
"dependencies": {
"@nx-tools/core": "6.0.0-alpha.1"
"@nx-tools/core": "6.0.0-alpha.2"
},
"peerDependencies": {
"@nx/devkit": "^16.0.0 || ^17.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/nx-set-shas/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "@nx-tools/nx-set-shas",
"version": "6.0.0-alpha.1",
"version": "6.0.0-alpha.2",
"type": "commonjs",
"bin": {
"nx-set-shas": "./src/index.js"
},
"main": "./src/index.js",
"typings": "./src/index.d.ts",
"dependencies": {
"@nx-tools/core": "6.0.0-alpha.1",
"@nx-tools/core": "6.0.0-alpha.2",
"chalk": "4.1.2",
"commander": "11.1.0",
"undici": "5.26.5"
Expand Down

0 comments on commit b6ad465

Please sign in to comment.