-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
123 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters