@oxog/dockcraft 1.0.0
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/LICENSE +21 -0
- package/README.md +336 -0
- package/dist/cli/index.cjs +2095 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +6 -0
- package/dist/cli/index.d.ts +6 -0
- package/dist/cli/index.js +2065 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.cjs +1651 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +446 -0
- package/dist/index.d.ts +446 -0
- package/dist/index.js +1604 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ersinkoc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
# @oxog/dockcraft
|
|
2
|
+
|
|
3
|
+
Zero-dependency Docker orchestration toolkit for Node.js projects.
|
|
4
|
+
|
|
5
|
+
A config-driven Docker setup generator that creates `Dockerfile`, `docker-compose.yml`, and environment configurations from a single TypeScript/JavaScript config. Supports built-in service presets, smart port management, connection string generation, and both CLI and programmatic APIs.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Zero Dependencies** - No runtime dependencies, everything implemented from scratch
|
|
10
|
+
- **Config-Driven** - Generate all Docker files from a single config
|
|
11
|
+
- **Built-in Presets** - Pre-configured stacks (Express, Fastify, NestJS)
|
|
12
|
+
- **Smart Port Management** - Auto-resolve port conflicts
|
|
13
|
+
- **Connection Strings** - Auto-generate for all services
|
|
14
|
+
- **CLI + API** - Use interactively or programmatically
|
|
15
|
+
- **Type-Safe** - Full TypeScript support
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @oxog/dockcraft
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
### CLI
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Interactive wizard
|
|
29
|
+
npx @oxog/dockcraft init
|
|
30
|
+
|
|
31
|
+
# Use a preset
|
|
32
|
+
npx @oxog/dockcraft init --preset express-postgres-redis
|
|
33
|
+
|
|
34
|
+
# Generate Docker files
|
|
35
|
+
npx @oxog/dockcraft generate
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Programmatic
|
|
39
|
+
|
|
40
|
+
Create `dockcraft.config.ts`:
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { dockcraft } from '@oxog/dockcraft';
|
|
44
|
+
|
|
45
|
+
await dockcraft({
|
|
46
|
+
name: 'my-api',
|
|
47
|
+
app: {
|
|
48
|
+
port: 3000,
|
|
49
|
+
node: '20-alpine',
|
|
50
|
+
},
|
|
51
|
+
services: {
|
|
52
|
+
postgres: { version: '16' },
|
|
53
|
+
redis: { version: '7-alpine' },
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Generate files:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npx @oxog/dockcraft generate
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
This creates:
|
|
65
|
+
- `Dockerfile` - Multi-stage Node.js build
|
|
66
|
+
- `docker-compose.yml` - All services configured
|
|
67
|
+
- `.dockerignore` - Optimized file exclusion
|
|
68
|
+
- `.env.example` - Environment variables with connection strings
|
|
69
|
+
|
|
70
|
+
## CLI Usage
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# Initialize with wizard
|
|
74
|
+
dockcraft init
|
|
75
|
+
|
|
76
|
+
# Initialize with preset
|
|
77
|
+
dockcraft init --preset express-postgres-redis
|
|
78
|
+
|
|
79
|
+
# Generate from config
|
|
80
|
+
dockcraft generate
|
|
81
|
+
|
|
82
|
+
# Dry run (preview)
|
|
83
|
+
dockcraft generate --dry-run
|
|
84
|
+
|
|
85
|
+
# Check ports
|
|
86
|
+
dockcraft ports --check 3000,5432,6379
|
|
87
|
+
|
|
88
|
+
# List presets
|
|
89
|
+
dockcraft presets
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## API Usage
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import {
|
|
96
|
+
dockcraft,
|
|
97
|
+
defineConfig,
|
|
98
|
+
getPreset,
|
|
99
|
+
listPresets,
|
|
100
|
+
resolvePort,
|
|
101
|
+
checkPort,
|
|
102
|
+
getConnectionString,
|
|
103
|
+
} from '@oxog/dockcraft';
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Main Function
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
await dockcraft({
|
|
110
|
+
name: 'my-app',
|
|
111
|
+
preset: 'express-postgres',
|
|
112
|
+
app: {
|
|
113
|
+
port: 3000,
|
|
114
|
+
healthcheck: '/health',
|
|
115
|
+
},
|
|
116
|
+
services: {
|
|
117
|
+
postgres: { version: '16' },
|
|
118
|
+
},
|
|
119
|
+
output: {
|
|
120
|
+
dir: './docker',
|
|
121
|
+
overwrite: false,
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Port Utilities
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
// Check if port is available
|
|
130
|
+
const available = await checkPort(3000);
|
|
131
|
+
|
|
132
|
+
// Resolve port (auto-find if taken)
|
|
133
|
+
const port = await resolvePort({
|
|
134
|
+
preferred: 3000,
|
|
135
|
+
strategy: 'auto', // 'fixed' | 'auto' | 'range'
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// Find in range
|
|
139
|
+
const port = await resolvePort({
|
|
140
|
+
preferred: 3000,
|
|
141
|
+
range: [3000, 3100],
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Connection Strings
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
const url = getConnectionString('postgres', {
|
|
149
|
+
host: 'localhost',
|
|
150
|
+
port: 5432,
|
|
151
|
+
database: 'myapp',
|
|
152
|
+
user: 'postgres',
|
|
153
|
+
password: 'postgres',
|
|
154
|
+
});
|
|
155
|
+
// => postgres://postgres:postgres@localhost:5432/myapp
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Configuration
|
|
159
|
+
|
|
160
|
+
### App Configuration
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
app: {
|
|
164
|
+
port: 3000, // App port or 'auto'
|
|
165
|
+
node: '20-alpine', // Node.js version
|
|
166
|
+
workdir: '/app', // Working directory
|
|
167
|
+
command: 'npm start', // Start command
|
|
168
|
+
buildCommand: 'npm run build',
|
|
169
|
+
multiStage: true, // Multi-stage build
|
|
170
|
+
healthcheck: '/health', // Health endpoint
|
|
171
|
+
env: ['API_KEY'], // Required env vars
|
|
172
|
+
volumes: ['./data:/app/data'],
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Service Configuration
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
services: {
|
|
180
|
+
postgres: {
|
|
181
|
+
version: '16',
|
|
182
|
+
port: 5432,
|
|
183
|
+
database: 'myapp',
|
|
184
|
+
user: 'postgres',
|
|
185
|
+
password: 'postgres',
|
|
186
|
+
},
|
|
187
|
+
redis: {
|
|
188
|
+
version: '7-alpine',
|
|
189
|
+
password: 'secret',
|
|
190
|
+
},
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Custom Services
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
services: {
|
|
198
|
+
elasticsearch: {
|
|
199
|
+
image: 'elasticsearch:8.11.0',
|
|
200
|
+
port: 9200,
|
|
201
|
+
env: {
|
|
202
|
+
'discovery.type': 'single-node',
|
|
203
|
+
},
|
|
204
|
+
volumes: ['es_data:/usr/share/elasticsearch/data'],
|
|
205
|
+
},
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Presets
|
|
210
|
+
|
|
211
|
+
Available presets:
|
|
212
|
+
|
|
213
|
+
- `express-postgres` - Express + PostgreSQL
|
|
214
|
+
- `express-postgres-redis` - Express + PostgreSQL + Redis
|
|
215
|
+
- `express-mongo` - Express + MongoDB
|
|
216
|
+
- `express-mongo-redis` - Express + MongoDB + Redis
|
|
217
|
+
- `express-mysql` - Express + MySQL
|
|
218
|
+
- `express-mysql-redis` - Express + MySQL + Redis
|
|
219
|
+
- `fastify-postgres` - Fastify + PostgreSQL
|
|
220
|
+
- `fastify-postgres-redis` - Fastify + PostgreSQL + Redis
|
|
221
|
+
- `nest-postgres` - NestJS + PostgreSQL
|
|
222
|
+
- `nest-mongo` - NestJS + MongoDB
|
|
223
|
+
- `node-minimal` - Minimal Node.js setup
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
// Use preset
|
|
227
|
+
await dockcraft({
|
|
228
|
+
name: 'my-api',
|
|
229
|
+
preset: 'express-postgres-redis',
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// Override preset values
|
|
233
|
+
await dockcraft({
|
|
234
|
+
name: 'my-api',
|
|
235
|
+
preset: 'express-postgres',
|
|
236
|
+
app: { port: 8080 },
|
|
237
|
+
services: {
|
|
238
|
+
postgres: { version: '15' },
|
|
239
|
+
},
|
|
240
|
+
});
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Built-in Services
|
|
244
|
+
|
|
245
|
+
### PostgreSQL
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
postgres: {
|
|
249
|
+
version: '16',
|
|
250
|
+
database: 'myapp',
|
|
251
|
+
user: 'postgres',
|
|
252
|
+
password: 'postgres',
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
Connection: `postgres://user:pass@host:port/db`
|
|
257
|
+
|
|
258
|
+
### MySQL
|
|
259
|
+
|
|
260
|
+
```typescript
|
|
261
|
+
mysql: {
|
|
262
|
+
version: '8',
|
|
263
|
+
database: 'myapp',
|
|
264
|
+
user: 'mysql',
|
|
265
|
+
password: 'mysql',
|
|
266
|
+
rootPassword: 'root',
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Connection: `mysql://user:pass@host:port/db`
|
|
271
|
+
|
|
272
|
+
### MongoDB
|
|
273
|
+
|
|
274
|
+
```typescript
|
|
275
|
+
mongo: {
|
|
276
|
+
version: '7',
|
|
277
|
+
database: 'myapp',
|
|
278
|
+
user: 'mongo',
|
|
279
|
+
password: 'mongo',
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
Connection: `mongodb://user:pass@host:port/db`
|
|
284
|
+
|
|
285
|
+
### Redis
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
redis: {
|
|
289
|
+
version: '7-alpine',
|
|
290
|
+
password: 'secret',
|
|
291
|
+
}
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
Connection: `redis://host:port`
|
|
295
|
+
|
|
296
|
+
## Generated Files
|
|
297
|
+
|
|
298
|
+
### Dockerfile
|
|
299
|
+
|
|
300
|
+
Multi-stage build with:
|
|
301
|
+
- Builder stage with dependencies
|
|
302
|
+
- Production stage with minimal image
|
|
303
|
+
- Health check support
|
|
304
|
+
- Configurable Node version
|
|
305
|
+
|
|
306
|
+
### docker-compose.yml
|
|
307
|
+
|
|
308
|
+
Complete setup with:
|
|
309
|
+
- All services with dependencies
|
|
310
|
+
- Port mappings
|
|
311
|
+
- Environment variables
|
|
312
|
+
- Volume definitions
|
|
313
|
+
- Health checks
|
|
314
|
+
|
|
315
|
+
### .dockerignore
|
|
316
|
+
|
|
317
|
+
Optimized exclusions:
|
|
318
|
+
- `node_modules`
|
|
319
|
+
- `.git`
|
|
320
|
+
- Test files
|
|
321
|
+
- Documentation
|
|
322
|
+
|
|
323
|
+
### .env.example
|
|
324
|
+
|
|
325
|
+
Environment template with:
|
|
326
|
+
- Connection strings
|
|
327
|
+
- Service configurations
|
|
328
|
+
- Required variables
|
|
329
|
+
|
|
330
|
+
## License
|
|
331
|
+
|
|
332
|
+
MIT
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
**GitHub**: [ersinkoc/dockcraft](https://github.com/ersinkoc/dockcraft)
|