@flisk-sh/flisk-import 0.7.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
@@ -15,7 +15,7 @@ flisk import . --yes # write service.json files and project setup
15
15
  - **Keeps:** the service names (`db` stays `db`, so it stays the hostname), the build context and Dockerfile (or the image), the container port as written (3000, 80, 5432), `depends_on`, and an HTTP health path. Databases and brokers are private, with no proxy route.
16
16
  - **Runtime keys:** named volumes and bind mounts inside the project (`volumes`), `cap_add`, `cap_drop`, `init`, `read_only`, `user`, `security_opt` and `shm_size` (`container`), extra published ports (`extraPorts`, on 127.0.0.1 only), `network_mode: service:<name>` (`sidecarOf`) and `restart`.
17
17
  - **Environment:** values that cannot be secrets go into the committed `service.json` `env`: numbers, `true`/`false`, another imported service's address without a user, password or query (`http://invidious:3000`, `redis:6379`), and pure `${VAR}` references. Every other name, and any name that looks like a credential (`PASSWORD`, `TOKEN`, `KEY`, ...), goes into `secrets.required`, with its literal value copied to the project `.env`, which is added to `.gitignore`. Values in `.env` already are kept.
18
- - **Keeps:** a `command` on an image as the `CMD` of a one-line `Dockerfile` next to `service.json` (Flisk sets no container command), a `healthcheck` as `healthCheck.command`, a published database port as `extraPorts`, and `restart: on-failure:N` as `on-failure`.
18
+ - **Keeps:** a `command` or `entrypoint` on an image as the `CMD`/`ENTRYPOINT` of a small `Dockerfile` next to `service.json` (Flisk sets no container command), a `healthcheck` as `healthCheck.command`, a published database port as `extraPorts`, and `restart: on-failure:N` as `on-failure`.
19
19
  - **Drops, and says so:** `command` on a service with a `build`, `env_file` and every other untranslated key; anonymous volumes and paths outside the project; `network_mode` other than `service:<name>`; services with `profiles`, `extends`, an out-of-tree build or a `${VAR}` image.
20
20
  - **Does not start anything.** Run `flisk up` with Flisk core **1.4.24 or later**. The importer does not check the core version.
21
21
  - **Exit codes:** `0` when the plan succeeds (`--dry-run`, files written, or all `service.json` files already exist), `1` when no root `docker-compose.yml` or mappable service is found, and `2` when the write prompt is declined or closed without an answer (`Nothing written.`).
@@ -45,6 +45,11 @@ const TRANSLATED_KEYS = new Set([
45
45
  "volumes",
46
46
  "restart",
47
47
  "command",
48
+ "entrypoint",
49
+ "models",
50
+ // Flisk gives every service its own stack network and container name, so these change nothing it needs.
51
+ "networks",
52
+ "expose",
48
53
  ]);
49
54
  const CAPABILITY = /^[A-Z_]+$/;
50
55
  const USER = /^[A-Za-z0-9_.:-]+$/;
@@ -286,6 +291,20 @@ function healthProbeOf(healthcheck) {
286
291
  ...(retries ? { retries } : {}),
287
292
  };
288
293
  }
