@flisk-sh/flisk-export 0.8.0 → 0.9.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 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 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`.
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`, `logging` stays `logging`, a bind source `${NAME:-./path}` keeps reading NAME with its default rewritten for this file, `selinux` becomes the `:z`/`:Z` mount option, and an image may use `${NAME:?message}` (Flisk 1.4.28 fields). 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
@@ -11,7 +11,11 @@ import { ExportError } from "./errors.js";
11
11
  /** extraPorts `publish`: digits, dots, colons and `${NAME:-default}` / `${NAME-default}`, as flisk core accepts it (flisk#2947). */
12
12
  const PUBLISH = /^(?:[0-9.:]|\$\{[A-Za-z_][A-Za-z0-9_]*:?-[0-9.:]+\})+$/;
13
13
  /** An image reference, with Compose variables `${NAME}`, `${NAME:-default}` and `${NAME-default}` kept for Compose to resolve. */
14
- const IMAGE = /^(?:[A-Za-z0-9._/:@-]|\$\{[A-Za-z_][A-Za-z0-9_]*(?::?-[A-Za-z0-9._/:@-]*)?\})+$/;
14
+ const IMAGE = /^(?:[A-Za-z0-9._/:@-]|\$\{[A-Za-z_][A-Za-z0-9_]*(?::?-[A-Za-z0-9._/:@-]+|:?\?[A-Za-z0-9 !#%&()*+,./:;<=>?@[\]^_|~-]*)?\})+$/;
15
+ /** A bind source from the environment, `${NAME:-./path}` (flisk 1.4.28): NAME, the operator and the default path. */
16
+ const ENV_BIND = /^\$\{([A-Za-z_][A-Za-z0-9_]*)(:?-)(\.{1,2}(?:\/[A-Za-z0-9_.-]+)*\/?)\}$/;
17
+ const LOG_DRIVER = /^[a-z0-9][a-z0-9_.-]*$/;
18
+ const LOG_OPTION = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;
15
19
  /** The only resource type the Compose export covers: it is the one whose service.json is a Compose service. */
16
20
  export const COMPOSE_TYPE = "bring-your-own";
17
21
  const RESTART_POLICIES = new Set(["no", "on-failure", "unless-stopped", "always"]);
@@ -153,7 +157,15 @@ function serviceLines(resource, outDir, services) {
153
157
  throw new ExportError(`${name}: a volume needs a source and a target`);
154
158
  }
155
159
  let source = v.source;
156
- if (isNamedVolume(source)) {
160
+ const fromEnv = source.match(ENV_BIND);
161
+ if (v.selinux !== undefined && v.selinux !== "z" && v.selinux !== "Z") {
162
+ throw new ExportError(`${name}: volume selinux must be z or Z`);
163
+ }
164
+ if (fromEnv) {
165
+ // The default is relative to the service directory; Compose reads it relative to this file.
166
+ source = `\${${fromEnv[1]}${fromEnv[2]}${hostPath(outDir, resolveFrom(resource.path, fromEnv[3]))}}`;
167
+ }
168
+ else if (isNamedVolume(source)) {
157
169
  const dockerName = typeof v.name === "string" ? v.name : undefined;
158
170
  if (dockerName !== undefined && !DOCKER_NAME.test(dockerName)) {
159
171
  throw new ExportError(`${name}: volume name "${dockerName}" is not a Docker volume name`);
@@ -163,7 +175,11 @@ function serviceLines(resource, outDir, services) {
163
175
  else {
164
176
  source = hostPath(outDir, resolveFrom(resource.path, source));
165
177
  }
166
- lines.push(` - ${q(`${source}:${v.target}${v.readOnly === true ? ":ro" : ""}`)}`);
178
+ const options = [
179
+ ...(v.readOnly === true ? ["ro"] : []),
180
+ ...(typeof v.selinux === "string" ? [v.selinux] : []),
181
+ ];
182
+ lines.push(` - ${q(`${source}:${v.target}${options.length ? `:${options.join(",")}` : ""}`)}`);
167
183
  }
168
184
  }
169
185
  const ports = Array.isArray(c.extraPorts) ? c.extraPorts : [];
@@ -316,6 +332,26 @@ function serviceLines(resource, outDir, services) {
316
332
  lines.push(` - path: ${q(hostPath(outDir, resolveFrom(resource.path, file)))}`, " required: false");
317
333
  }
318
334
  }
335
+ // logging (flisk 1.4.28): a driver and string options, checked so nothing can add a key.
336
+ if (c.logging !== undefined) {
337
+ const logging = record(c.logging);
338
+ const options = Object.entries(record(logging.options));
339
+ if (logging.driver !== undefined &&
340
+ (typeof logging.driver !== "string" || !LOG_DRIVER.test(logging.driver))) {
341
+ throw new ExportError(`${name}: logging.driver "${String(logging.driver)}" is not a logging driver`);
342
+ }
343
+ for (const [key, value] of options) {
344
+ if (!LOG_OPTION.test(key) || typeof value !== "string") {
345
+ throw new ExportError(`${name}: logging option "${key}" needs a name of letters, digits, _ . - and a string`);
346
+ }
347
+ }
348
+ lines.push(" logging:", ...(typeof logging.driver === "string" ? [` driver: ${q(logging.driver)}`] : []), ...(options.length
349
+ ? [
350
+ " options:",
351
+ ...options.map(([key, value]) => ` ${key}: ${q(value)}`),
352
+ ]
353
+ : []));
354
+ }
319
355
  const profiles = strings(c.profiles);
320
356
  if (profiles.length > 0) {
321
357
  for (const p of profiles) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flisk-sh/flisk-export",
3
- "version": "0.8.0",
3
+ "version": "0.9.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",