diff --git a/README.md b/README.md index b463475..193e30c 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ This project is mainly used internally within ebizbase projects but we have deci | [npm-playwright][npm-playwright-readme] | This feature will be install playwright via npm with os dependencies and browser binaries | -### devconainer prebuild images +### devconainer images | Name | Description| | ---------- | ---------- | @@ -39,7 +39,7 @@ This project is mainly used internally within ebizbase projects but we have deci ### npm packages | Name | Description| | ---------- | ---------- | -| [nx-devkit][nx-devkit-readme] | The NX plugin to build, push and analyze image | +| [nx-devkit][nx-devkit-readme] | It contains many utility functions for interactive with nx workspace and projects | ### nx plugins | Name | Description| diff --git a/devcontainer-features/omz-plugin/README.md b/devcontainer-features/omz-plugin/README.md index 4364020..2aec027 100644 --- a/devcontainer-features/omz-plugin/README.md +++ b/devcontainer-features/omz-plugin/README.md @@ -12,7 +12,7 @@ This feature will install and active plugins for oh my zsh "zsh-syntax-highlighting:https://github.com/zsh-users/zsh-syntax-highlighting.git", "zsh-autosuggestions:https://github.com/zsh-users/zsh-autosuggestions/archive/refs/tags/v0.7.1.zip" ], - "deleteInactive": false, // you can delete inactive plugins for lighter image + "deleteInactive": false, } } ``` @@ -26,4 +26,5 @@ This feature will install and active plugins for oh my zsh | deleteInactive | Should delete inactive plugins or not | bool | false | **(\*)** See [list of oh-my-zsh preinstalled plugins](https://github.com/ohmyzsh/ohmyzsh/wiki/plugins) + **(\*\*)** We support zip release url or git url. See example [here](https://github.com/ebizbase/dev-infras/blob/fff3b6ab9dd104f899b1a67c72e65c21f6f4e310/devcontainer-images/base-devcontainer/.devcontainer/devcontainer.json#L30) diff --git a/packages/nx-devkit/README.md b/packages/nx-devkit/README.md index 8f00241..53214f2 100644 --- a/packages/nx-devkit/README.md +++ b/packages/nx-devkit/README.md @@ -1,11 +1,49 @@ # nx-devkit -This library was generated with [Nx](https://nx.dev). +It contains many utility functions for interactive with nx workspace and projects -## Building -Run `nx build nx-devkit` to build the library. +## Installation -## Running unit tests +To install the package, run: -Run `nx test nx-devkit` to execute the unit tests via [Jest](https://jestjs.io). +```bash +npm install @ebizbase/nx-devkit +``` + +## Usage + +Here is an example of how to use the `DockerUtils`: + +```typescript +import { DockerUtils } from '@ebizbase/nx-devkit'; + +const dockerService = new DockerUtils(); + +// Check docker installed and docker daemon is running +if (!dockerService.checkDockerInstalled(context.isVerbose)) { + logger.error('Docker is not installed or docker daemon is not running'); + return { success: false }; +} + +// Determine using build or buildx for building Docker image +const isBuildxInstalled = dockerService.checkBuildxInstalled(context.isVerbose); +if (!isBuildxInstalled) { + logger.warn( + 'Buildx is not installed falling back to docker build. Docker buildx is not installed so performance may be degraded' + ); +} +const buildCommand = isBuildxInstalled ? ['docker', 'buildx', 'build'] : ['docker', 'build']; +``` + + +Here is an example of how to use the `DockerUtils`: + +```typescript +import { ProjectUtils } from '@ebizbase/nx-devkit'; +const executor: PromiseExecutor = async (options, context) => { + const projectUtils = new ProjectUtils(context); + const projectRoot: projectUtils.getProjectRoot(); + const projectName: projectUtils.getProjectName(); +}; +``` diff --git a/packages/nx-devkit/package.json b/packages/nx-devkit/package.json index 221314f..be6c11e 100644 --- a/packages/nx-devkit/package.json +++ b/packages/nx-devkit/package.json @@ -2,7 +2,7 @@ "name": "@ebizbase/nx-devkit", "version": "1.0.0", "private": false, - "description": "The nx devkit utils", + "description": "It contains many utility functions for interactive with nx workspace and projects", "bugs": "https://github.com/ebizbase/dev-infras/issues", "repository": { "type": "git", diff --git a/packages/nx-dive/README.md b/packages/nx-dive/README.md index 776b701..d1c2165 100644 --- a/packages/nx-dive/README.md +++ b/packages/nx-dive/README.md @@ -1,11 +1,80 @@ # nx-dive +The NX plugin to using [dive](https://github.com/wagoodman/dive) for analyze image -This library was generated with [Nx](https://nx.dev). +## Prerequisites -## Building +- Ensure you have Docker installed and running on your machine. +- Ensure you have NX installed in your workspace. -Run `nx build nx-dive` to build the library. +## Installation -## Running unit tests +To install plugin run the following command: -Run `nx test nx-dive` to execute the unit tests via [Jest](https://jestjs.io). +```bash +npm install -D @ebizbase/nx-dive +yarn add -D @ebizbase/nx-dive +pnpm add -D @ebizbase/nx-dive +``` + +## Analyze docker image + +The example of @ebizbase/nx-dive:analyze executor + +```json +{ + "targets": { + "analyze": { + "executor": "@ebizbase/nx-docker:analyze", + "options": { + "image": "your-app:latest" + } + } + } +} +``` + +You can validate of image with `ci` option like this + +```json +{ + "targets": { + "analyze": { + "dependsOn": ["build"], + "executor": "@ebizbase/nx-docker:analyze", + "options": { + "image": "your-app:latest", + "ci": true, + "highestUserWastedRatio": 0.1 + } + } + } +} +``` + +Or in ci/cd you can overwrite config with template `--[options]=value.` Example + +```shell +nx run project-name:analyze --ci --highestUserWastedRatio 0.1 +``` + +So ci will failed when wasted ratio greater than 10% + +Bellow is all options of @ebizbase/nx-docker:analyze + +| Option | Type | Description | Default | +| ------------------------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | +| `ci` | boolean | Skip the interactive TUI and validate against CI rules | `false` | +| `highestUserWastedRatio` | number | (only valid with --ci given) highest allowable percentage of bytes wasted (as a ratio between 0-1), otherwise CI validation will fail. (default 0.1) | | +| `highestUserWastedBytes` | number | (only valid with --ci given) highest allowable bytes wasted, otherwise CI validation will fail. Set -1 mean disabled | | +| `lowestEfficiencyRatio` | number | (only valid with --ci given) lowest allowable image efficiency (as a ratio between 0-1), otherwise CI validation will fail. (default 0.9) | | +| `ignoreError` | boolean | Ignore image parsing errors and run the analysis anyway | `false` | +| `source` | string | The container engine to fetch the image from. Allowed values: docker, podman, docker-archive (default docker) | `docker` | +| `image` | string | The image to analyze | | +| `dockerSocket` | string | The docker socket to use for the analysis | | +| `version` | string | The version of dive to use | | + +To check all possible options please check this [schema.json](./src/executors/analyze/schema.json) file + +## License + +This project is licensed under the MIT License. \ No newline at end of file diff --git a/packages/nx-docker/README.md b/packages/nx-docker/README.md index 368060e..b2f78de 100644 --- a/packages/nx-docker/README.md +++ b/packages/nx-docker/README.md @@ -9,7 +9,7 @@ The NX plugin to build, push containers, and analyze images from your applicatio ## Installation -To install the `nx-docker` plugin, run the following command: +To install plugin run the following command: ```bash npm install -D @ebizbase/nx-docker @@ -90,66 +90,6 @@ Bellow is all options of @ebizbase/nx-docker:build To check all possible options please check this [schema.json](./src/executors/build/schema.json) file -## Analyze image - -@ebizbase/nx-docker:analyze using [dive](https://github.com/wagoodman/dive) for analyze image - -The example of analyze executor - -```json -{ - "targets": { - "analyze": { - "dependsOn": ["build"], - "executor": "@ebizbase/nx-docker:analyze", - "options": { - "image": "your-app:latest" - } - } - } -} -``` - -You can validate of image with `ci` option like this - -```json -{ - "targets": { - "analyze": { - "dependsOn": ["build"], - "executor": "@ebizbase/nx-docker:analyze", - "options": { - "image": "your-app:latest", - "ci": true, - "highestUserWastedRatio": 0.1 - } - } - } -} -``` - -Or in ci/cd you can overwrite config with template `--[options]=value.` Example - -```shell -nx run project-name:analyze --ci --highestUserWastedRatio 0.1 -``` - -So ci will failed when wasted ratio greater than 10% - -Bellow is all options of @ebizbase/nx-docker:analyze - -| Option | Type | Description | Default | -| ------------------------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | -| `ci` | boolean | Skip the interactive TUI and validate against CI rules | `false` | -| `highestUserWastedRatio` | number | (only valid with --ci given) highest allowable percentage of bytes wasted (as a ratio between 0-1), otherwise CI validation will fail. (default 0.1) | | -| `highestUserWastedBytes` | number | (only valid with --ci given) highest allowable bytes wasted, otherwise CI validation will fail. Set -1 mean disabled | | -| `lowestEfficiencyRatio` | number | (only valid with --ci given) lowest allowable image efficiency (as a ratio between 0-1), otherwise CI validation will fail. (default 0.9) | | -| `ignoreError` | boolean | Ignore image parsing errors and run the analysis anyway | `false` | -| `source` | string | The container engine to fetch the image from. Allowed values: docker, podman, docker-archive (default docker) | `docker` | -| `image` | string | The image to analyze | | -| `dockerSocket` | string | The docker socket to use for the analysis | | -| `version` | string | The version of dive to use | | - ## License This project is licensed under the MIT License.