@oxog/dockcraft 1.3.0 → 1.3.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 +9 -0
- package/dist/cli/index.js +87 -44
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +64 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +64 -31
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
package/dist/index.js
CHANGED
|
@@ -39,7 +39,10 @@ var NoPortAvailableError = class extends DockcraftError {
|
|
|
39
39
|
};
|
|
40
40
|
var FileWriteError = class extends DockcraftError {
|
|
41
41
|
constructor(path, code = "FILE_WRITE_ERROR", cause) {
|
|
42
|
-
super(
|
|
42
|
+
super(
|
|
43
|
+
`Failed to write file: ${path}${cause instanceof Error ? ` (${cause.message})` : ""}`,
|
|
44
|
+
code
|
|
45
|
+
);
|
|
43
46
|
this.name = "FileWriteError";
|
|
44
47
|
if (cause !== void 0) {
|
|
45
48
|
this.cause = cause;
|
|
@@ -492,11 +495,7 @@ async function findAvailablePortInRange(start, end) {
|
|
|
492
495
|
return void 0;
|
|
493
496
|
}
|
|
494
497
|
async function resolvePort(options = {}) {
|
|
495
|
-
const {
|
|
496
|
-
preferred = 3e3,
|
|
497
|
-
strategy = "auto",
|
|
498
|
-
range
|
|
499
|
-
} = options;
|
|
498
|
+
const { preferred = 3e3, strategy = "auto", range } = options;
|
|
500
499
|
switch (strategy) {
|
|
501
500
|
case "fixed":
|
|
502
501
|
if (await isPortAvailable(preferred)) {
|
|
@@ -600,7 +599,11 @@ async function resolveServicePorts(portConfig, containerPort) {
|
|
|
600
599
|
const endPort = portConfig.end ?? startPort + 100;
|
|
601
600
|
return {
|
|
602
601
|
port: containerPort,
|
|
603
|
-
hostPort: await resolvePort({
|
|
602
|
+
hostPort: await resolvePort({
|
|
603
|
+
preferred: startPort,
|
|
604
|
+
strategy: "range",
|
|
605
|
+
range: [startPort, endPort]
|
|
606
|
+
})
|
|
604
607
|
};
|
|
605
608
|
}
|
|
606
609
|
return { port: containerPort };
|
|
@@ -636,7 +639,8 @@ async function resolveServiceConfig(name, config, projectName, definitions) {
|
|
|
636
639
|
if (mongoConfig.database) env.MONGO_INITDB_DATABASE = mongoConfig.database;
|
|
637
640
|
if (mongoConfig.user) env.MONGO_INITDB_ROOT_USERNAME = mongoConfig.user;
|
|
638
641
|
if (mongoConfig.password) env.MONGO_INITDB_ROOT_PASSWORD = mongoConfig.password;
|
|
639
|
-
if (!mongoConfig.database && !config.env?.MONGO_INITDB_DATABASE)
|
|
642
|
+
if (!mongoConfig.database && !config.env?.MONGO_INITDB_DATABASE)
|
|
643
|
+
env.MONGO_INITDB_DATABASE = projectName;
|
|
640
644
|
} else if (name === "redis") {
|
|
641
645
|
const redisConfig = config;
|
|
642
646
|
if (redisConfig.password) env.REDIS_PASSWORD = redisConfig.password;
|
|
@@ -777,17 +781,21 @@ function namedVolume(spec) {
|
|
|
777
781
|
var VALID_OUTPUT_FILES = ["dockerfile", "compose", "dockerignore", "env", "scripts", "makefile"];
|
|
778
782
|
function validateProjectName(name) {
|
|
779
783
|
if (isProjectName(name)) return [];
|
|
780
|
-
return [
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
784
|
+
return [
|
|
785
|
+
{
|
|
786
|
+
code: "INVALID_NAME",
|
|
787
|
+
message: `Invalid project name '${String(name)}'. Must start with a letter and contain only letters, numbers, hyphens, and underscores.`,
|
|
788
|
+
path: "name",
|
|
789
|
+
value: name
|
|
790
|
+
}
|
|
791
|
+
];
|
|
786
792
|
}
|
|
787
793
|
function validateStringList(value, path) {
|
|
788
794
|
if (value === void 0) return [];
|
|
789
795
|
if (!Array.isArray(value)) {
|
|
790
|
-
return [
|
|
796
|
+
return [
|
|
797
|
+
{ code: "INVALID_TYPE", message: `'${path}' must be an array of strings.`, path, value }
|
|
798
|
+
];
|
|
791
799
|
}
|
|
792
800
|
return value.filter((item) => !isSingleLine(item) || item === "").map((item) => ({
|
|
793
801
|
code: "INVALID_VALUE",
|
|
@@ -851,7 +859,12 @@ function validateAppConfig(config) {
|
|
|
851
859
|
}
|
|
852
860
|
if (config.env !== void 0) {
|
|
853
861
|
if (!Array.isArray(config.env)) {
|
|
854
|
-
errors.push({
|
|
862
|
+
errors.push({
|
|
863
|
+
code: "INVALID_TYPE",
|
|
864
|
+
message: `'app.env' must be an array of variable names.`,
|
|
865
|
+
path: "app.env",
|
|
866
|
+
value: config.env
|
|
867
|
+
});
|
|
855
868
|
} else {
|
|
856
869
|
for (const envVar of config.env) {
|
|
857
870
|
if (!isEnvVarName(envVar)) {
|
|
@@ -876,12 +889,14 @@ function validateServicePort(name, port) {
|
|
|
876
889
|
return [];
|
|
877
890
|
}
|
|
878
891
|
}
|
|
879
|
-
return [
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
892
|
+
return [
|
|
893
|
+
{
|
|
894
|
+
code: "INVALID_PORT",
|
|
895
|
+
message: `Invalid port configuration for service '${name}'. Must be a port number (1-65535), 'auto', or a range { start, end } with start <= end.`,
|
|
896
|
+
path: `services.${name}.port`,
|
|
897
|
+
value: port
|
|
898
|
+
}
|
|
899
|
+
];
|
|
885
900
|
}
|
|
886
901
|
function validateServiceConfig(name, config) {
|
|
887
902
|
const errors = [];
|
|
@@ -924,7 +939,12 @@ function validateServiceConfig(name, config) {
|
|
|
924
939
|
errors.push(...validateServicePort(name, svc.port));
|
|
925
940
|
if (svc.env !== void 0) {
|
|
926
941
|
if (typeof svc.env !== "object" || svc.env === null || Array.isArray(svc.env)) {
|
|
927
|
-
errors.push({
|
|
942
|
+
errors.push({
|
|
943
|
+
code: "INVALID_TYPE",
|
|
944
|
+
message: `'services.${name}.env' must be an object of strings.`,
|
|
945
|
+
path: `services.${name}.env`,
|
|
946
|
+
value: svc.env
|
|
947
|
+
});
|
|
928
948
|
} else {
|
|
929
949
|
for (const [key, value] of Object.entries(svc.env)) {
|
|
930
950
|
if (key === "" || /[=\s]/.test(key) || typeof value !== "string") {
|
|
@@ -938,7 +958,14 @@ function validateServiceConfig(name, config) {
|
|
|
938
958
|
}
|
|
939
959
|
}
|
|
940
960
|
}
|
|
941
|
-
for (const key of [
|
|
961
|
+
for (const key of [
|
|
962
|
+
"user",
|
|
963
|
+
"password",
|
|
964
|
+
"database",
|
|
965
|
+
"rootPassword",
|
|
966
|
+
"command",
|
|
967
|
+
"healthcheck"
|
|
968
|
+
]) {
|
|
942
969
|
const value = svc[key];
|
|
943
970
|
if (value !== void 0 && typeof value !== "string") {
|
|
944
971
|
errors.push({
|
|
@@ -981,7 +1008,9 @@ function validateConfig(config) {
|
|
|
981
1008
|
if (typeof config !== "object" || config === null) {
|
|
982
1009
|
return {
|
|
983
1010
|
valid: false,
|
|
984
|
-
errors: [
|
|
1011
|
+
errors: [
|
|
1012
|
+
{ code: "INVALID_CONFIG", message: "Configuration must be an object.", value: config }
|
|
1013
|
+
]
|
|
985
1014
|
};
|
|
986
1015
|
}
|
|
987
1016
|
errors.push(...validateProjectName(config.name));
|
|
@@ -1008,7 +1037,10 @@ function validateResolvedConfig(config) {
|
|
|
1008
1037
|
const usedPorts = /* @__PURE__ */ new Map();
|
|
1009
1038
|
usedPorts.set(config.app.port, "app");
|
|
1010
1039
|
for (const [serviceName, serviceConfig] of Object.entries(config.services)) {
|
|
1011
|
-
const published = [
|
|
1040
|
+
const published = [
|
|
1041
|
+
serviceConfig.hostPort ?? serviceConfig.port,
|
|
1042
|
+
...serviceConfig.ports ?? []
|
|
1043
|
+
];
|
|
1012
1044
|
for (const port of published) {
|
|
1013
1045
|
const owner = usedPorts.get(port);
|
|
1014
1046
|
if (owner !== void 0) {
|
|
@@ -1835,7 +1867,8 @@ ${errorMessages}`, errors);
|
|
|
1835
1867
|
}
|
|
1836
1868
|
function isSafeOutputPath(fileName) {
|
|
1837
1869
|
if (typeof fileName !== "string" || fileName === "" || fileName.includes("\0")) return false;
|
|
1838
|
-
if (isAbsolute2(fileName) || /^[a-zA-Z]:/.test(fileName) || fileName.startsWith("\\"))
|
|
1870
|
+
if (isAbsolute2(fileName) || /^[a-zA-Z]:/.test(fileName) || fileName.startsWith("\\"))
|
|
1871
|
+
return false;
|
|
1839
1872
|
const normalized = normalize(fileName.replace(/\\/g, "/"));
|
|
1840
1873
|
return !normalized.split(/[\\/]/).includes("..") && normalized !== ".";
|
|
1841
1874
|
}
|
|
@@ -1851,11 +1884,11 @@ async function dockcraft(config, options = {}) {
|
|
|
1851
1884
|
}
|
|
1852
1885
|
const context = {
|
|
1853
1886
|
config: resolved,
|
|
1854
|
-
ports: new Map(
|
|
1855
|
-
Object.entries(resolved.services).map(([name, svc]) => [name, svc.port])
|
|
1856
|
-
),
|
|
1887
|
+
ports: new Map(Object.entries(resolved.services).map(([name, svc]) => [name, svc.port])),
|
|
1857
1888
|
strings: new Map(
|
|
1858
|
-
Object.entries(resolved.services).filter(
|
|
1889
|
+
Object.entries(resolved.services).filter(
|
|
1890
|
+
(entry) => Boolean(entry[1].connectionString)
|
|
1891
|
+
).map(([name, svc]) => [name, svc.connectionString])
|
|
1859
1892
|
)
|
|
1860
1893
|
};
|
|
1861
1894
|
context.ports.set("app", resolved.app.port);
|