@shiplane/fly 0.0.0-stage → 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Arnaud Zheng
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,100 @@
1
- # Temporary Holding Version
1
+ # 🔌 @shiplane/fly
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Ships a backend to Fly.io: fills [shiplane](../shiplane/README.md)'s **server hosting** port with
4
+ `flyctl deploy`. Any app with a Dockerfile works.
5
+
6
+ ```mermaid
7
+ flowchart LR
8
+ CFG["shiplane.config.ts"] --> MOD["backendService"]
9
+ MOD --> FLY["flyServerHosting()"]
10
+ FLY --> CMD["flyctl deploy --remote-only"]
11
+ CMD --> HOST["Fly.io app per environment"]
12
+ ```
13
+
14
+ ## Install
15
+
16
+ ```sh
17
+ pnpm add -D shiplane @shiplane/fly
18
+ ```
19
+
20
+ ## Configure
21
+
22
+ Give the adapter to `backendService`. From
23
+ [`examples/shiplane.config.ts`](./examples/shiplane.config.ts):
24
+
25
+ ```ts
26
+ import { changesetsVersioning } from "@shiplane/changesets";
27
+ import { flyServerHosting } from "@shiplane/fly";
28
+ import { gitSourceControl } from "@shiplane/git";
29
+ import { gitHubActionsCiPipeline, gitHubCodeHost } from "@shiplane/github";
30
+ import { backendService, defineRelease, releaseFlow } from "shiplane";
31
+
32
+ export default defineRelease({
33
+ flow: releaseFlow({
34
+ sourceControl: gitSourceControl(),
35
+ codeHost: gitHubCodeHost(),
36
+ ciPipeline: gitHubActionsCiPipeline(),
37
+ versioning: changesetsVersioning(),
38
+ }),
39
+ modules: [backendService({ serverHosting: flyServerHosting() })],
40
+ });
41
+ ```
42
+
43
+ ## Unit file keys
44
+
45
+ In the app's `shiplane.unit.yml`, next to `module: backend-service`. A key marked per environment
46
+ also takes a `preview:` / `production:` map.
47
+
48
+ | Key | Default | Means |
49
+ | -------------- | ------------ | ------------------------------------------------------------------------ |
50
+ | `app` | required | The Fly app, per environment |
51
+ | `config` | `fly.toml` | Its fly.toml, relative to the unit's folder, per environment |
52
+ | `dockerfile` | `Dockerfile` | Relative to the unit's folder; the image builds from the repository root |
53
+ | `url` | | Where it answers, for other units to read, per environment |
54
+ | `buildSecrets` | `[]` | Variables its image build reads as secrets, passed by name when set |
55
+
56
+ Source: `FlyOptions` in `src/fly-server-hosting.adapter.ts`. `shiplane docs fly` prints the same.
57
+
58
+ ## Example
59
+
60
+ From [`examples/apps/api/shiplane.unit.yml`](./examples/apps/api/shiplane.unit.yml):
61
+
62
+ ```yaml
63
+ module: backend-service
64
+ app:
65
+ preview: acme-api-preview
66
+ production: acme-api
67
+ config:
68
+ preview: fly-preview.toml
69
+ production: fly-production.toml
70
+ url:
71
+ preview: https://api-preview.acme.dev
72
+ production: https://api.acme.dev
73
+ ```
74
+
75
+ `pnpm shiplane plan` in that repository prints what a ship to preview would run:
76
+
77
+ ```text
78
+ Plan · preview · nothing runs
79
+ Order 1 api · Latest
80
+
81
+ api@1.0.0 → acme-api-preview (Fly) (not tagged yet: release first)
82
+ this machine
83
+ flyctl deploy --remote-only --config apps/api/fly-preview.toml --dockerfile apps/api/Dockerfile
84
+ then record api@1.0.0 on preview in GitHub Deployments
85
+ GitHub Actions
86
+ gh workflow run ship.yml --ref api@1.0.0 -f units=api -f environment=preview
87
+ ```
88
+
89
+ The deploy waits until Fly rolled it out, then records it. `init` offers this adapter for a folder
90
+ with a `fly.toml` (or `fly-preview.toml` and `fly-production.toml`), and as a possibility for a
91
+ folder with only a Dockerfile.
92
+
93
+ ## Tools and sign-ins
94
+
95
+ | Tool | Checked with | Fixed with | In CI |
96
+ | -------- | -------------------- | ------------------- | --------------- |
97
+ | `flyctl` | `flyctl auth whoami` | `flyctl auth login` | `FLY_API_TOKEN` |
98
+
99
+ Source: `requirements` in `src/fly-server-hosting.adapter.ts`. `pnpm shiplane doctor` runs each
100
+ check and offers the fix.
@@ -0,0 +1,9 @@
1
+ import { DeliveryAdapter, ServerHostingPort } from "shiplane/plugin";
2
+
3
+ //#region src/fly-server-hosting.adapter.d.ts
4
+ /** Any Dockerfile on Fly.io: `flyctl deploy`, from this machine or the ship workflow on CI. */
5
+ type FlyServerHostingAdapter = DeliveryAdapter<ServerHostingPort>;
6
+ declare const flyServerHosting: () => FlyServerHostingAdapter;
7
+ //#endregion
8
+ export { type FlyServerHostingAdapter, flyServerHosting };
9
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,83 @@
1
+ import path from "node:path";
2
+ import { defineServerHosting, perEnv, z } from "shiplane/plugin";
3
+ //#region src/fly-server-hosting.adapter.ts
4
+ const FlyOptions = z.object({
5
+ app: perEnv(z.string()).describe("The Fly app, per environment"),
6
+ config: perEnv(z.string()).default("fly.toml").describe("Its fly.toml, relative to the unit's folder"),
7
+ dockerfile: z.string().default("Dockerfile").describe("Relative to the unit's folder; the image builds from the repository root"),
8
+ url: perEnv(z.string()).optional().describe("Where it answers, for other units to read"),
9
+ buildSecrets: z.array(z.string()).default([]).describe("Variables its image build reads as secrets, passed by name when set")
10
+ });
11
+ const flyServerHosting = () => defineServerHosting({
12
+ name: "fly",
13
+ settings: FlyOptions,
14
+ typicalMinutes: 13,
15
+ describe: ({ options }) => `${options.app} (Fly)`,
16
+ detect: (folder) => {
17
+ const tomls = folder.files.filter((file) => /^fly(-[\w]+)?\.toml$/.test(file)).sort();
18
+ if (tomls.length === 0) return folder.has("Dockerfile") ? {
19
+ certainty: "possible",
20
+ reason: "Dockerfile",
21
+ options: {}
22
+ } : null;
23
+ const appOf = (file) => /^app\s*=\s*"([^"]+)"/m.exec(folder.read(file) ?? "")?.[1];
24
+ const options = ["fly-preview.toml", "fly-production.toml"].every((file) => tomls.includes(file)) ? {
25
+ app: {
26
+ preview: appOf("fly-preview.toml"),
27
+ production: appOf("fly-production.toml")
28
+ },
29
+ config: {
30
+ preview: "fly-preview.toml",
31
+ production: "fly-production.toml"
32
+ }
33
+ } : {
34
+ app: appOf(tomls[0] ?? "fly.toml"),
35
+ ...tomls[0] === "fly.toml" ? {} : { config: tomls[0] }
36
+ };
37
+ return {
38
+ certainty: "found",
39
+ reason: tomls.join(", "),
40
+ options
41
+ };
42
+ },
43
+ questions: (folder, found, repository) => found.app === void 0 ? [{
44
+ key: "app",
45
+ message: "Fly app?",
46
+ initial: `${repository}-${folder.name}`
47
+ }] : [],
48
+ requirements: () => [{
49
+ label: "flyctl",
50
+ check: {
51
+ command: "flyctl",
52
+ args: ["auth", "whoami"]
53
+ },
54
+ fix: {
55
+ command: "flyctl",
56
+ args: ["auth", "login"]
57
+ }
58
+ }],
59
+ jobs: ({ unit, tag, options }) => [{
60
+ label: `deploy ${tag} to ${options.app} (Fly)`,
61
+ local: [{
62
+ command: "flyctl",
63
+ args: [
64
+ "deploy",
65
+ "--remote-only",
66
+ "--config",
67
+ path.posix.join(unit.dir, options.config),
68
+ "--dockerfile",
69
+ path.posix.join(unit.dir, options.dockerfile)
70
+ ],
71
+ secrets: options.buildSecrets.map((name) => ({
72
+ flag: "--build-secret",
73
+ name
74
+ }))
75
+ }],
76
+ ci: { ref: tag },
77
+ record: true
78
+ }]
79
+ });
80
+ //#endregion
81
+ export { flyServerHosting };
82
+
83
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/fly-server-hosting.adapter.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { DeliveryAdapter, ServerHostingPort } from \"shiplane/plugin\";\nimport { defineServerHosting, perEnv, z } 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/** 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 // 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 },\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":";;;AAIA,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,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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"}
package/package.json CHANGED
@@ -1,6 +1,53 @@
1
1
  {
2
2
  "name": "@shiplane/fly",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "Server hosting for shiplane: any Dockerfile on Fly.io.",
5
+ "homepage": "https://github.com/arnaud-zg/packages/tree/main/packages/shiplane-fly#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/arnaud-zg/packages/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/arnaud-zg/packages.git",
12
+ "directory": "packages/shiplane-fly"
13
+ },
14
+ "license": "MIT",
15
+ "author": "Arnaud Zheng <arnaud.zg@gmail.com>",
16
+ "sideEffects": false,
17
+ "type": "module",
18
+ "exports": {
19
+ ".": "./dist/index.js",
20
+ "./package.json": "./package.json"
21
+ },
22
+ "main": "./dist/index.js",
23
+ "module": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "devDependencies": {
29
+ "@arnaud-zg/configs": "0.3.0",
30
+ "@types/node": "^22.0.0",
31
+ "eslint": "^9.39.4",
32
+ "prettier": "^3.8.3",
33
+ "typescript": "6.0.3",
34
+ "vitest": "^4.1.11",
35
+ "shiplane": "0.2.0"
36
+ },
37
+ "peerDependencies": {
38
+ "shiplane": "0.2.0"
39
+ },
40
+ "shiplane": {
41
+ "adapters": [
42
+ "flyServerHosting"
43
+ ]
44
+ },
45
+ "scripts": {
46
+ "build": "tsdown",
47
+ "clean": "git clean -xdf .cache .turbo dist node_modules",
48
+ "format": "prettier --write . --cache --cache-location .cache/.prettiercache",
49
+ "lint": "eslint --cache --cache-location .cache/.eslintcache",
50
+ "test": "vitest run",
51
+ "typecheck": "tsc -p tsconfig.typecheck.json"
52
+ }
6
53
  }