@flisk-sh/flisk-export 0.4.0 → 0.4.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/README.md CHANGED
@@ -45,7 +45,7 @@ flisk-export compose --check # exit 1 when that file is out of date (for CI)
45
45
  ```
46
46
 
47
47
  Writes a **standalone** `docker-compose.yml` from the bring-your-own `service.json` files (`image` or `dockerfile`, `env`,
48
- `secrets.required`, `models`, `volumes`, `extraPorts`, `dependsOn`, `healthCheck`, `sidecarOf`, `container`). It runs with plain `docker compose up` and no Flisk: no external
48
+ `secrets.required`, `models`, `volumes`, `extraPorts`, `dependsOn`, `healthCheck`, `sidecarOf`, `container`). It runs without Flisk (`docker compose --env-file .env -f .autogenerated/docker-compose.yml up -d` from the project root, since Compose looks for `.env` next to the file it reads): no external
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, so `docker compose up` finds the same data as before.
51
51
  `healthCheck.command` becomes a Compose `healthcheck`; a service that lists a checked service in `dependsOn` waits for `service_healthy`, and one that lists a `restart: "no"` job waits for `service_completed_successfully`.
package/dist/compose.js CHANGED
@@ -7,6 +7,8 @@
7
7
  */
8
8
  import { relative, sep } from "node:path";
9
9
  import { ExportError } from "./errors.js";
10
+ /** extraPorts `publish`: digits, dots, colons and `${NAME:-default}`, as flisk core accepts it (flisk#2947). */
11
+ const PUBLISH = /^(?:[0-9.:]|\$\{[A-Za-z_][A-Za-z0-9_]*:-[0-9.:]+\})+$/;
10
12
  /** The only resource type the Compose export covers: it is the one whose service.json is a Compose service. */
11
13
  export const COMPOSE_TYPE = "bring-your-own";
12
14
  const RESTART_POLICIES = new Set(["no", "on-failure", "unless-stopped", "always"]);
@@ -130,9 +132,20 @@ function serviceLines(resource, outDir, services) {
130
132
  if (!Number.isInteger(port) || port < 1 || port > 65535) {
131
133
  throw new ExportError(`${name}: extraPorts needs a port from 1 to 65535`);
132
134
  }
133
- const hostPort = p.hostPort === undefined ? port : Number(p.hostPort);
134
- const bind = typeof p.bind === "string" && p.bind ? p.bind : "127.0.0.1";
135
135
  const protocol = p.protocol === "udp" ? "udp" : "tcp";
136
+ // `publish` (flisk#2947): the host side as the project's Compose wrote it, e.g. "${APP_HTTP_BIND:-80}"; Compose resolves it.
137
+ if (p.publish !== undefined) {
138
+ if (typeof p.publish !== "string" || !PUBLISH.test(p.publish)) {
139
+ throw new ExportError(`${name}: extraPorts publish must be a port, an IPv4 address:port, or \${NAME:-default}`);
140
+ }
141
+ lines.push(` - ${q(`${p.publish}:${port}/${protocol}`)}`);
142
+ continue;
143
+ }
144
+ const hostPort = p.hostPort === undefined ? port : Number(p.hostPort);
145
+ const bind = p.bind === undefined ? "127.0.0.1" : p.bind;
146
+ if (bind !== "127.0.0.1" && bind !== "0.0.0.0") {
147
+ throw new ExportError(`${name}: extraPorts bind must be 127.0.0.1 or 0.0.0.0`);
148
+ }
136
149
  lines.push(` - ${q(`${bind}:${hostPort}:${port}/${protocol}`)}`);
137
150
  }
138
151
  }
@@ -269,7 +282,9 @@ export function buildCompose(outDir, resources) {
269
282
  "# GENERATED by `flisk export compose` from the service.json files. DO NOT EDIT.",
270
283
  "# Change service.json and run `flisk export compose --force`; CI can run",
271
284
  "# `flisk export compose --check` to fail when this file is out of date.",
272
- "# Runs with plain `docker compose up`; Flisk is not needed to start it.",
285
+ "# Flisk is not needed to start it. Compose reads .env from this file's folder,",
286
+ "# so from the project root pass the project's .env:",
287
+ "# docker compose --env-file .env -f .autogenerated/docker-compose.yml up -d",
273
288
  "###############################################################################",
274
289
  "",
275
290
  // Without a name Compose takes the folder's (autogenerated), so containers and unnamed volumes would not match the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flisk-sh/flisk-export",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
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",