@dockerforge/core
v0.2.5
Published
DockerForge engine: analyse a local project and generate production-grade Dockerfiles, .dockerignore, and Compose, and lint Dockerfiles. Offline, no network.
Downloads
62
Maintainers
Readme
@dockerforge/core
The engine behind DockerForge. Generate and lint production-grade Dockerfiles from Node. Offline.
Give it a path to a local project and it analyses the stack and returns a Dockerfile, a
.dockerignore, and a Compose file, along with a confidence score and suggested improvements. It
also lints existing Dockerfiles. The package makes no network calls; it only reads the local
filesystem under the path you give it.
Most people should use the @dockerforge/cli
command line tool. Use this package when you want to call the engine from your own Node code.
Install
npm install @dockerforge/coreGenerate
The supported public API is exported from the package root. Internal files under src/engine are
not part of the compatibility contract.
const core = require('@dockerforge/core');
const projectPath = await core.ingestLocal('./my-app');
const result = await core.runDockerfileEngine({ projectPath });
console.log(result.dockerfile); // the generated Dockerfile
console.log(result.dockerignore); // the generated .dockerignore
console.log(result.compose); // the generated Compose file
console.log(result.confidence); // a number between 0 and 1
console.log(result.improvements); // suggested changesrunDockerfileEngine accepts:
| Field | Meaning |
| --- | --- |
| projectPath | Required. Absolute or relative path to the project directory. |
| hints | Optional stack hints, for example { stack: 'node', port: 3000 }. |
| optimise | Set to false to skip the optimisation pass. |
| security | Set to false to skip the security pass. |
projectPath is required because this package is offline. Ingesting a remote git URL or a zip is
part of the hosted product, not this package.
Lint
const { findings, summary } = await core.lint('./Dockerfile');
for (const f of findings) {
console.log(f.severity, f.ruleId, f.message);
}
console.log(summary.counts); // { critical, high, medium, low, info }
console.log(summary.worst); // the highest severity found, or nullLint a string instead of a file:
await core.lint({ dockerfile: 'FROM node\nUSER root\n' });The six rules (DF001–DF006) are documented in the
rules reference.
Errors
The package throws typed errors, each carrying a .code: PathNotFoundError,
NotADirectoryError, UnsupportedStackError, IngestError, and the base DockerForgeError.
They are exported from the package root:
const { PathNotFoundError } = require('@dockerforge/core');See the programmatic API guide for the full surface.
License
Apache-2.0.
