@shiplane/fly 0.6.0-nightly.7 → 0.6.0-nightly.8

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.js CHANGED
@@ -1,153 +1,3 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { adapterEntry, defineServerHosting, firstLine, isEnvVarName, parseJson, perEnv, z } from "shiplane/plugin";
4
- import { z as z$1 } from "shiplane";
5
- //#region src/fly-server-hosting.adapter.ts
6
- const FlyOptions = z.object({
7
- app: perEnv(z.string()).describe("The Fly app, per environment"),
8
- config: perEnv(z.string()).default("fly.toml").describe("Its fly.toml, relative to the unit's folder"),
9
- dockerfile: z.string().default("Dockerfile").describe("Relative to the unit's folder; the image builds from the repository root"),
10
- url: perEnv(z.string()).optional().describe("Where it answers, for other units to read"),
11
- buildSecrets: z.array(z.string()).default([]).describe("Variables its image build reads as secrets, passed by name when set")
12
- });
13
- const FlyTarget = z.object({
14
- app: z.string(),
15
- config: z.string().default("fly.toml")
16
- });
17
- const FlySecrets = z.array(z.union([z.object({ name: z.string() }), z.object({ Name: z.string() })]));
18
- const jsonArrayIn = (output) => {
19
- const start = output.search(/^\s*\[/m);
20
- return start === -1 ? "" : output.slice(start, output.lastIndexOf("]") + 1);
21
- };
22
- /** Keys of a fly.toml's `[env]` block: variables Fly sets next to its secrets. */
23
- const tomlEnvKeys = (toml) => {
24
- const lines = toml.split("\n");
25
- const start = lines.findIndex((line) => line.trim() === "[env]");
26
- if (start === -1) return [];
27
- const block = lines.slice(start + 1);
28
- const end = block.findIndex((line) => /^\s*\[/.test(line));
29
- return (end === -1 ? block : block.slice(0, end)).flatMap((line) => {
30
- const key = /^\s*([A-Z_][A-Z0-9_]*)\s*=/.exec(line)?.[1];
31
- return key ? [key] : [];
32
- });
33
- };
34
- const readToml = (file) => fs.existsSync(file) ? fs.readFileSync(file, "utf8") : "";
35
- /** Secrets of the Fly app plus its toml's `[env]` keys; values are never read. */
36
- const flyEnv = ({ root, shell }) => ({
37
- listNames: async ({ unit, options }) => {
38
- const { app, config } = FlyTarget.parse(options);
39
- const args = [
40
- "secrets",
41
- "list",
42
- "-a",
43
- app,
44
- "--json"
45
- ];
46
- const result = await shell.capture("flyctl", args);
47
- if (result.status !== 0) {
48
- const reason = firstLine(result.stderr) ?? `exit ${result.status}`;
49
- throw new Error(`flyctl secrets list -a ${app}: ${reason}`);
50
- }
51
- const listed = parseJson({
52
- text: jsonArrayIn(result.stdout),
53
- schema: FlySecrets
54
- });
55
- if (!listed.success) throw new Error(`flyctl secrets list -a ${app}: no secrets list in its output`);
56
- const secrets = listed.data.map((secret) => "name" in secret ? secret.name : secret.Name);
57
- const toml = tomlEnvKeys(readToml(path.join(root, unit.dir, config)));
58
- return new Set([...secrets, ...toml].filter(isEnvVarName));
59
- },
60
- setCommand: ({ options, names }) => `flyctl secrets set --stage -a ${FlyTarget.parse(options).app} ${names.map((name) => `${name}=...`).join(" ")}`
61
- });
62
- const flyServerHosting = () => defineServerHosting({
63
- name: "fly",
64
- settings: FlyOptions,
65
- env: flyEnv,
66
- typicalMinutes: 13,
67
- describe: ({ options }) => `${options.app} (Fly)`,
68
- detect: (folder) => {
69
- const tomls = folder.files.filter((file) => /^fly(-[\w]+)?\.toml$/.test(file)).sort();
70
- if (tomls.length === 0) return folder.has("Dockerfile") ? {
71
- certainty: "possible",
72
- reason: "Dockerfile",
73
- options: {}
74
- } : null;
75
- const appOf = (file) => /^app\s*=\s*"([^"]+)"/m.exec(folder.read(file) ?? "")?.[1];
76
- const options = ["fly-preview.toml", "fly-production.toml"].every((file) => tomls.includes(file)) ? {
77
- app: {
78
- preview: appOf("fly-preview.toml"),
79
- production: appOf("fly-production.toml")
80
- },
81
- config: {
82
- preview: "fly-preview.toml",
83
- production: "fly-production.toml"
84
- }
85
- } : {
86
- app: appOf(tomls[0] ?? "fly.toml"),
87
- ...tomls[0] === "fly.toml" ? {} : { config: tomls[0] }
88
- };
89
- return {
90
- certainty: "found",
91
- reason: tomls.join(", "),
92
- options
93
- };
94
- },
95
- questions: (folder, found, repository) => found.app === void 0 ? [{
96
- key: "app",
97
- message: "Fly app?",
98
- initial: `${repository}-${folder.name}`
99
- }] : [],
100
- requirements: () => [{
101
- label: "flyctl",
102
- check: {
103
- command: "flyctl",
104
- args: ["auth", "whoami"]
105
- },
106
- fix: {
107
- command: "flyctl",
108
- args: ["auth", "login"]
109
- },
110
- install: {
111
- command: {
112
- command: "sh",
113
- args: ["-c", "curl -fsSL https://fly.io/install.sh | sh"]
114
- },
115
- path: "$HOME/.fly/bin"
116
- },
117
- secrets: ["FLY_API_TOKEN"]
118
- }],
119
- jobs: ({ unit, tag, options }) => [{
120
- label: `deploy ${tag} to ${options.app} (Fly)`,
121
- local: [{
122
- command: "flyctl",
123
- args: [
124
- "deploy",
125
- "--remote-only",
126
- "--config",
127
- path.posix.join(unit.dir, options.config),
128
- "--dockerfile",
129
- path.posix.join(unit.dir, options.dockerfile)
130
- ],
131
- secrets: options.buildSecrets.map((name) => ({
132
- flag: "--build-secret",
133
- name
134
- }))
135
- }],
136
- ci: { ref: tag },
137
- record: true
138
- }]
139
- });
140
- //#endregion
141
- //#region src/catalog.ts
142
- /** What a shiplane.yml names from this plugin: `serverHosting: fly`. */
143
- const catalog = [adapterEntry({
144
- name: "fly",
145
- port: "serverHosting",
146
- description: "Deploys each app to Fly.io, through flyctl",
147
- options: z$1.object({}),
148
- make: () => flyServerHosting()
149
- })];
150
- //#endregion
151
- export { catalog, flyServerHosting };
152
-
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};
153
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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":";;;;;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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AClC,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;;;;ACrJJ,MAAa,UAAmC,CAC9C,aAAa;CACX,MAAM;CACN,MAAM;CACN,aAAa;CACb,SAASA,IAAE,OAAO,EAAE,CAAC;CACrB,YAAY,kBAAkB;CAC/B,CAAC,CACH"}
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,CAC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QAASA,EAAE,OAAO,EAAE,CAAC,CACrB,SAAY,kBAAkB,CAC/B,CAAC,CACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shiplane/fly",
3
- "version": "0.6.0-nightly.7",
3
+ "version": "0.6.0-nightly.8",
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-nightly.7"
41
+ "shiplane": "0.6.0-nightly.8"
42
42
  },
43
43
  "peerDependencies": {
44
- "shiplane": "0.6.0-nightly.7"
44
+ "shiplane": "0.6.0-nightly.8"
45
45
  },
46
46
  "shiplane": {
47
47
  "adapters": [