294
+ /** The models a service uses, joined to their top-level definitions. A model without a literal `model` is skipped. */
295
+ function modelsOf(uses, defined) {
296
+ const names = Array.isArray(uses) ? uses : isObj(uses) ? Object.keys(uses) : [];
297
+ const out = [];
298
+ for (const name of names) {
299
+ const def = isObj(defined) && typeof name === "string" ? defined[name] : undefined;
300
+ if (typeof name === "string" &&
301
+ isObj(def) &&
302
+ typeof def.model === "string" &&
303
+ /^[A-Za-z0-9_.-]+$/.test(name))
304
+ out.push({ name, model: def.model });
305
+ }
306
+ return out.length ? out : undefined;
307
+ }
289
308
  function healthPathOf(healthcheck) {
290
309
  if (!isObj(healthcheck) || !Array.isArray(healthcheck.test))
291
310
  return undefined;
@@ -413,7 +432,9 @@ registerDetector({
413
432
  ? Object.keys(raw.depends_on)
414
433
  : [];
415
434
  const command = commandOf(raw.command);
435
+ const models = modelsOf(raw.models, isObj(root) ? root.models : undefined);
416
436
  const containerCommand = containerCommandOf(raw.command);
437
+ const containerEntrypoint = containerCommandOf(raw.entrypoint);
417
438
  const healthProbe = healthProbeOf(raw.healthcheck);
418
439
  const envKeys = envNames(raw.environment);
419
440
  const env = envValues(raw.environment);
@@ -502,6 +523,8 @@ registerDetector({
502
523
  ...(dockerfile ? { dockerfile } : {}),
503
524
  ...(command ? { command } : {}),
504
525
  ...(containerCommand ? { containerCommand } : {}),
526
+ ...(containerEntrypoint ? { containerEntrypoint } : {}),
527
+ ...(models ? { models } : {}),
505
528
  ...(healthProbe ? { healthCheck: healthProbe } : {}),
506
529
  ...(selectedPort !== undefined ? { port: selectedPort } : {}),
507
530
  ...(healthCheckPath ? { healthCheckPath } : {}),
package/dist/merge.js CHANGED
@@ -72,6 +72,8 @@ function mergeGroup(name, dir, members, resolve) {
72
72
  ...firstOf(ordered, "volumes"),
73
73
  ...firstOf(ordered, "restart"),
74
74
  ...firstOf(ordered, "containerCommand"),
75
+ ...firstOf(ordered, "containerEntrypoint"),
76
+ ...firstOf(ordered, "models"),
75
77
  ...firstOf(ordered, "healthCheck"),
76
78
  ...(ordered.find((c) => c.sidecarOf)?.sidecarOf
77
79
  ? { sidecarOf: resolve(ordered.find((c) => c.sidecarOf)?.sidecarOf) }
package/dist/write.js CHANGED
@@ -207,16 +207,18 @@ export function planWrites(plan, force) {
207
207
  // Omit `image` from service.json so Flisk builds from the Dockerfile instead of pulling the tag.
208
208
  // Flisk has no container `command`, so a Compose `command` on an image becomes the CMD of a one-line Dockerfile.
209
209
  const files = [];
210
- const wrapWithCommand = !service.dockerfile && service.image && service.containerCommand;
210
+ const wrapWithCommand = !service.dockerfile &&
211
+ service.image &&
212
+ (service.containerCommand || service.containerEntrypoint);
211
213
  if (wrapWithCommand) {
212
214
  files.push({
213
215
  path: resolve(dirname(path), "Dockerfile"),
214
- content: `# From the Compose \`command\` of this service (flisk import). Flisk sets no container command, so it lives here.\nFROM ${service.image}\nCMD ${JSON.stringify(service.containerCommand)}\n`,
216
+ content: `# From the Compose \`command\` of this service (flisk import). Flisk sets no container command, so it lives here.\nFROM ${service.image}\n${service.containerEntrypoint ? `ENTRYPOINT ${JSON.stringify(service.containerEntrypoint)}\n` : ""}${service.containerCommand ? `CMD ${JSON.stringify(service.containerCommand)}\n` : ""}`,
215
217
  });
216
- notes.push(`command ${JSON.stringify(service.containerCommand)} is written as the CMD of a Dockerfile on ${service.image}`);
218
+ notes.push(`${service.containerEntrypoint ? "entrypoint" : "command"} ${JSON.stringify(service.containerEntrypoint ?? service.containerCommand)} is written to a Dockerfile on ${service.image}`);
217
219
  }
218
- else if (service.dockerfile && service.containerCommand) {
219
- notes.push(`command ${JSON.stringify(service.containerCommand)} not written: set it as CMD in ${service.dockerfile}`);
220
+ else if (service.dockerfile && (service.containerCommand || service.containerEntrypoint)) {
221
+ notes.push(`command/entrypoint not written: set it as CMD/ENTRYPOINT in ${service.dockerfile}`);
220
222
  }
221
223
  const source = wrapWithCommand
222
224
  ? { buildContext: ".", dockerfile: "Dockerfile" }
@@ -269,6 +271,7 @@ export function planWrites(plan, force) {
269
271
  ...(secretNames.length ? { secrets: { required: secretNames } } : {}),
270
272
  ...(service.restart ? { restart: service.restart } : {}),
271
273
  ...(service.container ? { container: service.container } : {}),
274
+ ...(service.models ? { models: service.models } : {}),
272
275
  ...(extraPorts.length ? { extraPorts } : {}),
273
276
  ...(sidecarOf ? { sidecarOf } : {}),
274
277
  ...(volumes.length
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flisk-sh/flisk-import",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "Import a repository's root docker-compose.yml into Flisk service.json files, or register its Tiltfile.",
5
5
  "type": "module",
6
6
  "license": "MIT",