@oxog/dockcraft 1.3.0 → 1.3.2
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 +20 -0
- package/dist/cli/index.js +119 -59
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +96 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +96 -46
- package/dist/index.js.map +1 -1
- package/package.json +7 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.3.2] - 2026-12-03
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- **`port: 'auto'` and `port: { start, end }` could pick a host port the same configuration
|
|
15
|
+
already publishes.** Only the host was probed, and the app (or an earlier service) is not
|
|
16
|
+
running yet, so e.g. a plugin service with default port 3000 and `port: 'auto'` next to the
|
|
17
|
+
app on 3000 got 3000 and generation failed with "already published by 'app'". Automatic
|
|
18
|
+
ports now skip the app port and the ports of earlier services.
|
|
19
|
+
|
|
20
|
+
## [1.3.1] - 2026-12-02
|
|
21
|
+
|
|
22
|
+
### Documentation
|
|
23
|
+
- README examples are run by the test suite (`tests/readme/readme-examples.test.ts`): config
|
|
24
|
+
fragments are type-checked inside `defineConfig()` and generated with, ports are probed against
|
|
25
|
+
an in-memory port table and files are written to a temporary directory; the test fails when a
|
|
26
|
+
README example changes without it.
|
|
27
|
+
|
|
10
28
|
## [1.3.0] - 2026-12-02
|
|
11
29
|
|
|
12
30
|
### Fixed
|
|
@@ -260,6 +278,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
260
278
|
|
|
261
279
|
---
|
|
262
280
|
|
|
281
|
+
[1.3.2]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.3.2
|
|
282
|
+
[1.3.1]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.3.1
|
|
263
283
|
[1.3.0]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.3.0
|
|
264
284
|
[1.2.1]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.2.1
|
|
265
285
|
[1.2.0]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.2.0
|
package/dist/cli/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
// src/version.ts
|
|
9
|
-
var VERSION = "1.3.
|
|
9
|
+
var VERSION = "1.3.2";
|
|
10
10
|
|
|
11
11
|
// src/cli/parser.ts
|
|
12
12
|
function parseArgs(args) {
|
|
@@ -330,7 +330,10 @@ var NoPortAvailableError = class extends DockcraftError {
|
|
|
330
330
|
};
|
|
331
331
|
var FileWriteError = class extends DockcraftError {
|
|
332
332
|
constructor(path, code = "FILE_WRITE_ERROR", cause) {
|
|
333
|
-
super(
|
|
333
|
+
super(
|
|
334
|
+
`Failed to write file: ${path}${cause instanceof Error ? ` (${cause.message})` : ""}`,
|
|
335
|
+
code
|
|
336
|
+
);
|
|
334
337
|
this.name = "FileWriteError";
|
|
335
338
|
if (cause !== void 0) {
|
|
336
339
|
this.cause = cause;
|
|
@@ -737,7 +740,9 @@ async function init(args) {
|
|
|
737
740
|
}
|
|
738
741
|
const unknown = selectedServices.filter((s) => !INIT_SERVICES.includes(s));
|
|
739
742
|
if (unknown.length > 0) {
|
|
740
|
-
throw new Error(
|
|
743
|
+
throw new Error(
|
|
744
|
+
`Unknown service(s): ${unknown.join(", ")}. Available services: ${INIT_SERVICES.join(", ")}`
|
|
745
|
+
);
|
|
741
746
|
}
|
|
742
747
|
const configPath = join2(outputDir, INIT_CONFIG_FILE);
|
|
743
748
|
if (!force && await fileExists(configPath)) {
|
|
@@ -972,11 +977,7 @@ async function findAvailablePortInRange(start, end) {
|
|
|
972
977
|
return void 0;
|
|
973
978
|
}
|
|
974
979
|
async function resolvePort(options = {}) {
|
|
975
|
-
const {
|
|
976
|
-
preferred = 3e3,
|
|
977
|
-
strategy = "auto",
|
|
978
|
-
range
|
|
979
|
-
} = options;
|
|
980
|
+
const { preferred = 3e3, strategy = "auto", range } = options;
|
|
980
981
|
switch (strategy) {
|
|
981
982
|
case "fixed":
|
|
982
983
|
if (await isPortAvailable(preferred)) {
|
|
@@ -1106,12 +1107,13 @@ function mergePreset(config, presetName) {
|
|
|
1106
1107
|
);
|
|
1107
1108
|
return merged;
|
|
1108
1109
|
}
|
|
1109
|
-
async function resolveServicePorts(portConfig, containerPort) {
|
|
1110
|
+
async function resolveServicePorts(portConfig, containerPort, claimed = /* @__PURE__ */ new Set()) {
|
|
1110
1111
|
if (portConfig === "auto") {
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
hostPort
|
|
1114
|
-
}
|
|
1112
|
+
let hostPort = await resolvePort({ preferred: containerPort, strategy: "auto" });
|
|
1113
|
+
while (claimed.has(hostPort)) {
|
|
1114
|
+
hostPort = await resolvePort({ preferred: hostPort + 1, strategy: "auto" });
|
|
1115
|
+
}
|
|
1116
|
+
return { port: containerPort, hostPort };
|
|
1115
1117
|
}
|
|
1116
1118
|
if (typeof portConfig === "number") {
|
|
1117
1119
|
return { port: containerPort, hostPort: portConfig };
|
|
@@ -1119,22 +1121,36 @@ async function resolveServicePorts(portConfig, containerPort) {
|
|
|
1119
1121
|
if (portConfig && typeof portConfig === "object") {
|
|
1120
1122
|
const startPort = portConfig.start ?? containerPort;
|
|
1121
1123
|
const endPort = portConfig.end ?? startPort + 100;
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1124
|
+
let hostPort = await resolvePort({
|
|
1125
|
+
preferred: startPort,
|
|
1126
|
+
strategy: "range",
|
|
1127
|
+
range: [startPort, endPort]
|
|
1128
|
+
});
|
|
1129
|
+
while (hostPort !== void 0 && claimed.has(hostPort)) {
|
|
1130
|
+
hostPort = hostPort < endPort ? await findAvailablePortInRange(hostPort + 1, endPort) : void 0;
|
|
1131
|
+
}
|
|
1132
|
+
if (hostPort === void 0) throw new NoPortAvailableError([startPort, endPort]);
|
|
1133
|
+
return { port: containerPort, hostPort };
|
|
1126
1134
|
}
|
|
1127
1135
|
return { port: containerPort };
|
|
1128
1136
|
}
|
|
1129
|
-
async function resolveServiceConfig(name, config, projectName, definitions) {
|
|
1137
|
+
async function resolveServiceConfig(name, config, projectName, definitions, claimedPorts) {
|
|
1130
1138
|
if ("image" in config && config.image) {
|
|
1131
|
-
return resolveCustomService(
|
|
1139
|
+
return resolveCustomService(
|
|
1140
|
+
name,
|
|
1141
|
+
config,
|
|
1142
|
+
claimedPorts
|
|
1143
|
+
);
|
|
1132
1144
|
}
|
|
1133
1145
|
const definition = definitions?.get(name) ?? getService(name);
|
|
1134
1146
|
if (!definition) {
|
|
1135
1147
|
throw new ServiceNotFoundError(name);
|
|
1136
1148
|
}
|
|
1137
|
-
const { port, hostPort } = await resolveServicePorts(
|
|
1149
|
+
const { port, hostPort } = await resolveServicePorts(
|
|
1150
|
+
config.port,
|
|
1151
|
+
definition.defaultPort,
|
|
1152
|
+
claimedPorts
|
|
1153
|
+
);
|
|
1138
1154
|
const version = config.version ?? definition.defaultVersion;
|
|
1139
1155
|
const image = typeof definition.image === "function" ? definition.image(version) : definition.image;
|
|
1140
1156
|
const env = { ...definition.env, ...config.env };
|
|
@@ -1157,7 +1173,8 @@ async function resolveServiceConfig(name, config, projectName, definitions) {
|
|
|
1157
1173
|
if (mongoConfig.database) env.MONGO_INITDB_DATABASE = mongoConfig.database;
|
|
1158
1174
|
if (mongoConfig.user) env.MONGO_INITDB_ROOT_USERNAME = mongoConfig.user;
|
|
1159
1175
|
if (mongoConfig.password) env.MONGO_INITDB_ROOT_PASSWORD = mongoConfig.password;
|
|
1160
|
-
if (!mongoConfig.database && !config.env?.MONGO_INITDB_DATABASE)
|
|
1176
|
+
if (!mongoConfig.database && !config.env?.MONGO_INITDB_DATABASE)
|
|
1177
|
+
env.MONGO_INITDB_DATABASE = projectName;
|
|
1161
1178
|
} else if (name === "redis") {
|
|
1162
1179
|
const redisConfig = config;
|
|
1163
1180
|
if (redisConfig.password) env.REDIS_PASSWORD = redisConfig.password;
|
|
@@ -1183,14 +1200,14 @@ async function resolveServiceConfig(name, config, projectName, definitions) {
|
|
|
1183
1200
|
}
|
|
1184
1201
|
return resolvedConfig;
|
|
1185
1202
|
}
|
|
1186
|
-
async function resolveCustomService(name, config) {
|
|
1203
|
+
async function resolveCustomService(name, config, claimedPorts) {
|
|
1187
1204
|
let containerPort = 80;
|
|
1188
1205
|
if (typeof config.port === "number") {
|
|
1189
1206
|
containerPort = config.port;
|
|
1190
1207
|
} else if (config.port && typeof config.port === "object" && config.port.start) {
|
|
1191
1208
|
containerPort = config.port.start;
|
|
1192
1209
|
}
|
|
1193
|
-
const { port, hostPort } = await resolveServicePorts(config.port, containerPort);
|
|
1210
|
+
const { port, hostPort } = await resolveServicePorts(config.port, containerPort, claimedPorts);
|
|
1194
1211
|
return {
|
|
1195
1212
|
name,
|
|
1196
1213
|
image: config.image,
|
|
@@ -1223,14 +1240,20 @@ async function resolveConfig(config) {
|
|
|
1223
1240
|
const app = normalizeAppConfig({ ...appConfig, port: appPort });
|
|
1224
1241
|
const definitions = pluginServiceDefinitions(finalConfig.plugins);
|
|
1225
1242
|
const services2 = {};
|
|
1243
|
+
const claimedPorts = /* @__PURE__ */ new Set([app.port]);
|
|
1226
1244
|
for (const [name, serviceConfig] of Object.entries(finalConfig.services ?? {})) {
|
|
1227
1245
|
if (serviceConfig) {
|
|
1228
|
-
|
|
1246
|
+
const service = await resolveServiceConfig(
|
|
1229
1247
|
name,
|
|
1230
1248
|
serviceConfig,
|
|
1231
1249
|
finalConfig.name,
|
|
1232
|
-
definitions
|
|
1250
|
+
definitions,
|
|
1251
|
+
claimedPorts
|
|
1233
1252
|
);
|
|
1253
|
+
services2[name] = service;
|
|
1254
|
+
for (const port of [service.hostPort ?? service.port, ...service.ports ?? []]) {
|
|
1255
|
+
claimedPorts.add(port);
|
|
1256
|
+
}
|
|
1234
1257
|
}
|
|
1235
1258
|
}
|
|
1236
1259
|
return {
|
|
@@ -1245,17 +1268,21 @@ async function resolveConfig(config) {
|
|
|
1245
1268
|
var VALID_OUTPUT_FILES = ["dockerfile", "compose", "dockerignore", "env", "scripts", "makefile"];
|
|
1246
1269
|
function validateProjectName(name) {
|
|
1247
1270
|
if (isProjectName(name)) return [];
|
|
1248
|
-
return [
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1271
|
+
return [
|
|
1272
|
+
{
|
|
1273
|
+
code: "INVALID_NAME",
|
|
1274
|
+
message: `Invalid project name '${String(name)}'. Must start with a letter and contain only letters, numbers, hyphens, and underscores.`,
|
|
1275
|
+
path: "name",
|
|
1276
|
+
value: name
|
|
1277
|
+
}
|
|
1278
|
+
];
|
|
1254
1279
|
}
|
|
1255
1280
|
function validateStringList(value, path) {
|
|
1256
1281
|
if (value === void 0) return [];
|
|
1257
1282
|
if (!Array.isArray(value)) {
|
|
1258
|
-
return [
|
|
1283
|
+
return [
|
|
1284
|
+
{ code: "INVALID_TYPE", message: `'${path}' must be an array of strings.`, path, value }
|
|
1285
|
+
];
|
|
1259
1286
|
}
|
|
1260
1287
|
return value.filter((item) => !isSingleLine(item) || item === "").map((item) => ({
|
|
1261
1288
|
code: "INVALID_VALUE",
|
|
@@ -1319,7 +1346,12 @@ function validateAppConfig(config) {
|
|
|
1319
1346
|
}
|
|
1320
1347
|
if (config.env !== void 0) {
|
|
1321
1348
|
if (!Array.isArray(config.env)) {
|
|
1322
|
-
errors.push({
|
|
1349
|
+
errors.push({
|
|
1350
|
+
code: "INVALID_TYPE",
|
|
1351
|
+
message: `'app.env' must be an array of variable names.`,
|
|
1352
|
+
path: "app.env",
|
|
1353
|
+
value: config.env
|
|
1354
|
+
});
|
|
1323
1355
|
} else {
|
|
1324
1356
|
for (const envVar of config.env) {
|
|
1325
1357
|
if (!isEnvVarName(envVar)) {
|
|
@@ -1344,12 +1376,14 @@ function validateServicePort(name, port) {
|
|
|
1344
1376
|
return [];
|
|
1345
1377
|
}
|
|
1346
1378
|
}
|
|
1347
|
-
return [
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1379
|
+
return [
|
|
1380
|
+
{
|
|
1381
|
+
code: "INVALID_PORT",
|
|
1382
|
+
message: `Invalid port configuration for service '${name}'. Must be a port number (1-65535), 'auto', or a range { start, end } with start <= end.`,
|
|
1383
|
+
path: `services.${name}.port`,
|
|
1384
|
+
value: port
|
|
1385
|
+
}
|
|
1386
|
+
];
|
|
1353
1387
|
}
|
|
1354
1388
|
function validateServiceConfig(name, config) {
|
|
1355
1389
|
const errors = [];
|
|
@@ -1392,7 +1426,12 @@ function validateServiceConfig(name, config) {
|
|
|
1392
1426
|
errors.push(...validateServicePort(name, svc.port));
|
|
1393
1427
|
if (svc.env !== void 0) {
|
|
1394
1428
|
if (typeof svc.env !== "object" || svc.env === null || Array.isArray(svc.env)) {
|
|
1395
|
-
errors.push({
|
|
1429
|
+
errors.push({
|
|
1430
|
+
code: "INVALID_TYPE",
|
|
1431
|
+
message: `'services.${name}.env' must be an object of strings.`,
|
|
1432
|
+
path: `services.${name}.env`,
|
|
1433
|
+
value: svc.env
|
|
1434
|
+
});
|
|
1396
1435
|
} else {
|
|
1397
1436
|
for (const [key, value] of Object.entries(svc.env)) {
|
|
1398
1437
|
if (key === "" || /[=\s]/.test(key) || typeof value !== "string") {
|
|
@@ -1406,7 +1445,14 @@ function validateServiceConfig(name, config) {
|
|
|
1406
1445
|
}
|
|
1407
1446
|
}
|
|
1408
1447
|
}
|
|
1409
|
-
for (const key of [
|
|
1448
|
+
for (const key of [
|
|
1449
|
+
"user",
|
|
1450
|
+
"password",
|
|
1451
|
+
"database",
|
|
1452
|
+
"rootPassword",
|
|
1453
|
+
"command",
|
|
1454
|
+
"healthcheck"
|
|
1455
|
+
]) {
|
|
1410
1456
|
const value = svc[key];
|
|
1411
1457
|
if (value !== void 0 && typeof value !== "string") {
|
|
1412
1458
|
errors.push({
|
|
@@ -1449,7 +1495,9 @@ function validateConfig(config) {
|
|
|
1449
1495
|
if (typeof config !== "object" || config === null) {
|
|
1450
1496
|
return {
|
|
1451
1497
|
valid: false,
|
|
1452
|
-
errors: [
|
|
1498
|
+
errors: [
|
|
1499
|
+
{ code: "INVALID_CONFIG", message: "Configuration must be an object.", value: config }
|
|
1500
|
+
]
|
|
1453
1501
|
};
|
|
1454
1502
|
}
|
|
1455
1503
|
errors.push(...validateProjectName(config.name));
|
|
@@ -1476,7 +1524,10 @@ function validateResolvedConfig(config) {
|
|
|
1476
1524
|
const usedPorts = /* @__PURE__ */ new Map();
|
|
1477
1525
|
usedPorts.set(config.app.port, "app");
|
|
1478
1526
|
for (const [serviceName, serviceConfig] of Object.entries(config.services)) {
|
|
1479
|
-
const published = [
|
|
1527
|
+
const published = [
|
|
1528
|
+
serviceConfig.hostPort ?? serviceConfig.port,
|
|
1529
|
+
...serviceConfig.ports ?? []
|
|
1530
|
+
];
|
|
1480
1531
|
for (const port of published) {
|
|
1481
1532
|
const owner = usedPorts.get(port);
|
|
1482
1533
|
if (owner !== void 0) {
|
|
@@ -2257,7 +2308,8 @@ ${errorMessages}`, errors);
|
|
|
2257
2308
|
}
|
|
2258
2309
|
function isSafeOutputPath(fileName) {
|
|
2259
2310
|
if (typeof fileName !== "string" || fileName === "" || fileName.includes("\0")) return false;
|
|
2260
|
-
if (isAbsolute3(fileName) || /^[a-zA-Z]:/.test(fileName) || fileName.startsWith("\\"))
|
|
2311
|
+
if (isAbsolute3(fileName) || /^[a-zA-Z]:/.test(fileName) || fileName.startsWith("\\"))
|
|
2312
|
+
return false;
|
|
2261
2313
|
const normalized = normalize(fileName.replace(/\\/g, "/"));
|
|
2262
2314
|
return !normalized.split(/[\\/]/).includes("..") && normalized !== ".";
|
|
2263
2315
|
}
|
|
@@ -2273,11 +2325,11 @@ async function dockcraft(config, options = {}) {
|
|
|
2273
2325
|
}
|
|
2274
2326
|
const context = {
|
|
2275
2327
|
config: resolved,
|
|
2276
|
-
ports: new Map(
|
|
2277
|
-
Object.entries(resolved.services).map(([name, svc]) => [name, svc.port])
|
|
2278
|
-
),
|
|
2328
|
+
ports: new Map(Object.entries(resolved.services).map(([name, svc]) => [name, svc.port])),
|
|
2279
2329
|
strings: new Map(
|
|
2280
|
-
Object.entries(resolved.services).filter(
|
|
2330
|
+
Object.entries(resolved.services).filter(
|
|
2331
|
+
(entry) => Boolean(entry[1].connectionString)
|
|
2332
|
+
).map(([name, svc]) => [name, svc.connectionString])
|
|
2281
2333
|
)
|
|
2282
2334
|
};
|
|
2283
2335
|
context.ports.set("app", resolved.app.port);
|
|
@@ -2400,12 +2452,15 @@ async function ports(args) {
|
|
|
2400
2452
|
if (asJson) {
|
|
2401
2453
|
json(Object.fromEntries(results));
|
|
2402
2454
|
} else {
|
|
2403
|
-
table(
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
available
|
|
2407
|
-
|
|
2408
|
-
|
|
2455
|
+
table(
|
|
2456
|
+
["Port", "Status"],
|
|
2457
|
+
[
|
|
2458
|
+
...Array.from(results.entries()).map(([port, available]) => [
|
|
2459
|
+
String(port),
|
|
2460
|
+
available ? "\u2713 Available" : "\u2717 In use"
|
|
2461
|
+
])
|
|
2462
|
+
]
|
|
2463
|
+
);
|
|
2409
2464
|
}
|
|
2410
2465
|
return;
|
|
2411
2466
|
}
|
|
@@ -2414,7 +2469,9 @@ async function ports(args) {
|
|
|
2414
2469
|
const start = Number(match?.[1]);
|
|
2415
2470
|
const end = Number(match?.[2]);
|
|
2416
2471
|
if (!match || !isPort(start) || !isPort(end) || start > end) {
|
|
2417
|
-
throw new Error(
|
|
2472
|
+
throw new Error(
|
|
2473
|
+
"Invalid range format. Use: --range START-END with ports 1-65535 (e.g., 3000-3010)"
|
|
2474
|
+
);
|
|
2418
2475
|
}
|
|
2419
2476
|
const port = await findAvailablePortInRange(start, end);
|
|
2420
2477
|
if (asJson) {
|
|
@@ -2431,9 +2488,10 @@ async function ports(args) {
|
|
|
2431
2488
|
json(defaults);
|
|
2432
2489
|
} else {
|
|
2433
2490
|
subtitle("Default service ports:");
|
|
2434
|
-
table(
|
|
2435
|
-
|
|
2436
|
-
|
|
2491
|
+
table(
|
|
2492
|
+
["Service", "Port"],
|
|
2493
|
+
[...Object.entries(defaults).map(([service, port]) => [service, String(port)])]
|
|
2494
|
+
);
|
|
2437
2495
|
}
|
|
2438
2496
|
}
|
|
2439
2497
|
|
|
@@ -2443,7 +2501,9 @@ function presets2(args) {
|
|
|
2443
2501
|
if (presetName) {
|
|
2444
2502
|
const preset = getPreset(presetName);
|
|
2445
2503
|
if (!preset) {
|
|
2446
|
-
throw new Error(
|
|
2504
|
+
throw new Error(
|
|
2505
|
+
`Preset '${presetName}' not found. Run "dockcraft presets" to list available presets.`
|
|
2506
|
+
);
|
|
2447
2507
|
}
|
|
2448
2508
|
title(`Preset: ${presetName}`);
|
|
2449
2509
|
if (preset.description) {
|