@cdwr/fly-node 0.2.3 → 0.3.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/CHANGELOG.md +59 -0
- package/LICENSE +21 -0
- package/README.md +197 -40
- package/api.cjs +517 -0
- package/api.js +483 -0
- package/index.cjs +1140 -225
- package/index.js +1131 -224
- package/package.json +12 -2
- package/src/api.d.ts +15 -0
- package/src/index.d.ts +2 -1
- package/src/lib/fly-api.class.d.ts +193 -0
- package/src/lib/fly.class.d.ts +214 -23
- package/src/lib/mocks.d.ts +22 -7
- package/src/lib/schemas/apps-create.schema.d.ts +3 -25
- package/src/lib/schemas/apps-list.schema.d.ts +17 -17
- package/src/lib/schemas/build-response.schema.d.ts +11 -0
- package/src/lib/schemas/certificate.schema.d.ts +392 -0
- package/src/lib/schemas/machine.schema.d.ts +44 -0
- package/src/lib/schemas/postgres-list.d.ts +17 -14
- package/src/lib/schemas/secrets-list-with-app.schema.d.ts +0 -4
- package/src/lib/schemas/secrets-list.schema.d.ts +0 -7
- package/src/lib/schemas/status-extended.schema.d.ts +126 -24
- package/src/lib/schemas/status.schema.d.ts +234 -42
- package/src/lib/schemas/version.schema.d.ts +45 -0
- package/src/lib/types.d.ts +158 -20
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cdwr/fly-node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "The flyctl node wrapper for programmatic deployments to fly.io.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "https://github.com/codeware-sthlm/
|
|
7
|
+
"url": "https://github.com/codeware-sthlm/cdwr.git",
|
|
8
8
|
"directory": "packages/fly-node"
|
|
9
9
|
},
|
|
10
10
|
"author": {
|
|
@@ -27,11 +27,21 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"zod": "^3.23.8"
|
|
29
29
|
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"dotenv": "^16.4.7",
|
|
32
|
+
"dotenv-expand": "^11.0.7",
|
|
33
|
+
"is-ci": "^3.0.1"
|
|
34
|
+
},
|
|
30
35
|
"exports": {
|
|
31
36
|
".": {
|
|
32
37
|
"types": "./src/index.d.ts",
|
|
33
38
|
"import": "./index.js",
|
|
34
39
|
"require": "./index.cjs"
|
|
40
|
+
},
|
|
41
|
+
"./api": {
|
|
42
|
+
"types": "./src/api.d.ts",
|
|
43
|
+
"import": "./api.js",
|
|
44
|
+
"require": "./api.cjs"
|
|
35
45
|
}
|
|
36
46
|
},
|
|
37
47
|
"types": "./src/index.d.ts",
|
package/src/api.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fly over its GraphQL API, without the CLI.
|
|
3
|
+
*
|
|
4
|
+
* A separate entry point because the two halves of this package have different
|
|
5
|
+
* runtime requirements: the `Fly` class shells out to `flyctl` and reaches a
|
|
6
|
+
* native pty module through `@codeware/shared/util/misc`, neither of which
|
|
7
|
+
* exists inside an application image. Importing the root barrel to reach
|
|
8
|
+
* `FlyApi` would pull all of that into the bundle.
|
|
9
|
+
*
|
|
10
|
+
* Nothing here touches the filesystem or spawns a process, so it runs anywhere
|
|
11
|
+
* `fetch` does.
|
|
12
|
+
*/
|
|
13
|
+
export { FlyApi, FlyApiError, type FlyApiConfig } from './lib/fly-api.class';
|
|
14
|
+
export { type Certificate, CertificateApiResponseSchema, CertificateListApiResponseSchema, type DnsInstructions, DnsInstructionsSchema, type HostnameCheck, HostnameCheckApiResponseSchema } from './lib/schemas/certificate.schema';
|
|
15
|
+
export { type Machine, MachineApiResponseSchema, MachineListApiResponseSchema } from './lib/schemas/machine.schema';
|
package/src/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
export * from './api';
|
|
1
2
|
export * from './lib/fly.class';
|
|
2
|
-
export type { Config, DeployAppOptions, DeployResponse } from './lib/types';
|
|
3
|
+
export type { BuildResponse, Config, DeployAppOptions, DeployResponse, MachineOperationOptions, SaveConfigOptions, StatusResponse } from './lib/types';
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { type Certificate, type DnsInstructions, type HostnameCheck } from './schemas/certificate.schema';
|
|
2
|
+
import { type Machine } from './schemas/machine.schema';
|
|
3
|
+
export type FlyApiConfig = {
|
|
4
|
+
/** Fly API token. An org-scoped token can manage certificates for its apps */
|
|
5
|
+
token: string;
|
|
6
|
+
/** Override the endpoint, for tests or a private Fly instance */
|
|
7
|
+
apiUrl?: string;
|
|
8
|
+
/** Override the machines endpoint, for tests or a private Fly instance */
|
|
9
|
+
machinesUrl?: string;
|
|
10
|
+
/** Called with a one-line description of every request; defaults to silence */
|
|
11
|
+
log?: (message: string) => void;
|
|
12
|
+
};
|
|
13
|
+
/** A GraphQL error as Fly returns it — status 200 with an `errors` array */
|
|
14
|
+
type GraphQLError = {
|
|
15
|
+
message: string;
|
|
16
|
+
extensions?: {
|
|
17
|
+
code?: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* A rejection from Fly, carrying the codes it sent.
|
|
22
|
+
*
|
|
23
|
+
* The codes matter: `NOT_FOUND` for a hostname with no certificate is an
|
|
24
|
+
* answer, while everything else is a fault. Callers should not have to match
|
|
25
|
+
* on message text to tell them apart.
|
|
26
|
+
*/
|
|
27
|
+
export declare class FlyApiError extends Error {
|
|
28
|
+
readonly errors: Array<GraphQLError>;
|
|
29
|
+
constructor(message: string, errors: Array<GraphQLError>);
|
|
30
|
+
/** Whether every error is Fly saying the thing simply does not exist */
|
|
31
|
+
get isNotFound(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Whether every error is Fly refusing a hostname that already has a
|
|
34
|
+
* certificate on the app.
|
|
35
|
+
*
|
|
36
|
+
* No `extensions.code` comes with this one — Fly's own dashboard and
|
|
37
|
+
* `flyctl` hit the same message, and both work around it the same way this
|
|
38
|
+
* class does, by re-reading rather than retrying the mutation.
|
|
39
|
+
*/
|
|
40
|
+
get isAlreadyExists(): boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Fly over its HTTP APIs, with no `flyctl` in sight.
|
|
44
|
+
*
|
|
45
|
+
* The `Fly` class in this package drives the CLI, which is the right tool in
|
|
46
|
+
* CI: it can build and deploy, and a runner has the binary. It cannot run
|
|
47
|
+
* inside an application server — there is no binary in the image, and the
|
|
48
|
+
* interactive paths need a pty.
|
|
49
|
+
*
|
|
50
|
+
* This class exists for the operations an application needs to perform on
|
|
51
|
+
* itself at runtime. It is deliberately a small subset rather than a second
|
|
52
|
+
* implementation of the whole CLI: certificates, because a custom domain has to
|
|
53
|
+
* be requested, checked and shown to a customer while they wait, and machine
|
|
54
|
+
* restarts, because a setting read at boot needs a boot to take effect.
|
|
55
|
+
*
|
|
56
|
+
* Fly splits those across two APIs and so does this class — certificates over
|
|
57
|
+
* GraphQL, machines over the REST Machines API. One token authenticates both.
|
|
58
|
+
* The split is Fly's; it is not hidden here, because the two have different
|
|
59
|
+
* hosts and different failure shapes.
|
|
60
|
+
*
|
|
61
|
+
* Where this and the CLI can do the same thing the returned shapes agree, so a
|
|
62
|
+
* caller can move between them. Where they differ, the API gives *more*:
|
|
63
|
+
* issuance state and the DNS records to create come back as fields rather than
|
|
64
|
+
* as text a human was meant to read.
|
|
65
|
+
*/
|
|
66
|
+
export declare class FlyApi {
|
|
67
|
+
private readonly token;
|
|
68
|
+
private readonly apiUrl;
|
|
69
|
+
private readonly machinesUrl;
|
|
70
|
+
private readonly log;
|
|
71
|
+
constructor(config: FlyApiConfig);
|
|
72
|
+
/**
|
|
73
|
+
* Manage certificates for an app.
|
|
74
|
+
*
|
|
75
|
+
* Every method takes the app name explicitly: this client is used by a
|
|
76
|
+
* process acting on *other* apps — the cms managing a tenant's web app — so
|
|
77
|
+
* there is no ambient "current app" to default to.
|
|
78
|
+
*/
|
|
79
|
+
certs: {
|
|
80
|
+
/**
|
|
81
|
+
* Request a certificate for a hostname.
|
|
82
|
+
*
|
|
83
|
+
* Safe to call when one already exists: Fly's own mutation is not
|
|
84
|
+
* idempotent — a hostname it already has a certificate for on this app is
|
|
85
|
+
* a fault, not a no-op, so this re-reads the existing certificate itself
|
|
86
|
+
* rather than surfacing that as an error a caller has to know to expect.
|
|
87
|
+
*
|
|
88
|
+
* Requesting before DNS is in place is normal and expected — the
|
|
89
|
+
* certificate stays pending until the records resolve, and the returned
|
|
90
|
+
* validation fields are what you show the customer meanwhile.
|
|
91
|
+
*
|
|
92
|
+
* @param app - Fly app name the domain should serve from
|
|
93
|
+
* @param hostname - Domain without a scheme, e.g. `tours.example.com`
|
|
94
|
+
* @returns The certificate, plus what Fly resolves for that hostname now
|
|
95
|
+
*/
|
|
96
|
+
add: (app: string, hostname: string) => Promise<{
|
|
97
|
+
certificate: Certificate;
|
|
98
|
+
check: HostnameCheck | null;
|
|
99
|
+
}>;
|
|
100
|
+
/**
|
|
101
|
+
* Read one certificate, or `null` when the app has none for that hostname.
|
|
102
|
+
*
|
|
103
|
+
* This is the call behind a "check" button: it re-reads issuance state from
|
|
104
|
+
* Fly rather than trusting anything stored locally.
|
|
105
|
+
*
|
|
106
|
+
* Fly reports an absent certificate as a `NOT_FOUND` *error* rather than a
|
|
107
|
+
* null field, so that case is translated here — asking about a domain
|
|
108
|
+
* nobody has added yet is an ordinary question with an ordinary answer.
|
|
109
|
+
*/
|
|
110
|
+
get: (app: string, hostname: string) => Promise<Certificate | null>;
|
|
111
|
+
/**
|
|
112
|
+
* What Fly resolves for a hostname right now, and what it objects to.
|
|
113
|
+
*
|
|
114
|
+
* A mutation on Fly's side despite reading rather than writing anything —
|
|
115
|
+
* `AppCertificate.check` is a plain boolean flag, and `HostnameCheck` is
|
|
116
|
+
* only ever returned by `addCertificate` and this, `checkCertificate`.
|
|
117
|
+
* Separate from `get` rather than folded into it: triggering a live dns
|
|
118
|
+
* resolution on every read would cost a caller that only wants issuance
|
|
119
|
+
* state. Pair the two when a person has just edited their records and
|
|
120
|
+
* wants to know whether it took.
|
|
121
|
+
*
|
|
122
|
+
* `errors` is the useful half — it is what Fly's own dashboard prints as
|
|
123
|
+
* "validation issues", already phrased for whoever owns the domain.
|
|
124
|
+
*
|
|
125
|
+
* @returns `null` when the app has no certificate for that hostname
|
|
126
|
+
*/
|
|
127
|
+
check: (app: string, hostname: string) => Promise<HostnameCheck | null>;
|
|
128
|
+
/** Every certificate on an app */
|
|
129
|
+
list: (app: string) => Promise<Array<Certificate>>;
|
|
130
|
+
/**
|
|
131
|
+
* Remove a certificate.
|
|
132
|
+
*
|
|
133
|
+
* The hostname keeps resolving until its DNS is changed — this only stops
|
|
134
|
+
* Fly serving TLS for it.
|
|
135
|
+
*/
|
|
136
|
+
remove: (app: string, hostname: string) => Promise<void>;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Operate an app's machines.
|
|
140
|
+
*
|
|
141
|
+
* Over Fly's REST Machines API rather than GraphQL, which has no current
|
|
142
|
+
* equivalent — the GraphQL mutations date from the Nomad platform and no
|
|
143
|
+
* longer apply.
|
|
144
|
+
*/
|
|
145
|
+
machines: {
|
|
146
|
+
/** Every machine on an app */
|
|
147
|
+
list: (app: string) => Promise<Array<Machine>>;
|
|
148
|
+
/**
|
|
149
|
+
* Restart an app's machines.
|
|
150
|
+
*
|
|
151
|
+
* One at a time on purpose: a settings change that only takes effect at
|
|
152
|
+
* boot should not cost the app its availability to apply. Restarting them
|
|
153
|
+
* together would drop every machine at once, while sequentially leaves the
|
|
154
|
+
* others serving. The trade is that a large app takes longer.
|
|
155
|
+
*
|
|
156
|
+
* A machine that fails to restart stops the run rather than being skipped —
|
|
157
|
+
* a half-restarted app is running two configurations at the same time, and
|
|
158
|
+
* silently returning "some of them" invites calling that done.
|
|
159
|
+
*
|
|
160
|
+
* @param app - Fly app name
|
|
161
|
+
* @param machineId - Restart only this machine, instead of all of them
|
|
162
|
+
* @returns Ids of the machines that were restarted, in the order they were
|
|
163
|
+
*/
|
|
164
|
+
restart: (app: string, machineId?: string) => Promise<Array<string>>;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* The DNS records a customer must create for a certificate to validate.
|
|
168
|
+
*
|
|
169
|
+
* Pulled out of the certificate rather than fetched, so a caller that
|
|
170
|
+
* already has one does not pay for a second round trip.
|
|
171
|
+
*/
|
|
172
|
+
static dnsInstructions(certificate: Certificate): DnsInstructions;
|
|
173
|
+
/**
|
|
174
|
+
* @private
|
|
175
|
+
* One GraphQL round trip.
|
|
176
|
+
*
|
|
177
|
+
* Fly answers a failed query with HTTP 200 and an `errors` array, so a
|
|
178
|
+
* response is only successful when both are checked — trusting the status
|
|
179
|
+
* alone would turn "permission denied" into a parse error further down.
|
|
180
|
+
*/
|
|
181
|
+
private request;
|
|
182
|
+
/**
|
|
183
|
+
* @private
|
|
184
|
+
* One call to the Machines REST API.
|
|
185
|
+
*
|
|
186
|
+
* Unlike GraphQL this one reports failure through the status code, and puts
|
|
187
|
+
* its reason in an `error` field. Worth reading rather than reporting the
|
|
188
|
+
* status alone: "machine not found" and "unauthorized" are different problems
|
|
189
|
+
* with different fixes.
|
|
190
|
+
*/
|
|
191
|
+
private machinesRequest;
|
|
192
|
+
}
|
|
193
|
+
export {};
|
package/src/lib/fly.class.d.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import { SpawnOptions, SpawnPtyOptions } from '@codeware/
|
|
2
|
-
import type { AppOrConfig, Config, CreateAppOptions, DeployAppOptions, DeployResponse,
|
|
3
|
-
export type ExecFlyOptions = SpawnOptions & SpawnPtyOptions
|
|
1
|
+
import { SpawnOptions, SpawnPtyOptions } from '@codeware/shared/util/misc';
|
|
2
|
+
import type { AppOrConfig, BuildResponse, Config, CreateAppOptions, CreateAppResponse, DeployAppOptions, DeployResponse, ListAppResponse, ListCertForAllResponse, ListCertForAppResponse, ListSecretForAllResponse, ListSecretForAppResponse, SaveConfigOptions, SetAppSecretsOptions, ShowConfigOptions, ShowConfigResponse, StatusExtendedResponse, StatusResponse, UnsetAppSecretsOptions, VersionResponse } from './types';
|
|
3
|
+
export type ExecFlyOptions = SpawnOptions & SpawnPtyOptions & {
|
|
4
|
+
/**
|
|
5
|
+
* How to assemble the returned output string from the spawned process.
|
|
6
|
+
* - `'stdout'` (default): return stdout only — correct for JSON and most text commands
|
|
7
|
+
* - `'stderr'`: return stderr only
|
|
8
|
+
* - `'combined'`: return stdout + stderr — use when the data of interest
|
|
9
|
+
* may appear in either stream (e.g. `fly deploy --build-only`)
|
|
10
|
+
*/
|
|
11
|
+
streamStrategy?: 'stdout' | 'stderr' | 'combined';
|
|
12
|
+
};
|
|
4
13
|
/**
|
|
5
14
|
* Manages deployments to Fly.io using the `flyctl` CLI tool.
|
|
6
15
|
*/
|
|
7
16
|
export declare class Fly {
|
|
8
17
|
/** Use underscore to avoid conflict with public `config` property */
|
|
9
18
|
private _config;
|
|
10
|
-
/**
|
|
11
|
-
* Whether a user is authenticated via local login.
|
|
12
|
-
* In this case a token is not needed, though it can still have been provided.
|
|
13
|
-
*/
|
|
14
|
-
private authByLogin;
|
|
15
19
|
private initialized;
|
|
16
20
|
private logger;
|
|
17
21
|
/**
|
|
@@ -45,6 +49,13 @@ export declare class Fly {
|
|
|
45
49
|
* @returns `true` if the Fly CLI tool is installed, `false` otherwise
|
|
46
50
|
*/
|
|
47
51
|
isInstalled: () => Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* Get version information about the installed Fly CLI
|
|
54
|
+
*
|
|
55
|
+
* @returns The installed Fly CLI version information
|
|
56
|
+
* @throws An error if the version cannot be retrieved
|
|
57
|
+
*/
|
|
58
|
+
version: () => Promise<VersionResponse>;
|
|
48
59
|
};
|
|
49
60
|
/**
|
|
50
61
|
* Manage apps
|
|
@@ -57,22 +68,21 @@ export declare class Fly {
|
|
|
57
68
|
* @returns The name of the created application
|
|
58
69
|
* @throws An error if the application cannot be created
|
|
59
70
|
*/
|
|
60
|
-
create: (options?: CreateAppOptions) => Promise<
|
|
71
|
+
create: (options?: CreateAppOptions) => Promise<CreateAppResponse>;
|
|
61
72
|
/**
|
|
62
73
|
* Destroy an application and make sure it gets detached from any Postgres clusters
|
|
63
74
|
*
|
|
64
75
|
* @param app - The name of the app to destroy
|
|
65
|
-
* @param options - Options for destroying an application
|
|
66
76
|
* @throws An error if the app cannot be destroyed
|
|
67
77
|
*/
|
|
68
|
-
destroy: (app: string
|
|
78
|
+
destroy: (app: string) => Promise<void>;
|
|
69
79
|
/**
|
|
70
80
|
* List all applications
|
|
71
81
|
*
|
|
72
82
|
* @returns A list of applications
|
|
73
83
|
* @throws An error if listing applications fails
|
|
74
84
|
*/
|
|
75
|
-
list: () => Promise<
|
|
85
|
+
list: () => Promise<ListAppResponse>;
|
|
76
86
|
};
|
|
77
87
|
/**
|
|
78
88
|
* Manage certificates
|
|
@@ -93,7 +103,7 @@ export declare class Fly {
|
|
|
93
103
|
* @returns A list of certificates
|
|
94
104
|
* @throws An error if listing certificates fails
|
|
95
105
|
*/
|
|
96
|
-
list: <T extends AppOrConfig | "all">(options?: T) => Promise<T extends "all" ?
|
|
106
|
+
list: <T extends AppOrConfig | "all">(options?: T) => Promise<T extends "all" ? ListCertForAllResponse : ListCertForAppResponse>;
|
|
97
107
|
/**
|
|
98
108
|
* Remove a certificate for a domain from an application
|
|
99
109
|
*
|
|
@@ -107,6 +117,16 @@ export declare class Fly {
|
|
|
107
117
|
* Manage an app's configuration
|
|
108
118
|
*/
|
|
109
119
|
config: {
|
|
120
|
+
/**
|
|
121
|
+
* Save an application's remote configuration locally.
|
|
122
|
+
*
|
|
123
|
+
* TOML by default; name the path `.json` or `.yaml`/`.yml` for either of
|
|
124
|
+
* those instead.
|
|
125
|
+
*
|
|
126
|
+
* @param options - Options for saving an application's configuration
|
|
127
|
+
* @throws An error if the configuration cannot be saved
|
|
128
|
+
*/
|
|
129
|
+
save: (options: SaveConfigOptions) => Promise<void>;
|
|
110
130
|
/**
|
|
111
131
|
* Show an application's configuration.
|
|
112
132
|
*
|
|
@@ -117,7 +137,12 @@ export declare class Fly {
|
|
|
117
137
|
show: (options?: ShowConfigOptions) => Promise<ShowConfigResponse>;
|
|
118
138
|
};
|
|
119
139
|
/**
|
|
120
|
-
* Deploy an application
|
|
140
|
+
* Deploy an application, or just build its Docker image without deploying when
|
|
141
|
+
* `buildOnly` is set (equivalent to using `build(options)`).
|
|
142
|
+
*
|
|
143
|
+
* Pre-building is useful to ensure the image can be built successfully and exists
|
|
144
|
+
* before running a deploy that depends on it, and also to get the image reference for use in
|
|
145
|
+
* subsequent operations.
|
|
121
146
|
*
|
|
122
147
|
* A valid config file is required but the app doesn't have to exist,
|
|
123
148
|
* since it gets created if needed.
|
|
@@ -127,15 +152,80 @@ export declare class Fly {
|
|
|
127
152
|
* 2. Instance app name
|
|
128
153
|
* 3. App name from the provided config file
|
|
129
154
|
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* @
|
|
133
|
-
* @throws An error if the deployment fails
|
|
155
|
+
* @param options - Deployment or build options
|
|
156
|
+
* @returns Build or deploy response depending on `buildOnly` option
|
|
157
|
+
* @throws An error if the operation fails
|
|
134
158
|
*/
|
|
135
|
-
deploy: (options?:
|
|
159
|
+
deploy: <T extends DeployAppOptions>(options?: T) => Promise<T extends {
|
|
160
|
+
buildOnly: true;
|
|
161
|
+
} ? BuildResponse : DeployResponse>;
|
|
162
|
+
/**
|
|
163
|
+
* Manage machines
|
|
164
|
+
*/
|
|
165
|
+
machines: {
|
|
166
|
+
/**
|
|
167
|
+
* Start a machine
|
|
168
|
+
*
|
|
169
|
+
* @param app - The name of the application
|
|
170
|
+
* @param machineId - The machine ID to start
|
|
171
|
+
* @throws An error if the machine cannot be started
|
|
172
|
+
*/
|
|
173
|
+
start: (app: string, machineId: string) => Promise<void>;
|
|
174
|
+
/**
|
|
175
|
+
* Stop a machine
|
|
176
|
+
*
|
|
177
|
+
* @param app - The name of the application
|
|
178
|
+
* @param machineId - The machine ID to stop
|
|
179
|
+
* @throws An error if the machine cannot be stopped
|
|
180
|
+
*/
|
|
181
|
+
stop: (app: string, machineId: string) => Promise<void>;
|
|
182
|
+
/**
|
|
183
|
+
* Restart a machine by stopping then starting it
|
|
184
|
+
*
|
|
185
|
+
* @param app - The name of the application
|
|
186
|
+
* @param machineId - The machine ID to restart
|
|
187
|
+
* @throws An error if the machine cannot be restarted
|
|
188
|
+
*/
|
|
189
|
+
restart: (app: string, machineId: string) => Promise<void>;
|
|
190
|
+
/**
|
|
191
|
+
* Update a machine's per-machine configuration (env vars, etc.).
|
|
192
|
+
*
|
|
193
|
+
* Unlike `restart`, this creates a new machine version from the updated config
|
|
194
|
+
* and forces a cold start — it does NOT resume from a suspended memory snapshot.
|
|
195
|
+
*
|
|
196
|
+
* @param app - The name of the application
|
|
197
|
+
* @param machineId - The machine ID to update
|
|
198
|
+
* @param options - Fields to update; env values set to `''` clear that var
|
|
199
|
+
* @throws An error if the machine cannot be updated
|
|
200
|
+
*/
|
|
201
|
+
update: (app: string, machineId: string, options: {
|
|
202
|
+
env?: Record<string, string>;
|
|
203
|
+
}) => Promise<void>;
|
|
204
|
+
};
|
|
136
205
|
postgres: {
|
|
137
206
|
detach: (cluster: string, app: string) => Promise<void>;
|
|
138
207
|
};
|
|
208
|
+
/**
|
|
209
|
+
* Run commands inside a running machine
|
|
210
|
+
*/
|
|
211
|
+
ssh: {
|
|
212
|
+
/**
|
|
213
|
+
* Execute a command in a running machine and return its output.
|
|
214
|
+
*
|
|
215
|
+
* Requires a started machine - Fly cannot connect to a stopped or
|
|
216
|
+
* suspended one. Use `machines.start` first when the app may be idle.
|
|
217
|
+
*
|
|
218
|
+
* The output is returned to the caller and not logged unless CLI tracing
|
|
219
|
+
* is enabled, so it can be used to read values that are otherwise
|
|
220
|
+
* write-only, such as secrets injected at deploy time.
|
|
221
|
+
*
|
|
222
|
+
* @param app - The name of the application
|
|
223
|
+
* @param command - The command to run inside the machine
|
|
224
|
+
* @returns The command output
|
|
225
|
+
* @throws An error if there is no started machine or the command fails
|
|
226
|
+
*/
|
|
227
|
+
exec: (app: string, command: string) => Promise<string>;
|
|
228
|
+
};
|
|
139
229
|
/**
|
|
140
230
|
* Manage application secrets
|
|
141
231
|
*/
|
|
@@ -149,13 +239,26 @@ export declare class Fly {
|
|
|
149
239
|
*/
|
|
150
240
|
set: (secrets: Record<string, string>, options?: SetAppSecretsOptions) => Promise<void>;
|
|
151
241
|
/**
|
|
152
|
-
*
|
|
242
|
+
* Apply secrets that were staged with `set({ stage: true })`.
|
|
243
|
+
*
|
|
244
|
+
* Staging first and deploying afterwards lets a set of apps take a new
|
|
245
|
+
* value together, instead of each restarting as its own secret is written.
|
|
246
|
+
*
|
|
247
|
+
* Fly needs a started machine to update, so an app whose machines are all
|
|
248
|
+
* stopped or suspended has to be started before this will do anything.
|
|
249
|
+
*
|
|
250
|
+
* @param app - The name of the application
|
|
251
|
+
* @throws An error if the staged secrets cannot be deployed
|
|
252
|
+
*/
|
|
253
|
+
deploy: (app: string) => Promise<void>;
|
|
254
|
+
/**
|
|
255
|
+
* List secrets for an application or all secrets when options is 'all'
|
|
153
256
|
*
|
|
154
257
|
* @param options - List secrets for an application or all secrets
|
|
155
258
|
* @returns A list of secrets
|
|
156
259
|
* @throws An error if listing secrets fails
|
|
157
260
|
*/
|
|
158
|
-
list: <T extends AppOrConfig | "all">(options?: T) => Promise<T extends "all" ?
|
|
261
|
+
list: <T extends AppOrConfig | "all">(options?: T) => Promise<T extends "all" ? ListSecretForAllResponse : ListSecretForAppResponse>;
|
|
159
262
|
/**
|
|
160
263
|
* Unset secrets for an application
|
|
161
264
|
*
|
|
@@ -172,6 +275,19 @@ export declare class Fly {
|
|
|
172
275
|
* @returns The app status, or `null` if an app could not be found
|
|
173
276
|
*/
|
|
174
277
|
status: (options?: AppOrConfig) => Promise<StatusResponse | null>;
|
|
278
|
+
/**
|
|
279
|
+
* Build a Docker image for an application and push it to the Fly registry
|
|
280
|
+
* without deploying.
|
|
281
|
+
*
|
|
282
|
+
* The image reference is returned for use in a subsequent `deploy` that depends on it.
|
|
283
|
+
*
|
|
284
|
+
* Shorthand for `deploy({ ...options, buildOnly: true })`.
|
|
285
|
+
*
|
|
286
|
+
* @param options - Build options
|
|
287
|
+
* @returns The app name and image reference for use in a subsequent `deploy`
|
|
288
|
+
* @throws An error if the build fails or the image reference cannot be parsed
|
|
289
|
+
*/
|
|
290
|
+
build: (options?: Omit<DeployAppOptions, "buildOnly">) => Promise<BuildResponse>;
|
|
175
291
|
/**
|
|
176
292
|
* Get the extended details of an application
|
|
177
293
|
*
|
|
@@ -188,7 +304,7 @@ export declare class Fly {
|
|
|
188
304
|
private createApp;
|
|
189
305
|
/**
|
|
190
306
|
* @private
|
|
191
|
-
* @returns The name
|
|
307
|
+
* @returns The app name and optional image reference (only set when buildOnly is true)
|
|
192
308
|
* @throws An error if the deployment fails
|
|
193
309
|
*/
|
|
194
310
|
private deployApp;
|
|
@@ -232,6 +348,45 @@ export declare class Fly {
|
|
|
232
348
|
* @throws An error if the domain cannot be removed
|
|
233
349
|
*/
|
|
234
350
|
private removeAppCertificate;
|
|
351
|
+
/**
|
|
352
|
+
* @private
|
|
353
|
+
* Deploy secrets previously staged for an application
|
|
354
|
+
* @throws An error if the staged secrets cannot be deployed
|
|
355
|
+
*/
|
|
356
|
+
private deployStagedSecrets;
|
|
357
|
+
/**
|
|
358
|
+
* @private
|
|
359
|
+
* Execute a command inside a running machine
|
|
360
|
+
* @returns The command output
|
|
361
|
+
* @throws An error if the command fails
|
|
362
|
+
*/
|
|
363
|
+
private sshExec;
|
|
364
|
+
/**
|
|
365
|
+
* @private
|
|
366
|
+
* Start a machine
|
|
367
|
+
* @throws An error if the machine cannot be started
|
|
368
|
+
*/
|
|
369
|
+
private startMachine;
|
|
370
|
+
/**
|
|
371
|
+
* @private
|
|
372
|
+
* Stop a machine
|
|
373
|
+
* @throws An error if the machine cannot be stopped
|
|
374
|
+
*/
|
|
375
|
+
private stopMachine;
|
|
376
|
+
/**
|
|
377
|
+
* @private
|
|
378
|
+
* Restart a machine by stopping then starting it
|
|
379
|
+
* @throws An error if the machine cannot be restarted
|
|
380
|
+
*/
|
|
381
|
+
private restartMachine;
|
|
382
|
+
/**
|
|
383
|
+
* @private
|
|
384
|
+
* Update a machine's per-machine config (env vars, etc.).
|
|
385
|
+
* Creates a new machine version so the machine cold-starts from the updated config,
|
|
386
|
+
* bypassing any suspended memory snapshot.
|
|
387
|
+
* @throws An error if the machine cannot be updated
|
|
388
|
+
*/
|
|
389
|
+
private updateMachine;
|
|
235
390
|
/**
|
|
236
391
|
* @private
|
|
237
392
|
* @returns A list of all applications or `null` if listing applications fails and `nullOnError` is used
|
|
@@ -288,11 +443,26 @@ export declare class Fly {
|
|
|
288
443
|
* @throws An error if the config cannot be retrieved and `throwOnError` is used
|
|
289
444
|
*/
|
|
290
445
|
private showConfig;
|
|
446
|
+
/**
|
|
447
|
+
* @private
|
|
448
|
+
* Save remote config to a local file
|
|
449
|
+
*
|
|
450
|
+
* Two things flyctl expects that a first-time caller would not: the output
|
|
451
|
+
* format is no longer sniffed from the path's extension — `--json`/`--yaml`
|
|
452
|
+
* has to be passed, TOML being what is left over when neither is — and the
|
|
453
|
+
* destination must already exist as a parseable file of that format, or
|
|
454
|
+
* `flyctl` refuses to write to it at all, mistaking "does not exist yet"
|
|
455
|
+
* for "path is wrong". A fresh, empty seed of the right shape satisfies
|
|
456
|
+
* that read without affecting what gets written back over it.
|
|
457
|
+
*
|
|
458
|
+
* @throws An error if the config cannot be saved
|
|
459
|
+
*/
|
|
460
|
+
private saveConfig;
|
|
291
461
|
/**
|
|
292
462
|
* @private
|
|
293
463
|
* Ensure Fly CLI is installed and authenticated
|
|
294
464
|
*
|
|
295
|
-
* @throws An error if Fly CLI is not installed or
|
|
465
|
+
* @throws An error if Fly CLI is not installed or not authenticated
|
|
296
466
|
*/
|
|
297
467
|
private ensureInitialized;
|
|
298
468
|
/**
|
|
@@ -336,6 +506,14 @@ export declare class Fly {
|
|
|
336
506
|
* @returns `true` if the Fly CLI is installed, `false` otherwise
|
|
337
507
|
*/
|
|
338
508
|
private isInstalled;
|
|
509
|
+
/**
|
|
510
|
+
* @private
|
|
511
|
+
* Get the installed Fly CLI version
|
|
512
|
+
*
|
|
513
|
+
* @returns The installed Fly CLI version information
|
|
514
|
+
* @throws An error if the version cannot be retrieved
|
|
515
|
+
*/
|
|
516
|
+
private version;
|
|
339
517
|
/**
|
|
340
518
|
* @private
|
|
341
519
|
* Normalize the options matching `AppOrConfig` type.
|
|
@@ -353,10 +531,23 @@ export declare class Fly {
|
|
|
353
531
|
* @returns The escaped argument
|
|
354
532
|
*/
|
|
355
533
|
private safeArg;
|
|
534
|
+
/**
|
|
535
|
+
* @private
|
|
536
|
+
* Redact sensitive values from text.
|
|
537
|
+
*
|
|
538
|
+
* Identifies and redacts:
|
|
539
|
+
* - Secret values provided with `secrets set KEY1=VALUE1 KEY2=VALUE2 ...`
|
|
540
|
+
*
|
|
541
|
+
* @param text - The text to redact
|
|
542
|
+
* @returns The redacted text
|
|
543
|
+
*/
|
|
544
|
+
private redactSensitiveData;
|
|
356
545
|
/**
|
|
357
546
|
* @private
|
|
358
547
|
* Trace the CLI calls, mocks and results
|
|
359
548
|
*
|
|
549
|
+
* Redacts sensitive data from CALL messages when enabled in logger config.
|
|
550
|
+
*
|
|
360
551
|
* @param type - The type of trace
|
|
361
552
|
* @param msg - The message to trace
|
|
362
553
|
*/
|
package/src/lib/mocks.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export declare const mockDefs: {
|
|
|
30
30
|
/**
|
|
31
31
|
* Mock `fly apps list` response for testing.
|
|
32
32
|
*/
|
|
33
|
-
export declare const mockAppsListResponse:
|
|
33
|
+
export declare const mockAppsListResponse: ListAppResponse;
|
|
34
34
|
/**
|
|
35
35
|
* Mock `fly apps create` response for testing.
|
|
36
36
|
*
|
|
@@ -40,31 +40,33 @@ export declare const mockCreateAppResponse: (app?: string) => CreateAppResponse;
|
|
|
40
40
|
/**
|
|
41
41
|
* Mock `fly certs list` response for testing.
|
|
42
42
|
*/
|
|
43
|
-
export declare const mockListCertForAppResponse:
|
|
43
|
+
export declare const mockListCertForAppResponse: ListCertForAppResponse;
|
|
44
44
|
/**
|
|
45
45
|
* Mock `fly certs list` response for all apps for testing.
|
|
46
46
|
*
|
|
47
47
|
* All apps from `mockAppsListResponse` gets the same certificates from `mockListCertForAppResponse`
|
|
48
48
|
*/
|
|
49
|
-
export declare const mockListCertForAllResponse:
|
|
49
|
+
export declare const mockListCertForAllResponse: ListCertForAllResponse;
|
|
50
50
|
/**
|
|
51
51
|
* Mock `fly postgres list` response for testing.
|
|
52
|
+
*
|
|
53
|
+
* TODO: Mock the string response when there are no Postgres clusters.
|
|
52
54
|
*/
|
|
53
|
-
export declare const mockListPostgresResponse:
|
|
55
|
+
export declare const mockListPostgresResponse: ListPostgresResponse;
|
|
54
56
|
/**
|
|
55
57
|
* Mock `fly postgres users list` response for testing.
|
|
56
58
|
*/
|
|
57
|
-
export declare const mockListPostgresUsersResponse:
|
|
59
|
+
export declare const mockListPostgresUsersResponse: ListPostgresUsersResponse;
|
|
58
60
|
/**
|
|
59
61
|
* Mock `fly secrets list` response for testing.
|
|
60
62
|
*/
|
|
61
|
-
export declare const mockListSecretForAppResponse:
|
|
63
|
+
export declare const mockListSecretForAppResponse: ListSecretForAppResponse;
|
|
62
64
|
/**
|
|
63
65
|
* Mock `fly secrets list` response for all apps for testing.
|
|
64
66
|
*
|
|
65
67
|
* All apps from `mockAppsListResponse` gets the same secrets from `mockListSecretForAppResponse`
|
|
66
68
|
*/
|
|
67
|
-
export declare const mockListSecretForAllResponse:
|
|
69
|
+
export declare const mockListSecretForAllResponse: ListSecretForAllResponse;
|
|
68
70
|
/**
|
|
69
71
|
* Mock `fly config show` response for testing.
|
|
70
72
|
*
|
|
@@ -91,3 +93,16 @@ export declare const mockShowConfigResponse: (app?: string) => {
|
|
|
91
93
|
* @param app - The app name to use in the response (defaults to `mockDefs.testApp`)
|
|
92
94
|
*/
|
|
93
95
|
export declare const mockStatusResponse: (app?: string) => StatusResponse;
|
|
96
|
+
/**
|
|
97
|
+
* Mock `fly version` response for testing.
|
|
98
|
+
*/
|
|
99
|
+
export declare const mockVersionResponse: {
|
|
100
|
+
Name: string;
|
|
101
|
+
Version: string;
|
|
102
|
+
Commit: string;
|
|
103
|
+
BranchName: string;
|
|
104
|
+
BuildDate: string;
|
|
105
|
+
OS: string;
|
|
106
|
+
Architecture: string;
|
|
107
|
+
Environment: string;
|
|
108
|
+
};
|