Skip to content

Commit

Permalink
docs: update document
Browse files Browse the repository at this point in the history
  • Loading branch information
johnitvn committed Nov 24, 2024
1 parent a7e2e3d commit bb9ec9b
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 74 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
| ---------- | ---------- |
Expand All @@ -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|
Expand Down
48 changes: 43 additions & 5 deletions packages/nx-devkit/README.md
Original file line number Diff line number Diff line change
@@ -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<DockerExecutorSchema> = async (options, context) => {
const projectUtils = new ProjectUtils(context);
const projectRoot: projectUtils.getProjectRoot();
const projectName: projectUtils.getProjectName();
};
```
2 changes: 1 addition & 1 deletion packages/nx-devkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
79 changes: 74 additions & 5 deletions packages/nx-dive/README.md
Original file line number Diff line number Diff line change
@@ -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.
62 changes: 1 addition & 61 deletions packages/nx-docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

0 comments on commit bb9ec9b

Please sign in to comment.