@shiplane/fly 0.6.0-rc.0 → 0.6.0-rc.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/dist/index.d.ts CHANGED
@@ -1,9 +1,13 @@
1
- import { DeliveryAdapter, ServerHostingPort } from "shiplane/plugin";
1
+ import { CatalogEntry, DeliveryAdapter, ServerHostingPort } from "shiplane/plugin";
2
2
 
3
3
  //#region src/fly-server-hosting.adapter.d.ts
4
4
  /** Any Dockerfile on Fly.io: `flyctl deploy`, from this machine or the ship workflow on CI. */
5
5
  type FlyServerHostingAdapter = DeliveryAdapter<ServerHostingPort>;
6
6
  declare const flyServerHosting: () => FlyServerHostingAdapter;
7
7
  //#endregion
8
- export { type FlyServerHostingAdapter, flyServerHosting };
8
+ //#region src/catalog.d.ts
9
+ /** What a shiplane.yml names from this plugin: `serverHosting: fly`. */
10
+ declare const catalog: readonly CatalogEntry[];
11
+ //#endregion
12
+ export { type FlyServerHostingAdapter, catalog, flyServerHosting };
9
13
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,142 +1,3 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { defineServerHosting, firstLine, isEnvVarName, parseJson, perEnv, z } from "shiplane/plugin";
4
- //#region src/fly-server-hosting.adapter.ts
5
- const FlyOptions = z.object({
6
- app: perEnv(z.string()).describe("The Fly app, per environment"),
7
- config: perEnv(z.string()).default("fly.toml").describe("Its fly.toml, relative to the unit's folder"),
8
- dockerfile: z.string().default("Dockerfile").describe("Relative to the unit's folder; the image builds from the repository root"),
9
- url: perEnv(z.string()).optional().describe("Where it answers, for other units to read"),
10
- buildSecrets: z.array(z.string()).default([]).describe("Variables its image build reads as secrets, passed by name when set")
11
- });
12
- const FlyTarget = z.object({
13
- app: z.string(),
14
- config: z.string().default("fly.toml")
15
- });
16
- const FlySecrets = z.array(z.union([z.object({ name: z.string() }), z.object({ Name: z.string() })]));
17
- const jsonArrayIn = (output) => {
18
- const start = output.search(/^\s*\[/m);
19
- return start === -1 ? "" : output.slice(start, output.lastIndexOf("]") + 1);
20
- };
21
- /** Keys of a fly.toml's `[env]` block: variables Fly sets next to its secrets. */
22
- const tomlEnvKeys = (toml) => {
23
- const lines = toml.split("\n");
24
- const start = lines.findIndex((line) => line.trim() === "[env]");
25
- if (start === -1) return [];
26
- const block = lines.slice(start + 1);
27
- const end = block.findIndex((line) => /^\s*\[/.test(line));
28
- return (end === -1 ? block : block.slice(0, end)).flatMap((line) => {
29
- const key = /^\s*([A-Z_][A-Z0-9_]*)\s*=/.exec(line)?.[1];
30
- return key ? [key] : [];
31
- });
32
- };
33
- const readToml = (file) => fs.existsSync(file) ? fs.readFileSync(file, "utf8") : "";
34
- /** Secrets of the Fly app plus its toml's `[env]` keys; values are never read. */
35
- const flyEnv = ({ root, shell }) => ({
36
- listNames: async ({ unit, options }) => {
37
- const { app, config } = FlyTarget.parse(options);
38
- const args = [
39
- "secrets",
40
- "list",
41
- "-a",
42
- app,
43
- "--json"
44
- ];
45
- const result = await shell.capture("flyctl", args);
46
- if (result.status !== 0) {
47
- const reason = firstLine(result.stderr) ?? `exit ${result.status}`;
48
- throw new Error(`flyctl secrets list -a ${app}: ${reason}`);
49
- }
50
- const listed = parseJson({
51
- text: jsonArrayIn(result.stdout),
52
- schema: FlySecrets
53
- });
54
- if (!listed.success) throw new Error(`flyctl secrets list -a ${app}: no secrets list in its output`);
55
- const secrets = listed.data.map((secret) => "name" in secret ? secret.name : secret.Name);
56
- const toml = tomlEnvKeys(readToml(path.join(root, unit.dir, config)));
57
- return new Set([...secrets, ...toml].filter(isEnvVarName));
58
- },
59
- setCommand: ({ options, names }) => `flyctl secrets set --stage -a ${FlyTarget.parse(options).app} ${names.map((name) => `${name}=...`).join(" ")}`
60
- });
61
- const flyServerHosting = () => defineServerHosting({
62
- name: "fly",
63
- settings: FlyOptions,
64
- env: flyEnv,
65
- typicalMinutes: 13,
66
- describe: ({ options }) => `${options.app} (Fly)`,
67
- detect: (folder) => {
68
- const tomls = folder.files.filter((file) => /^fly(-[\w]+)?\.toml$/.test(file)).sort();
69
- if (tomls.length === 0) return folder.has("Dockerfile") ? {
70
- certainty: "possible",
71
- reason: "Dockerfile",
72
- options: {}
73
- } : null;
74
- const appOf = (file) => /^app\s*=\s*"([^"]+)"/m.exec(folder.read(file) ?? "")?.[1];
75
- const options = ["fly-preview.toml", "fly-production.toml"].every((file) => tomls.includes(file)) ? {
76
- app: {
77
- preview: appOf("fly-preview.toml"),
78
- production: appOf("fly-production.toml")
79
- },
80
- config: {
81
- preview: "fly-preview.toml",
82
- production: "fly-production.toml"
83
- }
84
- } : {
85
- app: appOf(tomls[0] ?? "fly.toml"),
86
- ...tomls[0] === "fly.toml" ? {} : { config: tomls[0] }
87
- };
88
- return {
89
- certainty: "found",
90
- reason: tomls.join(", "),
91
- options
92
- };
93
- },
94
- questions: (folder, found, repository) => found.app === void 0 ? [{
95
- key: "app",
96
- message: "Fly app?",
97
- initial: `${repository}-${folder.name}`
98
- }] : [],
99
- requirements: () => [{
100
- label: "flyctl",
101
- check: {
102
- command: "flyctl",
103
- args: ["auth", "whoami"]
104
- },
105
- fix: {
106
- command: "flyctl",
107
- args: ["auth", "login"]
108
- },
109
- install: {
110
- command: {
111
- command: "sh",
112
- args: ["-c", "curl -fsSL https://fly.io/install.sh | sh"]
113
- },
114
- path: "$HOME/.fly/bin"
115
- },
116
- secrets: ["FLY_API_TOKEN"]
117
- }],
118
- jobs: ({ unit, tag, options }) => [{
119
- label: `deploy ${tag} to ${options.app} (Fly)`,
120
- local: [{
121
- command: "flyctl",
122
- args: [
123
- "deploy",
124
- "--remote-only",
125
- "--config",
126
- path.posix.join(unit.dir, options.config),
127
- "--dockerfile",
128
- path.posix.join(unit.dir, options.dockerfile)
129
- ],
130
- secrets: options.buildSecrets.map((name) => ({
131
- flag: "--build-secret",
132
- name
133
- }))
134
- }],
135
- ci: { ref: tag },
136
- record: true
137
- }]
138
- });
139
- //#endregion
140
- export { flyServerHosting };
141
-
1
+ import e from"node:fs";import t from"node:path";import{adapterEntry as n,defineServerHosting as r,firstLine as i,isEnvVarName as a,parseJson as o,perEnv as s,z as c}from"shiplane/plugin";import{z as l}from"shiplane";const u=c.object({app:s(c.string()).describe(`The Fly app, per environment`),config:s(c.string()).default(`fly.toml`).describe(`Its fly.toml, relative to the unit's folder`),dockerfile:c.string().default(`Dockerfile`).describe(`Relative to the unit's folder; the image builds from the repository root`),url:s(c.string()).optional().describe(`Where it answers, for other units to read`),buildSecrets:c.array(c.string()).default([]).describe(`Variables its image build reads as secrets, passed by name when set`)}),d=c.object({app:c.string(),config:c.string().default(`fly.toml`)}),f=c.array(c.union([c.object({name:c.string()}),c.object({Name:c.string()})])),jsonArrayIn=e=>{let t=e.search(/^\s*\[/m);return t===-1?``:e.slice(t,e.lastIndexOf(`]`)+1)},tomlEnvKeys=e=>{let t=e.split(`
2
+ `),n=t.findIndex(e=>e.trim()===`[env]`);if(n===-1)return[];let r=t.slice(n+1),i=r.findIndex(e=>/^\s*\[/.test(e));return(i===-1?r:r.slice(0,i)).flatMap(e=>{let t=/^\s*([A-Z_][A-Z0-9_]*)\s*=/.exec(e)?.[1];return t?[t]:[]})},readToml=t=>e.existsSync(t)?e.readFileSync(t,`utf8`):``,flyEnv=({root:e,shell:n})=>({listNames:async({unit:r,options:s})=>{let{app:c,config:l}=d.parse(s),u=[`secrets`,`list`,`-a`,c,`--json`],p=await n.capture(`flyctl`,u);if(p.status!==0){let e=i(p.stderr)??`exit ${p.status}`;throw Error(`flyctl secrets list -a ${c}: ${e}`)}let m=o({text:jsonArrayIn(p.stdout),schema:f});if(!m.success)throw Error(`flyctl secrets list -a ${c}: no secrets list in its output`);let h=m.data.map(e=>`name`in e?e.name:e.Name),g=tomlEnvKeys(readToml(t.join(e,r.dir,l)));return new Set([...h,...g].filter(a))},setCommand:({options:e,names:t})=>`flyctl secrets set --stage -a ${d.parse(e).app} ${t.map(e=>`${e}=...`).join(` `)}`}),flyServerHosting=()=>r({name:`fly`,settings:u,env:flyEnv,typicalMinutes:13,describe:({options:e})=>`${e.app} (Fly)`,detect:e=>{let t=e.files.filter(e=>/^fly(-[\w]+)?\.toml$/.test(e)).sort();if(t.length===0)return e.has(`Dockerfile`)?{certainty:`possible`,reason:`Dockerfile`,options:{}}:null;let appOf=t=>/^app\s*=\s*"([^"]+)"/m.exec(e.read(t)??``)?.[1],n=[`fly-preview.toml`,`fly-production.toml`].every(e=>t.includes(e))?{app:{preview:appOf(`fly-preview.toml`),production:appOf(`fly-production.toml`)},config:{preview:`fly-preview.toml`,production:`fly-production.toml`}}:{app:appOf(t[0]??`fly.toml`),...t[0]===`fly.toml`?{}:{config:t[0]}};return{certainty:`found`,reason:t.join(`, `),options:n}},questions:(e,t,n)=>t.app===void 0?[{key:`app`,message:`Fly app?`,initial:`${n}-${e.name}`}]:[],requirements:()=>[{label:`flyctl`,check:{command:`flyctl`,args:[`auth`,`whoami`]},fix:{command:`flyctl`,args:[`auth`,`login`]},install:{command:{command:`sh`,args:[`-c`,`curl -fsSL https://fly.io/install.sh | sh`]},path:`$HOME/.fly/bin`},secrets:[`FLY_API_TOKEN`]}],jobs:({unit:e,tag:n,options:r})=>[{label:`deploy ${n} to ${r.app} (Fly)`,local:[{command:`flyctl`,args:[`deploy`,`--remote-only`,`--config`,t.posix.join(e.dir,r.config),`--dockerfile`,t.posix.join(e.dir,r.dockerfile)],secrets:r.buildSecrets.map(e=>({flag:`--build-secret`,name:e}))}],ci:{ref:n},record:!0}]}),p=[n({name:`fly`,port:`serverHosting`,description:`Deploys each app to Fly.io, through flyctl`,options:l.object({}),make:()=>flyServerHosting()})];export{p as catalog,flyServerHosting};
142
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/fly-server-hosting.adapter.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type {\n AdapterContext,\n DeliveryAdapter,\n PlatformEnvPort,\n ServerHostingPort,\n} from \"shiplane/plugin\";\nimport {\n defineServerHosting,\n firstLine,\n isEnvVarName,\n parseJson,\n perEnv,\n z,\n} from \"shiplane/plugin\";\n\nconst FlyOptions = z.object({\n app: perEnv(z.string()).describe(\"The Fly app, per environment\"),\n config: perEnv(z.string())\n .default(\"fly.toml\")\n .describe(\"Its fly.toml, relative to the unit's folder\"),\n dockerfile: z\n .string()\n .default(\"Dockerfile\")\n .describe(\"Relative to the unit's folder; the image builds from the repository root\"),\n url: perEnv(z.string()).optional().describe(\"Where it answers, for other units to read\"),\n buildSecrets: z\n .array(z.string())\n .default([])\n .describe(\"Variables its image build reads as secrets, passed by name when set\"),\n});\n\n// The settings of one environment, as the env check receives them.\nconst FlyTarget = z.object({ app: z.string(), config: z.string().default(\"fly.toml\") });\n\n// Older flyctl printed `Name`, current prints `name`.\nconst FlySecrets = z.array(\n z.union([z.object({ name: z.string() }), z.object({ Name: z.string() })]),\n);\n\n// flyctl may print a notice before its JSON: read from the first line that opens an array.\nconst jsonArrayIn = (output: string) => {\n const start = output.search(/^\\s*\\[/m);\n return start === -1 ? \"\" : output.slice(start, output.lastIndexOf(\"]\") + 1);\n};\n\n/** Keys of a fly.toml's `[env]` block: variables Fly sets next to its secrets. */\nconst tomlEnvKeys = (toml: string): string[] => {\n const lines = toml.split(\"\\n\");\n const start = lines.findIndex((line) => line.trim() === \"[env]\");\n if (start === -1) return [];\n const block = lines.slice(start + 1);\n const end = block.findIndex((line) => /^\\s*\\[/.test(line));\n return (end === -1 ? block : block.slice(0, end)).flatMap((line) => {\n const key = /^\\s*([A-Z_][A-Z0-9_]*)\\s*=/.exec(line)?.[1];\n return key ? [key] : [];\n });\n};\n\nconst readToml = (file: string) => (fs.existsSync(file) ? fs.readFileSync(file, \"utf8\") : \"\");\n\n/** Secrets of the Fly app plus its toml's `[env]` keys; values are never read. */\nconst flyEnv = ({ root, shell }: AdapterContext): PlatformEnvPort => ({\n listNames: async ({ unit, options }) => {\n const { app, config } = FlyTarget.parse(options);\n const args = [\"secrets\", \"list\", \"-a\", app, \"--json\"];\n const result = await shell.capture(\"flyctl\", args);\n if (result.status !== 0) {\n const reason = firstLine(result.stderr) ?? `exit ${result.status}`;\n throw new Error(`flyctl secrets list -a ${app}: ${reason}`);\n }\n const listed = parseJson({ text: jsonArrayIn(result.stdout), schema: FlySecrets });\n if (!listed.success) {\n throw new Error(`flyctl secrets list -a ${app}: no secrets list in its output`);\n }\n const secrets = listed.data.map((secret) => (\"name\" in secret ? secret.name : secret.Name));\n const toml = tomlEnvKeys(readToml(path.join(root, unit.dir, config)));\n return new Set([...secrets, ...toml].filter(isEnvVarName));\n },\n // --stage: the next deploy applies them, instead of a restart now.\n setCommand: ({ options, names }) =>\n `flyctl secrets set --stage -a ${FlyTarget.parse(options).app} ${names.map((name) => `${name}=...`).join(\" \")}`,\n});\n\n/** Any Dockerfile on Fly.io: `flyctl deploy`, from this machine or the ship workflow on CI. */\nexport type FlyServerHostingAdapter = DeliveryAdapter<ServerHostingPort>;\n\nexport const flyServerHosting = (): FlyServerHostingAdapter =>\n defineServerHosting({\n name: \"fly\",\n settings: FlyOptions,\n env: flyEnv,\n // The ship workflow typechecks before Fly builds the image remotely.\n typicalMinutes: 13,\n describe: ({ options }) => `${options.app} (Fly)`,\n detect: (folder) => {\n const tomls = folder.files.filter((file) => /^fly(-[\\w]+)?\\.toml$/.test(file)).sort();\n if (tomls.length === 0) {\n return folder.has(\"Dockerfile\")\n ? { certainty: \"possible\", reason: \"Dockerfile\", options: {} }\n : null;\n }\n const appOf = (file: string) => /^app\\s*=\\s*\"([^\"]+)\"/m.exec(folder.read(file) ?? \"\")?.[1];\n const perEnvironment = [\"fly-preview.toml\", \"fly-production.toml\"].every((file) =>\n tomls.includes(file),\n );\n const options = perEnvironment\n ? {\n app: { preview: appOf(\"fly-preview.toml\"), production: appOf(\"fly-production.toml\") },\n config: { preview: \"fly-preview.toml\", production: \"fly-production.toml\" },\n }\n : {\n app: appOf(tomls[0] ?? \"fly.toml\"),\n ...(tomls[0] === \"fly.toml\" ? {} : { config: tomls[0] }),\n };\n return { certainty: \"found\", reason: tomls.join(\", \"), options };\n },\n questions: (folder, found, repository) =>\n found.app === undefined\n ? [{ key: \"app\", message: \"Fly app?\", initial: `${repository}-${folder.name}` }]\n : [],\n requirements: () => [\n {\n label: \"flyctl\",\n check: { command: \"flyctl\", args: [\"auth\", \"whoami\"] },\n fix: { command: \"flyctl\", args: [\"auth\", \"login\"] },\n install: {\n command: { command: \"sh\", args: [\"-c\", \"curl -fsSL https://fly.io/install.sh | sh\"] },\n path: \"$HOME/.fly/bin\",\n },\n secrets: [\"FLY_API_TOKEN\"],\n },\n ],\n jobs: ({ unit, tag, options }) => [\n {\n label: `deploy ${tag} to ${options.app} (Fly)`,\n local: [\n {\n command: \"flyctl\",\n args: [\n \"deploy\",\n \"--remote-only\",\n // No --detach: the deploy is recorded as done, so it waits until the machines run it.\n \"--config\",\n path.posix.join(unit.dir, options.config),\n \"--dockerfile\",\n path.posix.join(unit.dir, options.dockerfile),\n ],\n secrets: options.buildSecrets.map((name) => ({ flag: \"--build-secret\", name })),\n },\n ],\n ci: { ref: tag },\n record: true,\n },\n ],\n });\n"],"mappings":";;;;AAiBA,MAAM,aAAa,EAAE,OAAO;CAC1B,KAAK,OAAO,EAAE,QAAQ,CAAC,CAAC,SAAS,+BAA+B;CAChE,QAAQ,OAAO,EAAE,QAAQ,CAAC,CACvB,QAAQ,WAAW,CACnB,SAAS,8CAA8C;CAC1D,YAAY,EACT,QAAQ,CACR,QAAQ,aAAa,CACrB,SAAS,2EAA2E;CACvF,KAAK,OAAO,EAAE,QAAQ,CAAC,CAAC,UAAU,CAAC,SAAS,4CAA4C;CACxF,cAAc,EACX,MAAM,EAAE,QAAQ,CAAC,CACjB,QAAQ,EAAE,CAAC,CACX,SAAS,sEAAsE;CACnF,CAAC;AAGF,MAAM,YAAY,EAAE,OAAO;CAAE,KAAK,EAAE,QAAQ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ClC,GAAI,MAAM,OAAO,aAAa,EAAE,GAAG,EAAE,QAAQ,MAAM,IAAI;GACxD;AACL,SAAO;GAAE,WAAW;GAAS,QAAQ,MAAM,KAAK,KAAK;GAAE;GAAS;;CAElE,YAAY,QAAQ,OAAO,eACzB,MAAM,QAAQ,KAAA,IACV,CAAC;EAAE,KAAK;EAAO,SAAS;EAAY,SAAS,GAAG,WAAW,GAAG,OAAO;EAAQ,CAAC,GAC9E,EAAE;CACR,oBAAoB,CAClB;EACE,OAAO;EACP,OAAO;GAAE,SAAS;GAAU,MAAM,CAAC,QAAQ,SAAS;GAAE;EACtD,KAAK;GAAE,SAAS;GAAU,MAAM,CAAC,QAAQ,QAAQ;GAAE;EACnD,SAAS;GACP,SAAS;IAAE,SAAS;IAAM,MAAM,CAAC,MAAM,4CAA4C;IAAE;GACrF,MAAM;GACP;EACD,SAAS,CAAC,gBAAgB;EAC3B,CACF;CACD,OAAO,EAAE,MAAM,KAAK,cAAc,CAChC;EACE,OAAO,UAAU,IAAI,MAAM,QAAQ,IAAI;EACvC,OAAO,CACL;GACE,SAAS;GACT,MAAM;IACJ;IACA;IAEA;IACA,KAAK,MAAM,KAAK,KAAK,KAAK,QAAQ,OAAO;IACzC;IACA,KAAK,MAAM,KAAK,KAAK,KAAK,QAAQ,WAAW;IAC9C;GACD,SAAS,QAAQ,aAAa,KAAK,UAAU;IAAE,MAAM;IAAkB;IAAM,EAAE;GAChF,CACF;EACD,IAAI,EAAE,KAAK,KAAK;EAChB,QAAQ;EACT,CACF;CACF,CAAC"}
1
+ {"version":3,"file":"index.js","names":["z"],"sources":["../src/fly-server-hosting.adapter.ts","../src/catalog.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type {\n AdapterContext,\n DeliveryAdapter,\n PlatformEnvPort,\n ServerHostingPort,\n} from \"shiplane/plugin\";\nimport {\n defineServerHosting,\n firstLine,\n isEnvVarName,\n parseJson,\n perEnv,\n z,\n} from \"shiplane/plugin\";\n\nconst FlyOptions = z.object({\n app: perEnv(z.string()).describe(\"The Fly app, per environment\"),\n config: perEnv(z.string())\n .default(\"fly.toml\")\n .describe(\"Its fly.toml, relative to the unit's folder\"),\n dockerfile: z\n .string()\n .default(\"Dockerfile\")\n .describe(\"Relative to the unit's folder; the image builds from the repository root\"),\n url: perEnv(z.string()).optional().describe(\"Where it answers, for other units to read\"),\n buildSecrets: z\n .array(z.string())\n .default([])\n .describe(\"Variables its image build reads as secrets, passed by name when set\"),\n});\n\n// The settings of one environment, as the env check receives them.\nconst FlyTarget = z.object({ app: z.string(), config: z.string().default(\"fly.toml\") });\n\n// Older flyctl printed `Name`, current prints `name`.\nconst FlySecrets = z.array(\n z.union([z.object({ name: z.string() }), z.object({ Name: z.string() })]),\n);\n\n// flyctl may print a notice before its JSON: read from the first line that opens an array.\nconst jsonArrayIn = (output: string) => {\n const start = output.search(/^\\s*\\[/m);\n return start === -1 ? \"\" : output.slice(start, output.lastIndexOf(\"]\") + 1);\n};\n\n/** Keys of a fly.toml's `[env]` block: variables Fly sets next to its secrets. */\nconst tomlEnvKeys = (toml: string): string[] => {\n const lines = toml.split(\"\\n\");\n const start = lines.findIndex((line) => line.trim() === \"[env]\");\n if (start === -1) return [];\n const block = lines.slice(start + 1);\n const end = block.findIndex((line) => /^\\s*\\[/.test(line));\n return (end === -1 ? block : block.slice(0, end)).flatMap((line) => {\n const key = /^\\s*([A-Z_][A-Z0-9_]*)\\s*=/.exec(line)?.[1];\n return key ? [key] : [];\n });\n};\n\nconst readToml = (file: string) => (fs.existsSync(file) ? fs.readFileSync(file, \"utf8\") : \"\");\n\n/** Secrets of the Fly app plus its toml's `[env]` keys; values are never read. */\nconst flyEnv = ({ root, shell }: AdapterContext): PlatformEnvPort => ({\n listNames: async ({ unit, options }) => {\n const { app, config } = FlyTarget.parse(options);\n const args = [\"secrets\", \"list\", \"-a\", app, \"--json\"];\n const result = await shell.capture(\"flyctl\", args);\n if (result.status !== 0) {\n const reason = firstLine(result.stderr) ?? `exit ${result.status}`;\n throw new Error(`flyctl secrets list -a ${app}: ${reason}`);\n }\n const listed = parseJson({ text: jsonArrayIn(result.stdout), schema: FlySecrets });\n if (!listed.success) {\n throw new Error(`flyctl secrets list -a ${app}: no secrets list in its output`);\n }\n const secrets = listed.data.map((secret) => (\"name\" in secret ? secret.name : secret.Name));\n const toml = tomlEnvKeys(readToml(path.join(root, unit.dir, config)));\n return new Set([...secrets, ...toml].filter(isEnvVarName));\n },\n // --stage: the next deploy applies them, instead of a restart now.\n setCommand: ({ options, names }) =>\n `flyctl secrets set --stage -a ${FlyTarget.parse(options).app} ${names.map((name) => `${name}=...`).join(\" \")}`,\n});\n\n/** Any Dockerfile on Fly.io: `flyctl deploy`, from this machine or the ship workflow on CI. */\nexport type FlyServerHostingAdapter = DeliveryAdapter<ServerHostingPort>;\n\nexport const flyServerHosting = (): FlyServerHostingAdapter =>\n defineServerHosting({\n name: \"fly\",\n settings: FlyOptions,\n env: flyEnv,\n // The ship workflow typechecks before Fly builds the image remotely.\n typicalMinutes: 13,\n describe: ({ options }) => `${options.app} (Fly)`,\n detect: (folder) => {\n const tomls = folder.files.filter((file) => /^fly(-[\\w]+)?\\.toml$/.test(file)).sort();\n if (tomls.length === 0) {\n return folder.has(\"Dockerfile\")\n ? { certainty: \"possible\", reason: \"Dockerfile\", options: {} }\n : null;\n }\n const appOf = (file: string) => /^app\\s*=\\s*\"([^\"]+)\"/m.exec(folder.read(file) ?? \"\")?.[1];\n const perEnvironment = [\"fly-preview.toml\", \"fly-production.toml\"].every((file) =>\n tomls.includes(file),\n );\n const options = perEnvironment\n ? {\n app: { preview: appOf(\"fly-preview.toml\"), production: appOf(\"fly-production.toml\") },\n config: { preview: \"fly-preview.toml\", production: \"fly-production.toml\" },\n }\n : {\n app: appOf(tomls[0] ?? \"fly.toml\"),\n ...(tomls[0] === \"fly.toml\" ? {} : { config: tomls[0] }),\n };\n return { certainty: \"found\", reason: tomls.join(\", \"), options };\n },\n questions: (folder, found, repository) =>\n found.app === undefined\n ? [{ key: \"app\", message: \"Fly app?\", initial: `${repository}-${folder.name}` }]\n : [],\n requirements: () => [\n {\n label: \"flyctl\",\n check: { command: \"flyctl\", args: [\"auth\", \"whoami\"] },\n fix: { command: \"flyctl\", args: [\"auth\", \"login\"] },\n install: {\n command: { command: \"sh\", args: [\"-c\", \"curl -fsSL https://fly.io/install.sh | sh\"] },\n path: \"$HOME/.fly/bin\",\n },\n secrets: [\"FLY_API_TOKEN\"],\n },\n ],\n jobs: ({ unit, tag, options }) => [\n {\n label: `deploy ${tag} to ${options.app} (Fly)`,\n local: [\n {\n command: \"flyctl\",\n args: [\n \"deploy\",\n \"--remote-only\",\n // No --detach: the deploy is recorded as done, so it waits until the machines run it.\n \"--config\",\n path.posix.join(unit.dir, options.config),\n \"--dockerfile\",\n path.posix.join(unit.dir, options.dockerfile),\n ],\n secrets: options.buildSecrets.map((name) => ({ flag: \"--build-secret\", name })),\n },\n ],\n ci: { ref: tag },\n record: true,\n },\n ],\n });\n","import type { CatalogEntry } from \"shiplane/plugin\";\nimport { z } from \"shiplane\";\nimport { adapterEntry } from \"shiplane/plugin\";\n\nimport { flyServerHosting } from \"./fly-server-hosting.adapter\";\n\n/** What a shiplane.yml names from this plugin: `serverHosting: fly`. */\nexport const catalog: readonly CatalogEntry[] = [\n adapterEntry({\n name: \"fly\",\n port: \"serverHosting\",\n description: \"Deploys each app to Fly.io, through flyctl\",\n options: z.object({}),\n make: () => flyServerHosting(),\n }),\n];\n"],"mappings":"wNAiBA,MAAM,EAAa,EAAE,OAAO,CAC1B,IAAK,EAAO,EAAE,QAAQ,CAAC,CAAC,SAAS,+BAA+B,CAChE,OAAQ,EAAO,EAAE,QAAQ,CAAC,CACvB,QAAQ,WAAW,CACnB,SAAS,8CAA8C,CAC1D,WAAY,EACT,QAAQ,CACR,QAAQ,aAAa,CACrB,SAAS,2EAA2E,CACvF,IAAK,EAAO,EAAE,QAAQ,CAAC,CAAC,UAAU,CAAC,SAAS,4C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6.0-rc.0",
3
+ "version": "0.6.0-rc.2",
4
4
  "description": "Fly.io plugin for shiplane: deploy any Dockerfile app per environment with flyctl.",
5
5
  "keywords": [
6
6
  "shiplane",
@@ -38,10 +38,10 @@
38
38
  "prettier": "^3.10.1",
39
39
  "typescript": "6.0.3",
40
40
  "vitest": "^5.1.0",
41
- "shiplane": "0.6.0-rc.0"
41
+ "shiplane": "0.6.0-rc.2"
42
42
  },
43
43
  "peerDependencies": {
44
- "shiplane": "0.6.0-rc.0"
44
+ "shiplane": "0.6.0-rc.2"
45
45
  },
46
46
  "shiplane": {
47
47
  "adapters": [