@oxog/dockcraft 1.1.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 +37 -0
- package/README.md +20 -1
- package/dist/cli/index.js +156 -54
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +93 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +91 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,42 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
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
|
+
|
|
8
44
|
## [1.1.0] - 2026-11-30
|
|
9
45
|
|
|
10
46
|
### Fixed
|
|
@@ -179,5 +215,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
179
215
|
|
|
180
216
|
---
|
|
181
217
|
|
|
218
|
+
[1.1.1]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.1.1
|
|
182
219
|
[1.1.0]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.1.0
|
|
183
220
|
[1.0.0]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.0.0
|
package/README.md
CHANGED
|
@@ -98,6 +98,15 @@ dockcraft presets
|
|
|
98
98
|
```
|
|
99
99
|
|
|
100
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`.
|
|
101
110
|
Commands exit with code 1 on errors (invalid config, unknown command or
|
|
102
111
|
preset, invalid ports). `dockcraft ports --json` prints JSON only.
|
|
103
112
|
|
|
@@ -169,6 +178,11 @@ const portInRange = await resolvePort({
|
|
|
169
178
|
});
|
|
170
179
|
```
|
|
171
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
|
+
|
|
172
186
|
### Connection Strings
|
|
173
187
|
|
|
174
188
|
```typescript
|
|
@@ -389,7 +403,7 @@ Multi-stage build with:
|
|
|
389
403
|
|
|
390
404
|
### docker-compose.yml
|
|
391
405
|
|
|
392
|
-
|
|
406
|
+
Compose Specification file (no obsolete top-level `version`) with:
|
|
393
407
|
- All services with dependencies
|
|
394
408
|
- Port mappings
|
|
395
409
|
- Environment variables
|
|
@@ -419,6 +433,11 @@ Environment template with:
|
|
|
419
433
|
- Service configurations
|
|
420
434
|
- Required variables
|
|
421
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
|
+
|
|
422
441
|
## License
|
|
423
442
|
|
|
424
443
|
MIT
|
package/dist/cli/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
// src/version.ts
|
|
9
|
-
var VERSION = "1.1.
|
|
9
|
+
var VERSION = "1.1.1";
|
|
10
10
|
|
|
11
11
|
// src/cli/parser.ts
|
|
12
12
|
function parseArgs(args) {
|
|
@@ -263,6 +263,63 @@ async function multiselect(question, options) {
|
|
|
263
263
|
// src/utils/fs.ts
|
|
264
264
|
import { promises as fs } from "fs";
|
|
265
265
|
import { join, dirname, basename, extname, relative } from "path";
|
|
266
|
+
|
|
267
|
+
// src/types.ts
|
|
268
|
+
var DockcraftError = class extends Error {
|
|
269
|
+
constructor(message, code) {
|
|
270
|
+
super(message);
|
|
271
|
+
this.code = code;
|
|
272
|
+
this.name = "DockcraftError";
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
var ConfigError = class extends DockcraftError {
|
|
276
|
+
constructor(message, code = "CONFIG_ERROR") {
|
|
277
|
+
super(message, code);
|
|
278
|
+
this.name = "ConfigError";
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
var ValidationError = class extends DockcraftError {
|
|
282
|
+
constructor(message, errors, code = "VALIDATION_ERROR") {
|
|
283
|
+
super(message, code);
|
|
284
|
+
this.errors = errors;
|
|
285
|
+
this.name = "ValidationError";
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
var PortConflictError = class extends DockcraftError {
|
|
289
|
+
constructor(port, code = "PORT_CONFLICT") {
|
|
290
|
+
super(`Port ${port} is already in use`, code);
|
|
291
|
+
this.name = "PortConflictError";
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
var NoPortAvailableError = class extends DockcraftError {
|
|
295
|
+
constructor(range, code = "NO_PORT_AVAILABLE") {
|
|
296
|
+
super(`No available port in range ${range[0]}-${range[1]}`, code);
|
|
297
|
+
this.name = "NoPortAvailableError";
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
var FileWriteError = class extends DockcraftError {
|
|
301
|
+
constructor(path, code = "FILE_WRITE_ERROR", cause) {
|
|
302
|
+
super(`Failed to write file: ${path}${cause instanceof Error ? ` (${cause.message})` : ""}`, code);
|
|
303
|
+
this.name = "FileWriteError";
|
|
304
|
+
if (cause !== void 0) {
|
|
305
|
+
this.cause = cause;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
var PresetNotFoundError = class extends DockcraftError {
|
|
310
|
+
constructor(name, code = "PRESET_NOT_FOUND") {
|
|
311
|
+
super(`Preset '${name}' not found`, code);
|
|
312
|
+
this.name = "PresetNotFoundError";
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
var ServiceNotFoundError = class extends DockcraftError {
|
|
316
|
+
constructor(name, code = "SERVICE_NOT_FOUND") {
|
|
317
|
+
super(`Service '${name}' not found`, code);
|
|
318
|
+
this.name = "ServiceNotFoundError";
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
// src/utils/fs.ts
|
|
266
323
|
async function ensureDir(path) {
|
|
267
324
|
try {
|
|
268
325
|
await fs.mkdir(path, { recursive: true });
|
|
@@ -274,6 +331,13 @@ async function ensureDir(path) {
|
|
|
274
331
|
}
|
|
275
332
|
}
|
|
276
333
|
async function writeFile(filePath, content, mode) {
|
|
334
|
+
try {
|
|
335
|
+
await writeFileAtomic(filePath, content, mode);
|
|
336
|
+
} catch (error2) {
|
|
337
|
+
throw new FileWriteError(filePath, "FILE_WRITE_ERROR", error2);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
async function writeFileAtomic(filePath, content, mode) {
|
|
277
341
|
const dir = dirname(filePath);
|
|
278
342
|
await ensureDir(dir);
|
|
279
343
|
const suffix = `${process.pid}.${Date.now().toString(36)}.${Math.random().toString(36).slice(2)}`;
|
|
@@ -597,11 +661,15 @@ function defaultProjectName(dir) {
|
|
|
597
661
|
const name = basename2(dir).replace(/[^a-zA-Z0-9_-]/g, "-").replace(/^[^a-zA-Z]+/, "");
|
|
598
662
|
return isProjectName(name) ? name : "my-app";
|
|
599
663
|
}
|
|
664
|
+
function noTerminalMessage(question) {
|
|
665
|
+
return `Cannot ask "${question.replace(/:$/, "")}": stdin is not a terminal. Run "dockcraft init" in a terminal, or pass -y/--yes to use the defaults (and --name, --port, --preset, --services, --output to set values).`;
|
|
666
|
+
}
|
|
600
667
|
async function init(args) {
|
|
601
668
|
title("Dockcraft Init");
|
|
602
669
|
const skipPrompts = getBooleanFlag(args, "yes");
|
|
603
670
|
const force = getBooleanFlag(args, "force");
|
|
604
|
-
const
|
|
671
|
+
const interactive = (question, ask2) => process.stdin.isTTY ? ask2() : Promise.reject(new Error(noTerminalMessage(question)));
|
|
672
|
+
const ask = (question, defaultValue) => skipPrompts ? Promise.resolve(defaultValue) : interactive(question, () => prompt(question, defaultValue));
|
|
605
673
|
const name = getOption(args, "name") || await ask("Project name", defaultProjectName(process.cwd()));
|
|
606
674
|
if (!isProjectName(name)) {
|
|
607
675
|
throw new Error(
|
|
@@ -622,7 +690,7 @@ async function init(args) {
|
|
|
622
690
|
info(`Creating config for "${name}"`);
|
|
623
691
|
let selectedPreset = preset;
|
|
624
692
|
if (!selectedPreset && !skipPrompts) {
|
|
625
|
-
const usePreset = await confirm("Use a preset?");
|
|
693
|
+
const usePreset = await interactive("Use a preset?", () => confirm("Use a preset?"));
|
|
626
694
|
if (usePreset) {
|
|
627
695
|
selectedPreset = await select("Select preset:", presets3);
|
|
628
696
|
}
|
|
@@ -631,7 +699,10 @@ async function init(args) {
|
|
|
631
699
|
if (getOption(args, "services")) {
|
|
632
700
|
selectedServices = parseList(args, "services");
|
|
633
701
|
} else if (!skipPrompts && !selectedPreset) {
|
|
634
|
-
selectedServices = await
|
|
702
|
+
selectedServices = await interactive(
|
|
703
|
+
"Select services:",
|
|
704
|
+
() => multiselect("Select services:", [...INIT_SERVICES])
|
|
705
|
+
);
|
|
635
706
|
}
|
|
636
707
|
const unknown = selectedServices.filter((s) => !INIT_SERVICES.includes(s));
|
|
637
708
|
if (unknown.length > 0) {
|
|
@@ -678,40 +749,6 @@ function generateConfig(name, preset, services2, port) {
|
|
|
678
749
|
return content;
|
|
679
750
|
}
|
|
680
751
|
|
|
681
|
-
// src/types.ts
|
|
682
|
-
var DockcraftError = class extends Error {
|
|
683
|
-
constructor(message, code) {
|
|
684
|
-
super(message);
|
|
685
|
-
this.code = code;
|
|
686
|
-
this.name = "DockcraftError";
|
|
687
|
-
}
|
|
688
|
-
};
|
|
689
|
-
var ConfigError = class extends DockcraftError {
|
|
690
|
-
constructor(message, code = "CONFIG_ERROR") {
|
|
691
|
-
super(message, code);
|
|
692
|
-
this.name = "ConfigError";
|
|
693
|
-
}
|
|
694
|
-
};
|
|
695
|
-
var ValidationError = class extends DockcraftError {
|
|
696
|
-
constructor(message, errors, code = "VALIDATION_ERROR") {
|
|
697
|
-
super(message, code);
|
|
698
|
-
this.errors = errors;
|
|
699
|
-
this.name = "ValidationError";
|
|
700
|
-
}
|
|
701
|
-
};
|
|
702
|
-
var PresetNotFoundError = class extends DockcraftError {
|
|
703
|
-
constructor(name, code = "PRESET_NOT_FOUND") {
|
|
704
|
-
super(`Preset '${name}' not found`, code);
|
|
705
|
-
this.name = "PresetNotFoundError";
|
|
706
|
-
}
|
|
707
|
-
};
|
|
708
|
-
var ServiceNotFoundError = class extends DockcraftError {
|
|
709
|
-
constructor(name, code = "SERVICE_NOT_FOUND") {
|
|
710
|
-
super(`Service '${name}' not found`, code);
|
|
711
|
-
this.name = "ServiceNotFoundError";
|
|
712
|
-
}
|
|
713
|
-
};
|
|
714
|
-
|
|
715
752
|
// src/services/image.ts
|
|
716
753
|
function variantImage(repository, version, variant) {
|
|
717
754
|
if (version === "latest") {
|
|
@@ -914,7 +951,7 @@ async function resolvePort(options = {}) {
|
|
|
914
951
|
if (await isPortAvailable(preferred)) {
|
|
915
952
|
return preferred;
|
|
916
953
|
}
|
|
917
|
-
throw new
|
|
954
|
+
throw new PortConflictError(preferred);
|
|
918
955
|
case "range":
|
|
919
956
|
if (range) {
|
|
920
957
|
const [start, end = start + 100] = range;
|
|
@@ -922,7 +959,7 @@ async function resolvePort(options = {}) {
|
|
|
922
959
|
if (port !== void 0) {
|
|
923
960
|
return port;
|
|
924
961
|
}
|
|
925
|
-
throw new
|
|
962
|
+
throw new NoPortAvailableError([start, end]);
|
|
926
963
|
}
|
|
927
964
|
// Fall through to auto if no range specified
|
|
928
965
|
case "auto":
|
|
@@ -931,7 +968,7 @@ async function resolvePort(options = {}) {
|
|
|
931
968
|
if (port !== void 0) {
|
|
932
969
|
return port;
|
|
933
970
|
}
|
|
934
|
-
throw new
|
|
971
|
+
throw new NoPortAvailableError([preferred, 65535]);
|
|
935
972
|
}
|
|
936
973
|
}
|
|
937
974
|
}
|
|
@@ -1625,14 +1662,41 @@ function yamlScalar(str) {
|
|
|
1625
1662
|
return JSON.stringify(str);
|
|
1626
1663
|
}
|
|
1627
1664
|
|
|
1665
|
+
// src/generators/paths.ts
|
|
1666
|
+
import { isAbsolute as isAbsolute2, join as join3, relative as relative2 } from "path";
|
|
1667
|
+
function currentDir() {
|
|
1668
|
+
return typeof process !== "undefined" && typeof process.cwd === "function" ? process.cwd() : "/";
|
|
1669
|
+
}
|
|
1670
|
+
function outputSubdir(dir) {
|
|
1671
|
+
if (!dir) {
|
|
1672
|
+
return void 0;
|
|
1673
|
+
}
|
|
1674
|
+
const root = currentDir();
|
|
1675
|
+
const subdir = relative2(root, isAbsolute2(dir) ? dir : join3(root, dir)).replace(/\\/g, "/");
|
|
1676
|
+
if (subdir === "" || subdir === ".." || subdir.startsWith("../") || isAbsolute2(subdir)) {
|
|
1677
|
+
return void 0;
|
|
1678
|
+
}
|
|
1679
|
+
return subdir;
|
|
1680
|
+
}
|
|
1681
|
+
function pathToRoot(subdir) {
|
|
1682
|
+
return subdir.split("/").map(() => "..").join("/");
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1628
1685
|
// src/generators/compose.ts
|
|
1629
1686
|
function composeLiteral(value) {
|
|
1630
1687
|
return value.replace(/\$/g, "$$$$");
|
|
1631
1688
|
}
|
|
1689
|
+
function composeBuild(outputDir) {
|
|
1690
|
+
const subdir = outputSubdir(outputDir);
|
|
1691
|
+
if (subdir === void 0) {
|
|
1692
|
+
return ".";
|
|
1693
|
+
}
|
|
1694
|
+
return { context: pathToRoot(subdir), dockerfile: `${subdir}/Dockerfile` };
|
|
1695
|
+
}
|
|
1632
1696
|
function generateCompose(config, _context) {
|
|
1633
1697
|
const { app, services: services2 } = config;
|
|
1634
1698
|
const appService = {
|
|
1635
|
-
build:
|
|
1699
|
+
build: composeBuild(config.output.dir),
|
|
1636
1700
|
ports: [`${app.port}:${app.port}`],
|
|
1637
1701
|
environment: generateAppEnvironment(config),
|
|
1638
1702
|
depends_on: Object.keys(services2),
|
|
@@ -1651,13 +1715,20 @@ function generateCompose(config, _context) {
|
|
|
1651
1715
|
composeServices[serviceName] = generateServiceConfig(serviceConfig);
|
|
1652
1716
|
}
|
|
1653
1717
|
const compose = {
|
|
1654
|
-
version: "3.9",
|
|
1655
1718
|
services: composeServices,
|
|
1656
1719
|
volumes: generateVolumeDefinitions(config)
|
|
1657
1720
|
};
|
|
1658
1721
|
return `${toYaml(compose)}
|
|
1659
1722
|
`;
|
|
1660
1723
|
}
|
|
1724
|
+
function connectionStringVar(serviceName) {
|
|
1725
|
+
return `${serviceName.toUpperCase().replace(/[^A-Z0-9_]/g, "_")}_URL`;
|
|
1726
|
+
}
|
|
1727
|
+
function hasDatabaseUrlAlias(config) {
|
|
1728
|
+
return config.services.postgres !== void 0 && !Object.entries(config.services).some(
|
|
1729
|
+
([name, service]) => Boolean(service.connectionString) && connectionStringVar(name) === "DATABASE_URL"
|
|
1730
|
+
);
|
|
1731
|
+
}
|
|
1661
1732
|
function generateAppEnvironment(config) {
|
|
1662
1733
|
const env = ["NODE_ENV=production", `PORT=${config.app.port}`];
|
|
1663
1734
|
const add = (key, value) => {
|
|
@@ -1665,12 +1736,14 @@ function generateAppEnvironment(config) {
|
|
|
1665
1736
|
};
|
|
1666
1737
|
for (const [serviceName, serviceConfig] of Object.entries(config.services)) {
|
|
1667
1738
|
if (serviceConfig.connectionString) {
|
|
1668
|
-
|
|
1669
|
-
add(key, serviceConfig.connectionString);
|
|
1739
|
+
add(connectionStringVar(serviceName), serviceConfig.connectionString);
|
|
1670
1740
|
}
|
|
1671
1741
|
}
|
|
1672
1742
|
if (config.services.postgres) {
|
|
1673
1743
|
const pg = config.services.postgres;
|
|
1744
|
+
if (pg.connectionString && hasDatabaseUrlAlias(config)) {
|
|
1745
|
+
add("DATABASE_URL", pg.connectionString);
|
|
1746
|
+
}
|
|
1674
1747
|
add("POSTGRES_HOST", pg.name);
|
|
1675
1748
|
add("POSTGRES_PORT", pg.port);
|
|
1676
1749
|
add("POSTGRES_USER", pg.env.POSTGRES_USER || "postgres");
|
|
@@ -1754,7 +1827,19 @@ function generateVolumeDefinitions(config) {
|
|
|
1754
1827
|
}
|
|
1755
1828
|
|
|
1756
1829
|
// src/generators/dockerignore.ts
|
|
1757
|
-
|
|
1830
|
+
var DOCKERFILE_IGNORE_FILE = "Dockerfile.dockerignore";
|
|
1831
|
+
function dockerignoreFileName(outputDir) {
|
|
1832
|
+
return outputSubdir(outputDir) === void 0 ? ".dockerignore" : DOCKERFILE_IGNORE_FILE;
|
|
1833
|
+
}
|
|
1834
|
+
function outputDirPatterns(outputDir) {
|
|
1835
|
+
const subdir = outputSubdir(outputDir);
|
|
1836
|
+
if (subdir === void 0) {
|
|
1837
|
+
return "";
|
|
1838
|
+
}
|
|
1839
|
+
return ["Dockerfile", "docker-compose.yml", DOCKERFILE_IGNORE_FILE, ".env", ".env.*"].map((file) => `${subdir}/${file}
|
|
1840
|
+
`).join("");
|
|
1841
|
+
}
|
|
1842
|
+
function generateDockerignore(config) {
|
|
1758
1843
|
return `# Dependencies
|
|
1759
1844
|
node_modules/
|
|
1760
1845
|
npm-debug.log*
|
|
@@ -1816,7 +1901,7 @@ temp/
|
|
|
1816
1901
|
Dockerfile
|
|
1817
1902
|
docker-compose.yml
|
|
1818
1903
|
.dockerignore
|
|
1819
|
-
|
|
1904
|
+
${outputDirPatterns(config.output.dir)}
|
|
1820
1905
|
# Package manager lockfiles (optional - uncomment if you want to exclude)
|
|
1821
1906
|
# package-lock.json
|
|
1822
1907
|
# yarn.lock
|
|
@@ -1825,6 +1910,7 @@ docker-compose.yml
|
|
|
1825
1910
|
}
|
|
1826
1911
|
|
|
1827
1912
|
// src/generators/env.ts
|
|
1913
|
+
var BUILT_IN_SERVICES = /* @__PURE__ */ new Set(["postgres", "mysql", "mongo", "redis"]);
|
|
1828
1914
|
function envValue(value) {
|
|
1829
1915
|
if (/^[\w@%+=:,./?&-]*$/.test(value)) {
|
|
1830
1916
|
return value;
|
|
@@ -1854,7 +1940,11 @@ PORT=${config.app.port}
|
|
|
1854
1940
|
content += `
|
|
1855
1941
|
# PostgreSQL
|
|
1856
1942
|
`;
|
|
1857
|
-
|
|
1943
|
+
if (hasDatabaseUrlAlias(config)) {
|
|
1944
|
+
content += `DATABASE_URL=${envValue(String(pg.connectionString || ""))}
|
|
1945
|
+
`;
|
|
1946
|
+
}
|
|
1947
|
+
content += `POSTGRES_URL=${envValue(String(pg.connectionString || ""))}
|
|
1858
1948
|
`;
|
|
1859
1949
|
content += `POSTGRES_HOST=${envValue(String(pg.name))}
|
|
1860
1950
|
`;
|
|
@@ -1916,6 +2006,15 @@ PORT=${config.app.port}
|
|
|
1916
2006
|
`;
|
|
1917
2007
|
if (redis.env.REDIS_PASSWORD) {
|
|
1918
2008
|
content += `REDIS_PASSWORD=${envValue(String(redis.env.REDIS_PASSWORD))}
|
|
2009
|
+
`;
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
for (const [serviceName, service] of Object.entries(config.services)) {
|
|
2013
|
+
if (!BUILT_IN_SERVICES.has(serviceName) && service.connectionString) {
|
|
2014
|
+
content += `
|
|
2015
|
+
# ${serviceName}
|
|
2016
|
+
`;
|
|
2017
|
+
content += `${connectionStringVar(serviceName)}=${envValue(service.connectionString)}
|
|
1919
2018
|
`;
|
|
1920
2019
|
}
|
|
1921
2020
|
}
|
|
@@ -2069,7 +2168,8 @@ function generateAll(config, context) {
|
|
|
2069
2168
|
} else {
|
|
2070
2169
|
const generator = GENERATORS[fileType];
|
|
2071
2170
|
if (generator) {
|
|
2072
|
-
|
|
2171
|
+
const file = fileType === "dockerignore" ? dockerignoreFileName(config.output.dir) : generator.file;
|
|
2172
|
+
result[file] = generator.generate(config, context);
|
|
2073
2173
|
}
|
|
2074
2174
|
}
|
|
2075
2175
|
}
|
|
@@ -2077,7 +2177,7 @@ function generateAll(config, context) {
|
|
|
2077
2177
|
}
|
|
2078
2178
|
|
|
2079
2179
|
// src/core/dockcraft.ts
|
|
2080
|
-
import { isAbsolute as
|
|
2180
|
+
import { isAbsolute as isAbsolute3, join as join4, normalize } from "path";
|
|
2081
2181
|
function validationError(prefix, errors) {
|
|
2082
2182
|
const errorMessages = errors.map((e) => ` - ${e.message}`).join("\n");
|
|
2083
2183
|
return new ValidationError(`${prefix}:
|
|
@@ -2085,7 +2185,7 @@ ${errorMessages}`, errors);
|
|
|
2085
2185
|
}
|
|
2086
2186
|
function isSafeOutputPath(fileName) {
|
|
2087
2187
|
if (typeof fileName !== "string" || fileName === "" || fileName.includes("\0")) return false;
|
|
2088
|
-
if (
|
|
2188
|
+
if (isAbsolute3(fileName) || /^[a-zA-Z]:/.test(fileName) || fileName.startsWith("\\")) return false;
|
|
2089
2189
|
const normalized = normalize(fileName.replace(/\\/g, "/"));
|
|
2090
2190
|
return !normalized.split(/[\\/]/).includes("..") && normalized !== ".";
|
|
2091
2191
|
}
|
|
@@ -2131,7 +2231,7 @@ async function dockcraft(config, options = {}) {
|
|
|
2131
2231
|
const outputDir = resolved.output.dir ?? "./";
|
|
2132
2232
|
if (!options.dryRun) {
|
|
2133
2233
|
for (const [fileName, content] of Object.entries(generated)) {
|
|
2134
|
-
const filePath =
|
|
2234
|
+
const filePath = join4(outputDir, fileName);
|
|
2135
2235
|
const exists = await fileExists(filePath);
|
|
2136
2236
|
if (exists && !resolved.output.overwrite) {
|
|
2137
2237
|
continue;
|
|
@@ -2186,7 +2286,9 @@ async function generate(args) {
|
|
|
2186
2286
|
info(`Skipped ${skipped} existing file(s); use --force to overwrite them.`);
|
|
2187
2287
|
}
|
|
2188
2288
|
console.log("");
|
|
2189
|
-
|
|
2289
|
+
const subdir = outputSubdir(result.config.output.dir);
|
|
2290
|
+
const composeFile = subdir === void 0 ? "" : ` -f ${subdir}/docker-compose.yml`;
|
|
2291
|
+
success(`Done! Run "docker compose${composeFile} up -d" to start services`);
|
|
2190
2292
|
}
|
|
2191
2293
|
|
|
2192
2294
|
// src/ports/defaults.ts
|
|
@@ -2347,7 +2449,7 @@ OPTIONS:
|
|
|
2347
2449
|
--services <list> Comma-separated service list
|
|
2348
2450
|
--output <dir> Directory to write dockcraft.config.mts to
|
|
2349
2451
|
--force Overwrite an existing config file
|
|
2350
|
-
-y, --yes Skip prompts, use defaults
|
|
2452
|
+
-y, --yes Skip prompts, use defaults (required without a terminal)
|
|
2351
2453
|
`);
|
|
2352
2454
|
break;
|
|
2353
2455
|
case "generate":
|