@flisk-sh/flisk-export 0.7.0 → 0.8.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/README.md +1 -1
- package/dist/compose.js +33 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,7 +49,7 @@ Writes a **standalone** `docker-compose.yml` from the bring-your-own `service.js
|
|
|
49
49
|
networks, no `FLISK_*` variables, no generated secrets. `${VAR}` references in `env`, and every name in `secrets.required`, pass through as `${NAME}` for Compose to read from `.env`.
|
|
50
50
|
A volume's `name` (the Docker volume an install already has) is kept, and the project is named after its stack (or, when `.flisk/project.json` has `composeProjectNames.<stack>` from flisk-import, the Compose project name it had before, such as `pl_mail`), so `docker compose up` finds the same data as before.
|
|
51
51
|
An `image` with Compose variables (`postgres:${POSTGRES_VERSION:-18}-alpine`) is written as it is, for Compose to resolve; `restart: "on-failure:N"` keeps N. From `container`: `stopGracePeriod` becomes `stop_grace_period`, `networkAliases` become `networks: { default: { aliases } }` (not on a `sidecarOf` service, which has no network of its own), `extraHosts` become `extra_hosts` and `ulimits` stay `ulimits`. Each value is checked so it cannot add YAML keys; one that does not fit is an error.
|
|
52
|
-
`healthCheck.command` becomes a Compose `healthcheck` (with `startPeriod` as `start_period`); a service that lists a checked service in `dependsOn` waits for `service_healthy` (only when that healthcheck is written: a service with only `healthCheckPath`, or `enabled: false`, is waited for with `service_started`), and one that lists a `restart: "no"` job waits for `service_completed_successfully`.
|
|
52
|
+
`healthCheck.command` becomes a Compose `healthcheck` (with `startPeriod` as `start_period`); a service that lists a checked service in `dependsOn` waits for `service_healthy` (only when that healthcheck is written: a service with only `healthCheckPath`, or `enabled: false`, is waited for with `service_started`), and a `dependsOn` entry written as `{ name, condition }` (flisk#2983) keeps its condition. `buildArgs` become `build.args`. A service with no `restart` gets none (Compose's default), as the project's own Compose file had it. and one that lists a `restart: "no"` job waits for `service_completed_successfully`.
|
|
53
53
|
Other resource types and `command` (native) services are not exported. The file is generated: change `service.json` and run it
|
|
54
54
|
again with `--force`. It never starts a container or calls an API.
|
|
55
55
|
|
package/dist/compose.js
CHANGED
|
@@ -15,6 +15,11 @@ const IMAGE = /^(?:[A-Za-z0-9._/:@-]|\$\{[A-Za-z_][A-Za-z0-9_]*(?::?-[A-Za-z0-9.
|
|
|
15
15
|
/** The only resource type the Compose export covers: it is the one whose service.json is a Compose service. */
|
|
16
16
|
export const COMPOSE_TYPE = "bring-your-own";
|
|
17
17
|
const RESTART_POLICIES = new Set(["no", "on-failure", "unless-stopped", "always"]);
|
|
18
|
+
const CONDITIONS = new Set([
|
|
19
|
+
"service_started",
|
|
20
|
+
"service_healthy",
|
|
21
|
+
"service_completed_successfully",
|
|
22
|
+
]);
|
|
18
23
|
/** `on-failure:N` with a retry limit from 1 to 100. */
|
|
19
24
|
const RESTART_LIMIT = /^on-failure:([1-9][0-9]?|100)$/;
|
|
20
25
|
/** A Compose duration such as 30s, 1m30s or 500ms. */
|
|
@@ -86,6 +91,16 @@ function serviceLines(resource, outDir, services) {
|
|
|
86
91
|
lines.push(" build:", ` context: ${q(context)}`);
|
|
87
92
|
if (dockerfile)
|
|
88
93
|
lines.push(` dockerfile: ${q(dockerfile)}`);
|
|
94
|
+
// buildArgs (flisk#2983): NAME to a string, which may use Compose variables such as ${NODE_VERSION:-22}.
|
|
95
|
+
const args = Object.entries(record(c.buildArgs));
|
|
96
|
+
for (const [arg, value] of args) {
|
|
97
|
+
if (!ENV_NAME.test(arg) || typeof value !== "string") {
|
|
98
|
+
throw new ExportError(`${name}: buildArgs "${arg}" needs a name of letters, digits and _ and a string`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (args.length > 0) {
|
|
102
|
+
lines.push(" args:", ...args.map(([arg, value]) => ` ${arg}: ${q(value)}`));
|
|
103
|
+
}
|
|
89
104
|
}
|
|
90
105
|
const container = record(c.container);
|
|
91
106
|
if (container.init !== false)
|
|
@@ -96,9 +111,7 @@ function serviceLines(resource, outDir, services) {
|
|
|
96
111
|
}
|
|
97
112
|
lines.push(` restart: ${q(c.restart)}`);
|
|
98
113
|
}
|
|
99
|
-
|
|
100
|
-
lines.push(' restart: "unless-stopped"');
|
|
101
|
-
}
|
|
114
|
+
// No restart in service.json is written as none: Compose's default, as the project's own Compose file had it.
|
|
102
115
|
const sidecarOf = typeof c.sidecarOf === "string" ? c.sidecarOf : undefined;
|
|
103
116
|
if (sidecarOf) {
|
|
104
117
|
if (!known.has(sidecarOf)) {
|
|
@@ -182,11 +195,26 @@ function serviceLines(resource, outDir, services) {
|
|
|
182
195
|
lines.push(` - ${q(`${bind}:${hostPort}:${port}/${protocol}`)}`);
|
|
183
196
|
}
|
|
184
197
|
}
|
|
185
|
-
|
|
198
|
+
// dependsOn entries are names or { name, condition } (flisk#2983); a stated condition wins over the guess.
|
|
199
|
+
const dependsOn = (Array.isArray(c.dependsOn) ? c.dependsOn : [])
|
|
200
|
+
.map((entry) => typeof entry === "string"
|
|
201
|
+
? { name: entry, condition: undefined }
|
|
202
|
+
: { name: record(entry).name, condition: record(entry).condition })
|
|
203
|
+
.filter((d) => typeof d.name === "string" && known.has(d.name));
|
|
186
204
|
if (dependsOn.length > 0) {
|
|
187
205
|
lines.push(" depends_on:");
|
|
188
206
|
for (const d of dependsOn) {
|
|
189
|
-
|
|
207
|
+
const dep = known.get(d.name);
|
|
208
|
+
if (d.condition !== undefined && !CONDITIONS.has(d.condition)) {
|
|
209
|
+
throw new ExportError(`${name}: dependsOn "${d.name}" condition is not a Compose condition`, ["Use service_started, service_healthy or service_completed_successfully"]);
|
|
210
|
+
}
|
|
211
|
+
// service_healthy needs a healthcheck in this file; without one Compose would refuse to start.
|
|
212
|
+
const condition = d.condition === undefined
|
|
213
|
+
? dependencyCondition(dep)
|
|
214
|
+
: d.condition === "service_healthy" && !hasProbeCommand(dep.config.healthCheck)
|
|
215
|
+
? "service_started"
|
|
216
|
+
: d.condition;
|
|
217
|
+
lines.push(` ${d.name}:`, ` condition: ${condition}`);
|
|
190
218
|
}
|
|
191
219
|
}
|
|
192
220
|
lines.push(...healthcheckLines(name, c.healthCheck));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flisk-sh/flisk-export",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Write a Render Blueprint (render.yaml), a Cloudflare wrangler.toml or a standalone docker-compose.yml from Flisk service.json files. Never deploys.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|