@oxog/dockcraft 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +220 -0
- package/README.md +132 -21
- package/dist/cli/index.js +912 -439
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +736 -386
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -12
- package/dist/index.d.ts +29 -12
- package/dist/index.js +732 -382
- package/dist/index.js.map +1 -1
- package/package.json +32 -16
- package/dist/cli/index.cjs +0 -2095
- package/dist/cli/index.cjs.map +0 -1
- package/dist/cli/index.d.cts +0 -6
- package/dist/cli/index.d.ts +0 -6
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.1.1] - 2026-12-01
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **`--output ./docker` / `output.dir` produced a compose file that could not
|
|
13
|
+
build.** It said `build: .`, which Compose resolves relative to the compose
|
|
14
|
+
file, so the build context was `./docker` (no `package.json`). When the
|
|
15
|
+
output directory is a subdirectory of the working directory, the app now builds
|
|
16
|
+
from the project root: `build: { context: .., dockerfile: docker/Dockerfile }`.
|
|
17
|
+
Docker only reads `.dockerignore` from the context root, so in that case the
|
|
18
|
+
ignore file is now written as `docker/Dockerfile.dockerignore` (the
|
|
19
|
+
Dockerfile-specific ignore file BuildKit reads) instead of `docker/.dockerignore`,
|
|
20
|
+
and it also keeps the generated files and `docker/.env*` out of the image.
|
|
21
|
+
`dockcraft generate` prints the matching `docker compose -f docker/docker-compose.yml up -d`.
|
|
22
|
+
Output to the working directory (the default) or to a directory outside it is
|
|
23
|
+
unchanged (`build: .`, `.dockerignore`).
|
|
24
|
+
- docker-compose.yml no longer contains `version: "3.9"`, which Docker Compose v2
|
|
25
|
+
reports as obsolete on every command.
|
|
26
|
+
- The app container got `POSTGRES_URL` while `.env.example` documented the same
|
|
27
|
+
value as `DATABASE_URL`. Both files now contain both names (`DATABASE_URL` is an
|
|
28
|
+
alias of `POSTGRES_URL`; nothing was renamed, so existing apps keep working).
|
|
29
|
+
`.env.example` also lists `<SERVICE>_URL` for plugin services, which the app
|
|
30
|
+
container already received. MySQL, MongoDB and Redis variables already matched.
|
|
31
|
+
- `PortConflictError`, `NoPortAvailableError` and `FileWriteError` were exported
|
|
32
|
+
but never thrown. `resolvePort` now rejects with `PortConflictError` (port of a
|
|
33
|
+
`'fixed'` strategy in use) and `NoPortAvailableError` (no free port in the range or
|
|
34
|
+
above the preferred port; the `'auto'` message is now
|
|
35
|
+
`No available port in range <port>-65535`), and failed file writes in
|
|
36
|
+
`dockcraft()` and `dockcraft init` reject with `FileWriteError`, whose message
|
|
37
|
+
includes the file system error and whose `cause` is that error. They still are
|
|
38
|
+
`instanceof Error` (and `DockcraftError`).
|
|
39
|
+
- `dockcraft init` without a terminal (CI, piped or closed stdin) and without
|
|
40
|
+
`-y` stopped at the first prompt and exited with code 0 without writing a
|
|
41
|
+
config. It now exits with code 1 and says to pass `-y`/`--yes` (or to run it in
|
|
42
|
+
a terminal); it still runs when every needed value is given as an option.
|
|
43
|
+
|
|
44
|
+
## [1.1.0] - 2026-11-30
|
|
45
|
+
|
|
46
|
+
### Fixed
|
|
47
|
+
|
|
48
|
+
- **CLI did not run when installed.** The `dockcraft` bin had no shebang (the shell
|
|
49
|
+
tried to execute JavaScript) and only started when `process.argv[1]` was the
|
|
50
|
+
real file path, so `npx @oxog/dockcraft` and `node_modules/.bin/dockcraft`
|
|
51
|
+
failed or did nothing.
|
|
52
|
+
- `dockcraft generate` resolved a relative `--config` path against the installed
|
|
53
|
+
package instead of the working directory, so the default `./dockcraft.config.ts`
|
|
54
|
+
was never found. It now resolves against the working directory, searches
|
|
55
|
+
`dockcraft.config.{ts,mts,js,mjs,cjs}`, and requires a default export (with a clear
|
|
56
|
+
error message instead of silently running a config's side effects).
|
|
57
|
+
- `dockcraft init` wrote user input (name, port, preset, services) verbatim into
|
|
58
|
+
the generated config module, allowing code injection into a file that
|
|
59
|
+
`generate` then executes. Values are now validated and emitted as JSON literals.
|
|
60
|
+
`init` also no longer silently overwrites an existing config (use `--force`).
|
|
61
|
+
- docker-compose.yml was invalid YAML whenever a map had a single key
|
|
62
|
+
(`environment: REDIS_PASSWORD: secret`, `volumes: redis_data: null`) and
|
|
63
|
+
contained `volumes: undefined` for every app without volumes.
|
|
64
|
+
- YAML strings were not quoted when they contained `,` inside flow sequences or
|
|
65
|
+
were YAML keywords/numbers (`yes`, `off`, `~`, `0x1F`, `1e3`); keys were never quoted.
|
|
66
|
+
- A custom service `port` changed the container port too: `postgres: { port: 5433 }`
|
|
67
|
+
published `5433:5433` while Postgres listens on 5432, and connection strings used
|
|
68
|
+
5433. The option is now the host port (`5433:5432`); containers keep using the
|
|
69
|
+
default port. `'auto'` and ranges behave the same way. Host port conflicts are
|
|
70
|
+
checked on the published ports (including extra ports).
|
|
71
|
+
- `redis: { version: '7-alpine' }` (README example) produced the non-existent image
|
|
72
|
+
`redis:7-alpine-alpine` (same for Postgres); `latest` produced `*:latest-alpine`.
|
|
73
|
+
- `redis: { password }` had no effect: the official image ignores `REDIS_PASSWORD`.
|
|
74
|
+
The service now runs with `--requirepass` (read from the container environment),
|
|
75
|
+
the health check authenticates via `REDISCLI_AUTH`, and `REDIS_URL` includes the
|
|
76
|
+
password.
|
|
77
|
+
- Passwords containing `$` were interpolated by Docker Compose; environment values
|
|
78
|
+
are now written literally (`$` → `$$`).
|
|
79
|
+
- Connection strings did not percent-encode user, password or database, so
|
|
80
|
+
passwords with `@`, `:`, `/`, `#` produced broken URLs (also in `getConnectionString`).
|
|
81
|
+
- MongoDB connection strings lacked `?authSource=admin`; the image creates the root
|
|
82
|
+
user in the `admin` database, so authentication against the app database failed.
|
|
83
|
+
- The default database name was always `myapp` although documented as the project
|
|
84
|
+
name.
|
|
85
|
+
- Custom services used a numeric image tag as port (`image: 'redis:7'` → `7:7`) and
|
|
86
|
+
their `command` as health check (starting a second server process).
|
|
87
|
+
- The Dockerfile ignored `app.command` (always `CMD ["npm", "start"]`) and
|
|
88
|
+
`app.buildCommand` (always `npm run build`), and swallowed build failures with
|
|
89
|
+
`|| true`. `buildCommand: ''` now skips the build step.
|
|
90
|
+
- The compose health check for the app used `curl`, which is not installed in
|
|
91
|
+
`node:*-alpine` images, so the app was always unhealthy; it now uses `node`.
|
|
92
|
+
- `app.env` (required variables) was only listed in `.env.example`; the names are
|
|
93
|
+
now also passed through to the app container.
|
|
94
|
+
- Bind mounts (`./data:/app/data`) were declared as named volumes; app volumes were
|
|
95
|
+
never declared.
|
|
96
|
+
- `.dockerignore` let `.env.production` and other `.env.*` files into the image.
|
|
97
|
+
- `.env.example` values with spaces, `#`, `$`, quotes or newlines were written
|
|
98
|
+
unquoted (a newline could add extra variables).
|
|
99
|
+
- Generated `make clean` ran `docker system prune -f`, deleting unrelated stopped
|
|
100
|
+
containers, networks and images on the machine.
|
|
101
|
+
- Service names were not validated and were written verbatim into generated shell
|
|
102
|
+
scripts and the Makefile (`'x; rm -rf ~'` became a command).
|
|
103
|
+
- Validation accepted out-of-range ports (`99999`), `null` ports, invalid image tags
|
|
104
|
+
(`-alpine`) and images, multi-line commands/workdirs (Dockerfile instruction
|
|
105
|
+
injection) and health check paths containing quotes. The image check now follows
|
|
106
|
+
Docker's reference grammar (registries with ports, underscores, digests).
|
|
107
|
+
- `config.plugins` was accepted but ignored; plugin services now resolve and plugin
|
|
108
|
+
`outputs` are generated (only inside the output directory; paths with `..` or
|
|
109
|
+
absolute paths are rejected).
|
|
110
|
+
- `isPortAvailable` left a 1 second timer running after every check (keeping the
|
|
111
|
+
process alive) and threw asynchronously for invalid ports; it now rejects with a
|
|
112
|
+
`RangeError`.
|
|
113
|
+
- `deepMerge` (preset merging) let a `__proto__` key replace the merged object's
|
|
114
|
+
prototype.
|
|
115
|
+
- `dockcraft ports --json` printed a title before the JSON; `ports --check abc`
|
|
116
|
+
printed a Node.js internal error; `dockcraft presets <unknown>` exited with 0.
|
|
117
|
+
- Generated shell scripts are written executable (`0755`); concurrent writes of the
|
|
118
|
+
same file no longer share a temp file.
|
|
119
|
+
- README examples that did not compile (`checkPort`, preset without `app`).
|
|
120
|
+
|
|
121
|
+
### Added
|
|
122
|
+
|
|
123
|
+
- `CustomServiceConfig.healthcheck` for custom services.
|
|
124
|
+
- `app` is optional in `DockcraftConfig` and `app.port` defaults to 3000.
|
|
125
|
+
- `dockcraft help [command]`, `dockcraft init --force`.
|
|
126
|
+
- Typed errors: `dockcraft()` throws `ValidationErrorClass` (with `errors`),
|
|
127
|
+
`PresetNotFoundError` and `ServiceNotFoundError`.
|
|
128
|
+
|
|
129
|
+
### Changed
|
|
130
|
+
|
|
131
|
+
- Generated scripts and Makefile use the Docker Compose v2 CLI (`docker compose`);
|
|
132
|
+
`docker-compose` v1 is end-of-life and not shipped with current Docker.
|
|
133
|
+
- `dockcraft init` writes `dockcraft.config.mts` with a type-only import
|
|
134
|
+
(`export default { ... } satisfies DockcraftConfig`), which loads in CommonJS and
|
|
135
|
+
ESM projects without a local install (Node.js 22.18+ type stripping).
|
|
136
|
+
- The CLI sets the exit code instead of calling `process.exit()`; every error exits 1.
|
|
137
|
+
- Error messages for unknown services changed to `Service '<name>' not found`.
|
|
138
|
+
- Packaging: `exports` now has separate `import`/`require` conditions with matching
|
|
139
|
+
declaration files (`index.d.ts` / `index.d.cts`) and exposes `./package.json`.
|
|
140
|
+
The CLI is built once as ESM with a shebang (no unused CJS/d.ts CLI files).
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## [1.0.0] - 2025-01-XX
|
|
145
|
+
|
|
146
|
+
### Added
|
|
147
|
+
|
|
148
|
+
- Zero-dependency Docker orchestration toolkit
|
|
149
|
+
- Config-driven Docker file generation
|
|
150
|
+
- Built-in service presets (PostgreSQL, MySQL, MongoDB, Redis)
|
|
151
|
+
- Smart port management with auto-resolve
|
|
152
|
+
- Connection string generation
|
|
153
|
+
- Preset system with 11 pre-configured stacks
|
|
154
|
+
- Full CLI with interactive wizard
|
|
155
|
+
- Programmatic API
|
|
156
|
+
- TypeScript strict mode support
|
|
157
|
+
- 100% test coverage
|
|
158
|
+
|
|
159
|
+
### Features
|
|
160
|
+
|
|
161
|
+
#### Core
|
|
162
|
+
- `dockcraft()` - Main generation function
|
|
163
|
+
- `defineConfig()` - Configuration helper
|
|
164
|
+
- Config validation and resolution
|
|
165
|
+
- Port conflict detection and resolution
|
|
166
|
+
|
|
167
|
+
#### Services
|
|
168
|
+
- PostgreSQL service definition
|
|
169
|
+
- MySQL service definition
|
|
170
|
+
- MongoDB service definition
|
|
171
|
+
- Redis service definition
|
|
172
|
+
- Custom service support
|
|
173
|
+
|
|
174
|
+
#### Presets
|
|
175
|
+
- Express + PostgreSQL
|
|
176
|
+
- Express + PostgreSQL + Redis
|
|
177
|
+
- Express + MongoDB
|
|
178
|
+
- Express + MongoDB + Redis
|
|
179
|
+
- Express + MySQL
|
|
180
|
+
- Express + MySQL + Redis
|
|
181
|
+
- Fastify + PostgreSQL
|
|
182
|
+
- Fastify + PostgreSQL + Redis
|
|
183
|
+
- NestJS + PostgreSQL
|
|
184
|
+
- NestJS + MongoDB
|
|
185
|
+
- Node.js minimal
|
|
186
|
+
|
|
187
|
+
#### CLI
|
|
188
|
+
- `dockcraft init` - Interactive configuration wizard
|
|
189
|
+
- `dockcraft generate` - Generate Docker files
|
|
190
|
+
- `dockcraft ports` - Port checking utilities
|
|
191
|
+
- `dockcraft presets` - List and show presets
|
|
192
|
+
|
|
193
|
+
#### Generators
|
|
194
|
+
- Dockerfile (multi-stage)
|
|
195
|
+
- docker-compose.yml
|
|
196
|
+
- .dockerignore
|
|
197
|
+
- .env.example
|
|
198
|
+
- Shell scripts (build, up, down, logs)
|
|
199
|
+
- Makefile
|
|
200
|
+
|
|
201
|
+
#### Utilities
|
|
202
|
+
- Port scanner and resolver
|
|
203
|
+
- YAML generator (no dependencies)
|
|
204
|
+
- File system utilities
|
|
205
|
+
- String utilities
|
|
206
|
+
- Template engine
|
|
207
|
+
- Deep merge utility
|
|
208
|
+
|
|
209
|
+
### Documentation
|
|
210
|
+
- Complete API reference
|
|
211
|
+
- CLI reference
|
|
212
|
+
- Service configuration guide
|
|
213
|
+
- Preset reference
|
|
214
|
+
- Examples
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
[1.1.1]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.1.1
|
|
219
|
+
[1.1.0]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.1.0
|
|
220
|
+
[1.0.0]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.0.0
|
package/README.md
CHANGED
|
@@ -35,14 +35,15 @@ npx @oxog/dockcraft init --preset express-postgres-redis
|
|
|
35
35
|
npx @oxog/dockcraft generate
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
###
|
|
38
|
+
### Config file
|
|
39
39
|
|
|
40
|
-
Create `dockcraft.config.ts
|
|
40
|
+
Create `dockcraft.config.ts` (or `.mts`, `.js`, `.mjs`, `.cjs`) and export the
|
|
41
|
+
configuration as the default export:
|
|
41
42
|
|
|
42
43
|
```typescript
|
|
43
|
-
import {
|
|
44
|
+
import { defineConfig } from '@oxog/dockcraft';
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
export default defineConfig({
|
|
46
47
|
name: 'my-api',
|
|
47
48
|
app: {
|
|
48
49
|
port: 3000,
|
|
@@ -67,6 +68,13 @@ This creates:
|
|
|
67
68
|
- `.dockerignore` - Optimized file exclusion
|
|
68
69
|
- `.env.example` - Environment variables with connection strings
|
|
69
70
|
|
|
71
|
+
Existing files are kept unless you pass `--force`.
|
|
72
|
+
|
|
73
|
+
TypeScript config files are loaded with Node.js type stripping (Node.js 22.18+
|
|
74
|
+
or 23.6+). On older Node.js versions use `dockcraft.config.mjs`. `dockcraft init`
|
|
75
|
+
writes `dockcraft.config.mts`, which loads as an ES module in any project and
|
|
76
|
+
only uses a type import, so it also works with `npx` without a local install.
|
|
77
|
+
|
|
70
78
|
## CLI Usage
|
|
71
79
|
|
|
72
80
|
```bash
|
|
@@ -89,6 +97,19 @@ dockcraft ports --check 3000,5432,6379
|
|
|
89
97
|
dockcraft presets
|
|
90
98
|
```
|
|
91
99
|
|
|
100
|
+
`init` refuses to overwrite an existing config unless `--force` is given.
|
|
101
|
+
Without a terminal (CI, piped stdin) `init` cannot prompt: pass `-y` to use
|
|
102
|
+
the defaults for every value not given as an option, otherwise it exits with
|
|
103
|
+
code 1.
|
|
104
|
+
|
|
105
|
+
`generate --output ./docker` (or `output.dir`) writes the files to a
|
|
106
|
+
subdirectory; the compose file then builds from the project root
|
|
107
|
+
(`build: { context: .., dockerfile: docker/Dockerfile }`) and the ignore file is
|
|
108
|
+
written as `docker/Dockerfile.dockerignore`, which BuildKit reads for that
|
|
109
|
+
Dockerfile. Run it with `docker compose -f docker/docker-compose.yml up -d`.
|
|
110
|
+
Commands exit with code 1 on errors (invalid config, unknown command or
|
|
111
|
+
preset, invalid ports). `dockcraft ports --json` prints JSON only.
|
|
112
|
+
|
|
92
113
|
## API Usage
|
|
93
114
|
|
|
94
115
|
```typescript
|
|
@@ -98,15 +119,21 @@ import {
|
|
|
98
119
|
getPreset,
|
|
99
120
|
listPresets,
|
|
100
121
|
resolvePort,
|
|
101
|
-
|
|
122
|
+
isPortAvailable,
|
|
123
|
+
checkPorts,
|
|
102
124
|
getConnectionString,
|
|
103
125
|
} from '@oxog/dockcraft';
|
|
104
126
|
```
|
|
105
127
|
|
|
106
128
|
### Main Function
|
|
107
129
|
|
|
130
|
+
`dockcraft()` validates the config, resolves presets, services and ports, and
|
|
131
|
+
writes the files (or only returns them with `{ dryRun: true }`). Invalid
|
|
132
|
+
configuration throws a `ValidationErrorClass` (a `DockcraftError`) whose
|
|
133
|
+
`errors` array lists every problem.
|
|
134
|
+
|
|
108
135
|
```typescript
|
|
109
|
-
await dockcraft({
|
|
136
|
+
const result = await dockcraft({
|
|
110
137
|
name: 'my-app',
|
|
111
138
|
preset: 'express-postgres',
|
|
112
139
|
app: {
|
|
@@ -121,13 +148,22 @@ await dockcraft({
|
|
|
121
148
|
overwrite: false,
|
|
122
149
|
},
|
|
123
150
|
});
|
|
151
|
+
|
|
152
|
+
result.files; // Map<file name, content>
|
|
153
|
+
result.written; // paths written to disk
|
|
154
|
+
|
|
155
|
+
// Preview only
|
|
156
|
+
const preview = await dockcraft(config, { dryRun: true });
|
|
124
157
|
```
|
|
125
158
|
|
|
126
159
|
### Port Utilities
|
|
127
160
|
|
|
128
161
|
```typescript
|
|
129
162
|
// Check if port is available
|
|
130
|
-
const available = await
|
|
163
|
+
const available = await isPortAvailable(3000);
|
|
164
|
+
|
|
165
|
+
// Check several ports
|
|
166
|
+
const results = await checkPorts([3000, 5432]); // Map<port, boolean>
|
|
131
167
|
|
|
132
168
|
// Resolve port (auto-find if taken)
|
|
133
169
|
const port = await resolvePort({
|
|
@@ -136,12 +172,17 @@ const port = await resolvePort({
|
|
|
136
172
|
});
|
|
137
173
|
|
|
138
174
|
// Find in range
|
|
139
|
-
const
|
|
140
|
-
|
|
175
|
+
const portInRange = await resolvePort({
|
|
176
|
+
strategy: 'range',
|
|
141
177
|
range: [3000, 3100],
|
|
142
178
|
});
|
|
143
179
|
```
|
|
144
180
|
|
|
181
|
+
`resolvePort` rejects with a `PortConflictError` when a `'fixed'` port is in
|
|
182
|
+
use and with a `NoPortAvailableError` when no port is free; failed writes in
|
|
183
|
+
`dockcraft()` reject with a `FileWriteError` (its `cause` is the file system
|
|
184
|
+
error). All of them extend `DockcraftError` (and `Error`) and have a `code`.
|
|
185
|
+
|
|
145
186
|
### Connection Strings
|
|
146
187
|
|
|
147
188
|
```typescript
|
|
@@ -155,24 +196,45 @@ const url = getConnectionString('postgres', {
|
|
|
155
196
|
// => postgres://postgres:postgres@localhost:5432/myapp
|
|
156
197
|
```
|
|
157
198
|
|
|
199
|
+
User, password and database are percent-encoded, MongoDB URLs include
|
|
200
|
+
`?authSource=admin`, and Redis URLs include the password when one is given
|
|
201
|
+
(`redis://:secret@localhost:6379`).
|
|
202
|
+
|
|
158
203
|
## Configuration
|
|
159
204
|
|
|
160
205
|
### App Configuration
|
|
161
206
|
|
|
162
207
|
```typescript
|
|
163
208
|
app: {
|
|
164
|
-
port: 3000, // App port or 'auto'
|
|
165
|
-
node: '20-alpine', // Node.js
|
|
166
|
-
workdir: '/app', // Working directory
|
|
167
|
-
command: 'npm start', //
|
|
168
|
-
buildCommand: 'npm run build',
|
|
209
|
+
port: 3000, // App port or 'auto' (default: 3000)
|
|
210
|
+
node: '20-alpine', // Node.js image tag
|
|
211
|
+
workdir: '/app', // Working directory (absolute path)
|
|
212
|
+
command: 'npm start', // Dockerfile CMD
|
|
213
|
+
buildCommand: 'npm run build', // Builder stage command; '' = no build step
|
|
169
214
|
multiStage: true, // Multi-stage build
|
|
170
|
-
healthcheck: '/health', // Health endpoint
|
|
171
|
-
env: ['API_KEY'], // Required env vars
|
|
215
|
+
healthcheck: '/health', // Health endpoint (2xx = healthy)
|
|
216
|
+
env: ['API_KEY'], // Required env vars (.env.example + passed to the app container)
|
|
172
217
|
volumes: ['./data:/app/data'],
|
|
173
218
|
}
|
|
174
219
|
```
|
|
175
220
|
|
|
221
|
+
`app` is optional when a preset provides it.
|
|
222
|
+
|
|
223
|
+
### Ports
|
|
224
|
+
|
|
225
|
+
`port` on a service is the **host** port. The container keeps listening on the
|
|
226
|
+
service's default port, so `postgres: { port: 5433 }` publishes `5433:5432`
|
|
227
|
+
and other containers still connect to `postgres:5432`. `'auto'` picks the first
|
|
228
|
+
free host port from the default port up; `{ start, end }` picks one in a range.
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
services: {
|
|
232
|
+
postgres: { port: 5433 }, // 5433:5432
|
|
233
|
+
redis: { port: 'auto' }, // first free host port from 6379
|
|
234
|
+
mongo: { port: { start: 27100, end: 27200 } },
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
176
238
|
### Service Configuration
|
|
177
239
|
|
|
178
240
|
```typescript
|
|
@@ -180,7 +242,7 @@ services: {
|
|
|
180
242
|
postgres: {
|
|
181
243
|
version: '16',
|
|
182
244
|
port: 5432,
|
|
183
|
-
database: 'myapp',
|
|
245
|
+
database: 'myapp', // default: project name
|
|
184
246
|
user: 'postgres',
|
|
185
247
|
password: 'postgres',
|
|
186
248
|
},
|
|
@@ -193,6 +255,9 @@ services: {
|
|
|
193
255
|
|
|
194
256
|
### Custom Services
|
|
195
257
|
|
|
258
|
+
Any service with an `image` is a custom service. Its `port` is used for both
|
|
259
|
+
the container and the host (default: 80).
|
|
260
|
+
|
|
196
261
|
```typescript
|
|
197
262
|
services: {
|
|
198
263
|
elasticsearch: {
|
|
@@ -202,10 +267,40 @@ services: {
|
|
|
202
267
|
'discovery.type': 'single-node',
|
|
203
268
|
},
|
|
204
269
|
volumes: ['es_data:/usr/share/elasticsearch/data'],
|
|
270
|
+
healthcheck: 'curl -fs localhost:9200', // optional, run with CMD-SHELL
|
|
205
271
|
},
|
|
206
272
|
}
|
|
207
273
|
```
|
|
208
274
|
|
|
275
|
+
Service names must match `[a-zA-Z0-9][a-zA-Z0-9_.-]*` and images must be valid
|
|
276
|
+
Docker image references. Environment values are written literally: a `$` is
|
|
277
|
+
escaped as `$$` in `docker-compose.yml`, so Compose does not interpolate it.
|
|
278
|
+
|
|
279
|
+
### Plugins
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
import { defineConfig, defineService } from '@oxog/dockcraft';
|
|
283
|
+
|
|
284
|
+
const rabbitmq = defineService({
|
|
285
|
+
name: 'rabbitmq',
|
|
286
|
+
image: (version) => `rabbitmq:${version}-management`,
|
|
287
|
+
defaultPort: 5672,
|
|
288
|
+
defaultVersion: '3',
|
|
289
|
+
ports: [15672],
|
|
290
|
+
connectionString: (svc) => `amqp://guest:guest@${svc.name}:${svc.port}`,
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
export default defineConfig({
|
|
294
|
+
name: 'my-api',
|
|
295
|
+
plugins: [
|
|
296
|
+
rabbitmq,
|
|
297
|
+
// Extra output files, written relative to output.dir
|
|
298
|
+
{ name: 'notes', outputs: [{ name: 'notes', file: 'docker/NOTES.md', generate: (c) => `# ${c.name}\n` }] },
|
|
299
|
+
],
|
|
300
|
+
services: { rabbitmq: {} },
|
|
301
|
+
});
|
|
302
|
+
```
|
|
303
|
+
|
|
209
304
|
## Presets
|
|
210
305
|
|
|
211
306
|
Available presets:
|
|
@@ -280,7 +375,7 @@ mongo: {
|
|
|
280
375
|
}
|
|
281
376
|
```
|
|
282
377
|
|
|
283
|
-
Connection: `mongodb://user:pass@host:port/db`
|
|
378
|
+
Connection: `mongodb://user:pass@host:port/db?authSource=admin`
|
|
284
379
|
|
|
285
380
|
### Redis
|
|
286
381
|
|
|
@@ -291,7 +386,10 @@ redis: {
|
|
|
291
386
|
}
|
|
292
387
|
```
|
|
293
388
|
|
|
294
|
-
Connection: `redis://host:port`
|
|
389
|
+
Connection: `redis://host:port`, or `redis://:password@host:port` with a password.
|
|
390
|
+
The official Redis image ignores `REDIS_PASSWORD`, so with a password the
|
|
391
|
+
service is started with `--requirepass` (read from the container environment)
|
|
392
|
+
and the health check authenticates via `REDISCLI_AUTH`.
|
|
295
393
|
|
|
296
394
|
## Generated Files
|
|
297
395
|
|
|
@@ -305,7 +403,7 @@ Multi-stage build with:
|
|
|
305
403
|
|
|
306
404
|
### docker-compose.yml
|
|
307
405
|
|
|
308
|
-
|
|
406
|
+
Compose Specification file (no obsolete top-level `version`) with:
|
|
309
407
|
- All services with dependencies
|
|
310
408
|
- Port mappings
|
|
311
409
|
- Environment variables
|
|
@@ -317,9 +415,17 @@ Complete setup with:
|
|
|
317
415
|
Optimized exclusions:
|
|
318
416
|
- `node_modules`
|
|
319
417
|
- `.git`
|
|
418
|
+
- `.env` and every `.env.*` file except `.env.example` (no secrets in images)
|
|
320
419
|
- Test files
|
|
321
420
|
- Documentation
|
|
322
421
|
|
|
422
|
+
### Scripts and Makefile
|
|
423
|
+
|
|
424
|
+
Add `'scripts'` and `'makefile'` to `output.files` to get `docker-build.sh`,
|
|
425
|
+
`docker-up.sh`, `docker-down.sh`, `docker-logs.sh` (written executable) and a
|
|
426
|
+
`Makefile`. They use the Docker Compose v2 CLI (`docker compose`); `make clean`
|
|
427
|
+
runs `docker compose down -v --remove-orphans` for this project only.
|
|
428
|
+
|
|
323
429
|
### .env.example
|
|
324
430
|
|
|
325
431
|
Environment template with:
|
|
@@ -327,10 +433,15 @@ Environment template with:
|
|
|
327
433
|
- Service configurations
|
|
328
434
|
- Required variables
|
|
329
435
|
|
|
436
|
+
It lists the same variables the app container gets: `POSTGRES_URL` (also as
|
|
437
|
+
`DATABASE_URL`), `MYSQL_URL`, `MONGO_URL`, `REDIS_URL`, `<SERVICE>_URL` for
|
|
438
|
+
plugin services, and the `*_HOST`, `*_PORT`, `*_USER`, `*_PASSWORD` and
|
|
439
|
+
database variables of each service.
|
|
440
|
+
|
|
330
441
|
## License
|
|
331
442
|
|
|
332
443
|
MIT
|
|
333
444
|
|
|
334
445
|
---
|
|
335
446
|
|
|
336
|
-
**GitHub**: [ersinkoc/
|
|
447
|
+
**GitHub**: [ersinkoc/DockCraft](https://github.com/ersinkoc/DockCraft)
|