@shiplane/fly 0.5.1 → 0.6.0-ci-setup-action.d7598bc
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 +2 -2
- package/dist/index.js +22 -5
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -73,7 +73,7 @@ url:
|
|
|
73
73
|
production: https://api.acme.dev
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
`pnpm shiplane
|
|
76
|
+
`pnpm shiplane ship --dry-run` in that repository prints what a ship to preview would run:
|
|
77
77
|
|
|
78
78
|
```text
|
|
79
79
|
Plan · preview · nothing runs
|
|
@@ -87,7 +87,7 @@ url:
|
|
|
87
87
|
gh workflow run ship.yml --ref api@1.0.0 -f units=api -f environment=preview
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
The deploy waits until Fly rolled it out, then records it. `
|
|
90
|
+
The deploy waits until Fly rolled it out, then records it. `setup` offers this adapter for a folder
|
|
91
91
|
with a `fly.toml` (or `fly-preview.toml` and `fly-production.toml`), and as a possibility for a
|
|
92
92
|
folder with only a Dockerfile.
|
|
93
93
|
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { defineServerHosting, isEnvVarName, perEnv, z } from "shiplane/plugin";
|
|
3
|
+
import { defineServerHosting, firstLine, isEnvVarName, parseJson, perEnv, z } from "shiplane/plugin";
|
|
4
4
|
//#region src/fly-server-hosting.adapter.ts
|
|
5
5
|
const FlyOptions = z.object({
|
|
6
6
|
app: perEnv(z.string()).describe("The Fly app, per environment"),
|
|
@@ -14,6 +14,10 @@ const FlyTarget = z.object({
|
|
|
14
14
|
config: z.string().default("fly.toml")
|
|
15
15
|
});
|
|
16
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
|
+
};
|
|
17
21
|
/** Keys of a fly.toml's `[env]` block: variables Fly sets next to its secrets. */
|
|
18
22
|
const tomlEnvKeys = (toml) => {
|
|
19
23
|
const lines = toml.split("\n");
|
|
@@ -40,10 +44,15 @@ const flyEnv = ({ root, shell }) => ({
|
|
|
40
44
|
];
|
|
41
45
|
const result = await shell.capture("flyctl", args);
|
|
42
46
|
if (result.status !== 0) {
|
|
43
|
-
const reason = result.stderr
|
|
44
|
-
throw new Error(`flyctl secrets list -a ${app}: ${reason
|
|
47
|
+
const reason = firstLine(result.stderr) ?? `exit ${result.status}`;
|
|
48
|
+
throw new Error(`flyctl secrets list -a ${app}: ${reason}`);
|
|
45
49
|
}
|
|
46
|
-
const
|
|
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);
|
|
47
56
|
const toml = tomlEnvKeys(readToml(path.join(root, unit.dir, config)));
|
|
48
57
|
return new Set([...secrets, ...toml].filter(isEnvVarName));
|
|
49
58
|
},
|
|
@@ -96,7 +105,15 @@ const flyServerHosting = () => defineServerHosting({
|
|
|
96
105
|
fix: {
|
|
97
106
|
command: "flyctl",
|
|
98
107
|
args: ["auth", "login"]
|
|
99
|
-
}
|
|
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"]
|
|
100
117
|
}],
|
|
101
118
|
jobs: ({ unit, tag, options }) => [{
|
|
102
119
|
label: `deploy ${tag} to ${options.app} (Fly)`,
|
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 {
|
|
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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AAK,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shiplane/fly",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-ci-setup-action.d7598bc",
|
|
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.
|
|
41
|
+
"shiplane": "0.6.0-ci-setup-action.d7598bc"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"shiplane": "0.
|
|
44
|
+
"shiplane": "0.6.0-ci-setup-action.d7598bc"
|
|
45
45
|
},
|
|
46
46
|
"shiplane": {
|
|
47
47
|
"adapters": [
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"format": "prettier --write . --cache --cache-location .cache/.prettiercache",
|
|
55
55
|
"lint": "eslint --cache --cache-location .cache/.eslintcache",
|
|
56
56
|
"test": "vitest run",
|
|
57
|
+
"test:mutate": "stryker run ../../stryker.config.mjs",
|
|
57
58
|
"typecheck": "tsc -p tsconfig.typecheck.json"
|
|
58
59
|
}
|
|
59
60
|
}
|