@flisk-sh/flisk-export 0.4.2 → 0.5.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
@@ -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 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
48
+ `secrets.required`, `envFile`, `profiles`, `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
@@ -15,6 +15,10 @@ const RESTART_POLICIES = new Set(["no", "on-failure", "unless-stopped", "always"
15
15
  const SERVICE_NAME = /^[a-z0-9][a-z0-9_.-]*$/i;
16
16
  const ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
17
17
  const SHM_SIZE = /^\d+(b|k|kb|m|mb|g|gb)?$/i;
18
+ const TMPFS = /^\/[A-Za-z0-9_./-]*(:[a-z0-9=,_-]+)?$/;
19
+ const CPUS = /^[0-9]+(\.[0-9]{1,2})?$/;
20
+ const MEMORY = /^[0-9]+([bBkKmMgG][bB]?)?$/;
21
+ const PROFILE = /^[a-z0-9][a-z0-9-]*$/;
18
22
  const DOCKER_NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;
19
23
  export function isComposeExportable(resource) {
20
24
  return resource.type === COMPOSE_TYPE && typeof resource.config.command !== "string";
@@ -192,6 +196,42 @@ function serviceLines(resource, outDir, services) {
192
196
  }
193
197
  lines.push(` shm_size: ${q(container.shmSize)}`);
194
198
  }
199
+ const tmpfs = strings(container.tmpfs);
200
+ if (tmpfs.length > 0) {
201
+ for (const t of tmpfs) {
202
+ if (!TMPFS.test(t))
203
+ throw new ExportError(`${name}: tmpfs "${t}" is not /path or /path:options`);
204
+ }
205
+ lines.push(" tmpfs:", ...tmpfs.map((t) => ` - ${q(t)}`));
206
+ }
207
+ const cpus = container.cpus === undefined ? undefined : String(container.cpus);
208
+ const memory = typeof container.memory === "string" ? container.memory : undefined;
209
+ if (cpus !== undefined && !CPUS.test(cpus))
210
+ throw new ExportError(`${name}: cpus "${cpus}" is not a number of CPUs`);
211
+ if (memory !== undefined && !MEMORY.test(memory))
212
+ throw new ExportError(`${name}: memory "${memory}" is not a size such as 2g`);
213
+ if (cpus !== undefined || memory !== undefined) {
214
+ lines.push(" deploy:", " resources:", " limits:", ...(cpus !== undefined ? [` cpus: ${q(cpus)}`] : []), ...(memory !== undefined ? [` memory: ${q(memory)}`] : []));
215
+ }
216
+ // Paths in envFile are relative to the service directory; a missing file is skipped, as Flisk does.
217
+ const envFiles = strings(c.envFile);
218
+ if (envFiles.length > 0) {
219
+ lines.push(" env_file:");
220
+ for (const file of envFiles) {
221
+ if (!/^[A-Za-z0-9_.-]+(\/[A-Za-z0-9_.-]+)*$/.test(file)) {
222
+ throw new ExportError(`${name}: envFile "${file}" is not a relative path`);
223
+ }
224
+ lines.push(` - path: ${q(hostPath(outDir, resolveFrom(resource.path, file)))}`, " required: false");
225
+ }
226
+ }
227
+ const profiles = strings(c.profiles);
228
+ if (profiles.length > 0) {
229
+ for (const p of profiles) {
230
+ if (!PROFILE.test(p))
231
+ throw new ExportError(`${name}: profile "${p}" is not a profile name`);
232
+ }
233
+ lines.push(" profiles:", ...profiles.map((p) => ` - ${q(p)}`));
234
+ }
195
235
  return { lines, namedVolumes, models };
196
236
  }
197
237
  /** What Compose waits for before starting a dependent: a passing check, a finished one-shot job, or the start. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flisk-sh/flisk-export",
3
- "version": "0.4.2",
3
+ "version": "0.5.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",