@cdwr/fly-node 0.1.0 → 0.2.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 +18 -0
- package/README.md +8 -1
- package/index.cjs +227 -139
- package/index.js +227 -137
- package/package.json +1 -1
- package/src/lib/fly.class.d.ts +6 -0
- package/src/lib/schemas/apps-create.schema.d.ts +8 -8
- package/src/lib/schemas/apps-list.schema.d.ts +6 -6
- package/src/lib/schemas/postgres-list.d.ts +6 -6
- package/src/lib/schemas/status-extended.schema.d.ts +18 -18
- package/src/lib/schemas/status.schema.d.ts +32 -32
- package/src/lib/types.d.ts +6 -0
package/index.js
CHANGED
|
@@ -29,9 +29,75 @@ import { exec as cpExec } from "child_process";
|
|
|
29
29
|
import { promisify as promisify3 } from "util";
|
|
30
30
|
var exec = promisify3(cpExec);
|
|
31
31
|
|
|
32
|
+
// packages/core/src/lib/utils/promisified-spawn.ts
|
|
33
|
+
import {
|
|
34
|
+
spawn as cpSpawn
|
|
35
|
+
} from "child_process";
|
|
36
|
+
function spawn(command, args, options) {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
const process2 = cpSpawn(command, args, {
|
|
39
|
+
...options,
|
|
40
|
+
stdio: "pipe"
|
|
41
|
+
});
|
|
42
|
+
const stdoutChunks = [];
|
|
43
|
+
const stderrChunks = [];
|
|
44
|
+
process2.stdout.on("data", (data) => {
|
|
45
|
+
stdoutChunks.push(Buffer.from(data));
|
|
46
|
+
});
|
|
47
|
+
process2.stderr.on("data", (data) => {
|
|
48
|
+
stderrChunks.push(Buffer.from(data));
|
|
49
|
+
});
|
|
50
|
+
process2.on("close", (code) => {
|
|
51
|
+
const stdout = Buffer.concat(stdoutChunks).toString();
|
|
52
|
+
const stderr = Buffer.concat(stderrChunks).toString();
|
|
53
|
+
if (code === 0) {
|
|
54
|
+
resolve({ stdout, stderr });
|
|
55
|
+
} else {
|
|
56
|
+
reject(new Error(`Process exited with code ${code}
|
|
57
|
+
Error: ${stderr}`));
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
process2.on("error", reject);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
32
64
|
// packages/core/src/lib/utils/run-command.ts
|
|
33
65
|
import { tmpProjPath } from "@nx/plugin/testing";
|
|
34
66
|
|
|
67
|
+
// packages/core/src/lib/utils/spawn-pty.ts
|
|
68
|
+
import { spawn as spawn2 } from "@homebridge/node-pty-prebuilt-multiarch";
|
|
69
|
+
function spawnPty(command, args, options) {
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
const ptyData = [];
|
|
72
|
+
const ptyProcess = spawn2(command, args, {
|
|
73
|
+
cwd: process.cwd(),
|
|
74
|
+
encoding: "utf-8",
|
|
75
|
+
env: process.env
|
|
76
|
+
});
|
|
77
|
+
ptyProcess.onData((data) => {
|
|
78
|
+
ptyData.push(data);
|
|
79
|
+
if (options?.prompt) {
|
|
80
|
+
const answer = options.prompt(data);
|
|
81
|
+
if (answer) {
|
|
82
|
+
ptyProcess.write(`${answer}
|
|
83
|
+
`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
ptyProcess.onExit(({ exitCode }) => {
|
|
88
|
+
const output = ptyData.join("");
|
|
89
|
+
if (exitCode === 0) {
|
|
90
|
+
resolve(output);
|
|
91
|
+
} else {
|
|
92
|
+
reject(
|
|
93
|
+
new Error(`Process exited with code ${exitCode}
|
|
94
|
+
Output: ${output}`)
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
35
101
|
// packages/core/src/lib/utils/whoami.ts
|
|
36
102
|
import npmWhoami from "npm-whoami";
|
|
37
103
|
|
|
@@ -104,43 +170,40 @@ var withCamelCase = (schema, options = {}) => {
|
|
|
104
170
|
);
|
|
105
171
|
};
|
|
106
172
|
|
|
107
|
-
// packages/core/src/lib/zod/with-env-vars.preprocess.ts
|
|
108
|
-
import { z as z3 } from "zod";
|
|
109
|
-
|
|
110
173
|
// packages/core/src/lib/zod/with-replace-all.preprocess.ts
|
|
111
|
-
import { z as
|
|
174
|
+
import { z as z3 } from "zod";
|
|
112
175
|
|
|
113
176
|
// packages/fly-node/src/lib/schemas/apps-create.schema.ts
|
|
114
|
-
import { z as
|
|
177
|
+
import { z as z4 } from "zod";
|
|
115
178
|
var AppsCreateTransformedResponseSchema = withCamelCase(
|
|
116
|
-
|
|
117
|
-
id:
|
|
118
|
-
name:
|
|
119
|
-
organization:
|
|
120
|
-
id:
|
|
121
|
-
name:
|
|
179
|
+
z4.object({
|
|
180
|
+
id: z4.string(),
|
|
181
|
+
name: z4.string(),
|
|
182
|
+
organization: z4.object({
|
|
183
|
+
id: z4.string(),
|
|
184
|
+
name: z4.string()
|
|
122
185
|
})
|
|
123
186
|
})
|
|
124
187
|
);
|
|
125
188
|
|
|
126
189
|
// packages/fly-node/src/lib/schemas/apps-list.schema.ts
|
|
127
|
-
import { z as
|
|
128
|
-
var AppsListTransformedResponseSchema =
|
|
190
|
+
import { z as z5 } from "zod";
|
|
191
|
+
var AppsListTransformedResponseSchema = z5.array(
|
|
129
192
|
withCamelCase(
|
|
130
|
-
|
|
131
|
-
id:
|
|
132
|
-
name:
|
|
133
|
-
status:
|
|
134
|
-
deployed:
|
|
135
|
-
hostname:
|
|
136
|
-
organization:
|
|
137
|
-
name:
|
|
138
|
-
slug:
|
|
193
|
+
z5.object({
|
|
194
|
+
id: z5.string(),
|
|
195
|
+
name: z5.string(),
|
|
196
|
+
status: z5.string(),
|
|
197
|
+
deployed: z5.boolean(),
|
|
198
|
+
hostname: z5.string(),
|
|
199
|
+
organization: z5.object({
|
|
200
|
+
name: z5.string(),
|
|
201
|
+
slug: z5.string()
|
|
139
202
|
}),
|
|
140
|
-
currentRelease:
|
|
141
|
-
|
|
142
|
-
status:
|
|
143
|
-
createdAt:
|
|
203
|
+
currentRelease: z5.nullable(
|
|
204
|
+
z5.object({
|
|
205
|
+
status: z5.string(),
|
|
206
|
+
createdAt: z5.string().datetime()
|
|
144
207
|
})
|
|
145
208
|
)
|
|
146
209
|
})
|
|
@@ -148,46 +211,46 @@ var AppsListTransformedResponseSchema = z6.array(
|
|
|
148
211
|
);
|
|
149
212
|
|
|
150
213
|
// packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
|
|
151
|
-
import { z as
|
|
214
|
+
import { z as z7 } from "zod";
|
|
152
215
|
|
|
153
216
|
// packages/fly-node/src/lib/schemas/certs-list.schema.ts
|
|
154
|
-
import { z as
|
|
155
|
-
var CertsListFlyResponseElementSchema =
|
|
156
|
-
createdAt:
|
|
157
|
-
hostname:
|
|
158
|
-
clientStatus:
|
|
217
|
+
import { z as z6 } from "zod";
|
|
218
|
+
var CertsListFlyResponseElementSchema = z6.object({
|
|
219
|
+
createdAt: z6.string().datetime(),
|
|
220
|
+
hostname: z6.string(),
|
|
221
|
+
clientStatus: z6.string()
|
|
159
222
|
});
|
|
160
|
-
var CertsListTransformedResponseSchema =
|
|
223
|
+
var CertsListTransformedResponseSchema = z6.array(
|
|
161
224
|
withCamelCase(CertsListFlyResponseElementSchema)
|
|
162
225
|
);
|
|
163
226
|
|
|
164
227
|
// packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
|
|
165
|
-
var CertsListWithAppTransformedResponseSchema =
|
|
228
|
+
var CertsListWithAppTransformedResponseSchema = z7.array(
|
|
166
229
|
withCamelCase(
|
|
167
230
|
CertsListFlyResponseElementSchema.extend({
|
|
168
|
-
app:
|
|
231
|
+
app: z7.string()
|
|
169
232
|
})
|
|
170
233
|
)
|
|
171
234
|
);
|
|
172
235
|
|
|
173
236
|
// packages/fly-node/src/lib/schemas/config-show.schema.ts
|
|
174
|
-
import { z as
|
|
237
|
+
import { z as z8 } from "zod";
|
|
175
238
|
var ConfigShowResponseSchema = withCamelCase(
|
|
176
|
-
|
|
177
|
-
app:
|
|
178
|
-
primaryRegion:
|
|
179
|
-
build:
|
|
180
|
-
|
|
181
|
-
args:
|
|
182
|
-
dockerfile:
|
|
183
|
-
image:
|
|
239
|
+
z8.object({
|
|
240
|
+
app: z8.string(),
|
|
241
|
+
primaryRegion: z8.string().optional(),
|
|
242
|
+
build: z8.record(z8.string(), z8.any()).optional().or(
|
|
243
|
+
z8.object({
|
|
244
|
+
args: z8.record(z8.string(), z8.string()).optional(),
|
|
245
|
+
dockerfile: z8.string().optional(),
|
|
246
|
+
image: z8.string().optional()
|
|
184
247
|
})
|
|
185
248
|
),
|
|
186
|
-
deploy:
|
|
187
|
-
env:
|
|
188
|
-
httpService:
|
|
189
|
-
mounts:
|
|
190
|
-
services:
|
|
249
|
+
deploy: z8.record(z8.string(), z8.any()).optional().or(z8.object({ strategy: z8.string().optional() })),
|
|
250
|
+
env: z8.record(z8.string(), z8.string()).optional(),
|
|
251
|
+
httpService: z8.record(z8.string(), z8.any()).optional(),
|
|
252
|
+
mounts: z8.record(z8.string(), z8.any()).optional(),
|
|
253
|
+
services: z8.array(z8.record(z8.string(), z8.any())).optional()
|
|
191
254
|
}),
|
|
192
255
|
{
|
|
193
256
|
preserve: ["build.args", "env"]
|
|
@@ -195,115 +258,115 @@ var ConfigShowResponseSchema = withCamelCase(
|
|
|
195
258
|
);
|
|
196
259
|
|
|
197
260
|
// packages/fly-node/src/lib/schemas/deploy.schema.ts
|
|
198
|
-
import { z as
|
|
199
|
-
var DeployResponseSchema =
|
|
200
|
-
app:
|
|
201
|
-
hostname:
|
|
202
|
-
url:
|
|
261
|
+
import { z as z9 } from "zod";
|
|
262
|
+
var DeployResponseSchema = z9.object({
|
|
263
|
+
app: z9.string(),
|
|
264
|
+
hostname: z9.string(),
|
|
265
|
+
url: z9.string().url()
|
|
203
266
|
});
|
|
204
267
|
|
|
205
268
|
// packages/fly-node/src/lib/schemas/helper-schemas.ts
|
|
206
|
-
import { z as
|
|
207
|
-
var AllowEmptyUrlSchema =
|
|
208
|
-
var NameSchema =
|
|
269
|
+
import { z as z10 } from "zod";
|
|
270
|
+
var AllowEmptyUrlSchema = z10.string().url().or(z10.literal(""));
|
|
271
|
+
var NameSchema = z10.string({ message: "App name must be a valid slug" }).regex(/^[a-z0-9-]+$/);
|
|
209
272
|
|
|
210
273
|
// packages/fly-node/src/lib/schemas/postgres-list.ts
|
|
211
|
-
import { z as
|
|
212
|
-
var PostgresListTransformedResponseSchema =
|
|
274
|
+
import { z as z11 } from "zod";
|
|
275
|
+
var PostgresListTransformedResponseSchema = z11.array(
|
|
213
276
|
withCamelCase(
|
|
214
|
-
|
|
215
|
-
deployed:
|
|
216
|
-
hostname:
|
|
217
|
-
id:
|
|
218
|
-
name:
|
|
219
|
-
organization:
|
|
220
|
-
status:
|
|
221
|
-
version:
|
|
277
|
+
z11.object({
|
|
278
|
+
deployed: z11.boolean(),
|
|
279
|
+
hostname: z11.string(),
|
|
280
|
+
id: z11.string(),
|
|
281
|
+
name: z11.string(),
|
|
282
|
+
organization: z11.object({ id: z11.string(), slug: z11.string() }),
|
|
283
|
+
status: z11.string(),
|
|
284
|
+
version: z11.number()
|
|
222
285
|
})
|
|
223
286
|
)
|
|
224
287
|
);
|
|
225
288
|
|
|
226
289
|
// packages/fly-node/src/lib/schemas/postgres-users-list.ts
|
|
227
|
-
import { z as
|
|
228
|
-
var PostgresUsersListTransformedResponseSchema =
|
|
290
|
+
import { z as z12 } from "zod";
|
|
291
|
+
var PostgresUsersListTransformedResponseSchema = z12.array(
|
|
229
292
|
withCamelCase(
|
|
230
|
-
|
|
231
|
-
username:
|
|
232
|
-
superuser:
|
|
233
|
-
databases:
|
|
293
|
+
z12.object({
|
|
294
|
+
username: z12.string(),
|
|
295
|
+
superuser: z12.boolean(),
|
|
296
|
+
databases: z12.array(z12.string())
|
|
234
297
|
})
|
|
235
298
|
)
|
|
236
299
|
);
|
|
237
300
|
|
|
238
301
|
// packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
|
|
239
|
-
import { z as
|
|
302
|
+
import { z as z14 } from "zod";
|
|
240
303
|
|
|
241
304
|
// packages/fly-node/src/lib/schemas/secrets-list.schema.ts
|
|
242
|
-
import { z as
|
|
243
|
-
var SecretsListFlyResponseElementSchema =
|
|
244
|
-
name:
|
|
245
|
-
digest:
|
|
246
|
-
createdAt:
|
|
305
|
+
import { z as z13 } from "zod";
|
|
306
|
+
var SecretsListFlyResponseElementSchema = z13.object({
|
|
307
|
+
name: z13.string(),
|
|
308
|
+
digest: z13.string(),
|
|
309
|
+
createdAt: z13.string().datetime()
|
|
247
310
|
});
|
|
248
|
-
var SecretsListTransformedResponseSchema =
|
|
311
|
+
var SecretsListTransformedResponseSchema = z13.array(
|
|
249
312
|
withCamelCase(SecretsListFlyResponseElementSchema)
|
|
250
313
|
);
|
|
251
314
|
|
|
252
315
|
// packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
|
|
253
|
-
var SecretsListWithAppTransformedResponseSchema =
|
|
316
|
+
var SecretsListWithAppTransformedResponseSchema = z14.array(
|
|
254
317
|
withCamelCase(
|
|
255
318
|
SecretsListFlyResponseElementSchema.extend({
|
|
256
|
-
app:
|
|
319
|
+
app: z14.string()
|
|
257
320
|
})
|
|
258
321
|
)
|
|
259
322
|
);
|
|
260
323
|
|
|
261
324
|
// packages/fly-node/src/lib/schemas/status-extended.schema.ts
|
|
262
|
-
import { z as
|
|
325
|
+
import { z as z16 } from "zod";
|
|
263
326
|
|
|
264
327
|
// packages/fly-node/src/lib/schemas/status.schema.ts
|
|
265
|
-
import { z as
|
|
266
|
-
var statusFlyResponseSchema =
|
|
267
|
-
deployed:
|
|
268
|
-
hostname:
|
|
269
|
-
id:
|
|
270
|
-
machines:
|
|
271
|
-
|
|
272
|
-
id:
|
|
273
|
-
name:
|
|
274
|
-
state:
|
|
275
|
-
region:
|
|
276
|
-
createdAt:
|
|
277
|
-
updatedAt:
|
|
278
|
-
config:
|
|
279
|
-
env:
|
|
280
|
-
metadata:
|
|
328
|
+
import { z as z15 } from "zod";
|
|
329
|
+
var statusFlyResponseSchema = z15.object({
|
|
330
|
+
deployed: z15.boolean(),
|
|
331
|
+
hostname: z15.string(),
|
|
332
|
+
id: z15.string(),
|
|
333
|
+
machines: z15.array(
|
|
334
|
+
z15.object({
|
|
335
|
+
id: z15.string(),
|
|
336
|
+
name: z15.string(),
|
|
337
|
+
state: z15.string(),
|
|
338
|
+
region: z15.string(),
|
|
339
|
+
createdAt: z15.string().datetime(),
|
|
340
|
+
updatedAt: z15.string().datetime(),
|
|
341
|
+
config: z15.object({
|
|
342
|
+
env: z15.record(z15.string()),
|
|
343
|
+
metadata: z15.record(z15.string())
|
|
281
344
|
}),
|
|
282
|
-
events:
|
|
283
|
-
|
|
284
|
-
type:
|
|
285
|
-
status:
|
|
286
|
-
timestamp:
|
|
345
|
+
events: z15.array(
|
|
346
|
+
z15.object({
|
|
347
|
+
type: z15.string(),
|
|
348
|
+
status: z15.string(),
|
|
349
|
+
timestamp: z15.number()
|
|
287
350
|
})
|
|
288
351
|
),
|
|
289
|
-
checks:
|
|
290
|
-
|
|
291
|
-
name:
|
|
292
|
-
status:
|
|
293
|
-
output:
|
|
294
|
-
updatedAt:
|
|
352
|
+
checks: z15.array(
|
|
353
|
+
z15.object({
|
|
354
|
+
name: z15.string(),
|
|
355
|
+
status: z15.string(),
|
|
356
|
+
output: z15.string(),
|
|
357
|
+
updatedAt: z15.string().datetime()
|
|
295
358
|
})
|
|
296
359
|
).optional(),
|
|
297
|
-
hostStatus:
|
|
360
|
+
hostStatus: z15.string()
|
|
298
361
|
})
|
|
299
362
|
),
|
|
300
|
-
name:
|
|
301
|
-
organization:
|
|
302
|
-
id:
|
|
303
|
-
slug:
|
|
363
|
+
name: z15.string(),
|
|
364
|
+
organization: z15.object({
|
|
365
|
+
id: z15.string(),
|
|
366
|
+
slug: z15.string()
|
|
304
367
|
}),
|
|
305
|
-
status:
|
|
306
|
-
version:
|
|
368
|
+
status: z15.string(),
|
|
369
|
+
version: z15.number()
|
|
307
370
|
});
|
|
308
371
|
var StatusTransformedResponseSchema = withCamelCase(
|
|
309
372
|
statusFlyResponseSchema,
|
|
@@ -316,8 +379,8 @@ var StatusTransformedResponseSchema = withCamelCase(
|
|
|
316
379
|
// packages/fly-node/src/lib/schemas/status-extended.schema.ts
|
|
317
380
|
var StatusExtendedTransformedResponseSchema = withCamelCase(
|
|
318
381
|
statusFlyResponseSchema.extend({
|
|
319
|
-
domains:
|
|
320
|
-
secrets:
|
|
382
|
+
domains: z16.array(z16.object({ hostname: z16.string() })),
|
|
383
|
+
secrets: z16.array(z16.object({ name: z16.string() }))
|
|
321
384
|
}),
|
|
322
385
|
{
|
|
323
386
|
preserve: ["machines.config.env", "machines.config.metadata"]
|
|
@@ -441,7 +504,8 @@ ${error}`
|
|
|
441
504
|
this.logger.info(
|
|
442
505
|
`Detaching Postgres cluster '${cluster}' from application '${app}'`
|
|
443
506
|
);
|
|
444
|
-
await this.detachPostgres(cluster, app);
|
|
507
|
+
const output = await this.detachPostgres(cluster, app);
|
|
508
|
+
this.logger.info(output);
|
|
445
509
|
}
|
|
446
510
|
await this.destroyApp(app, options?.force);
|
|
447
511
|
this.logger.info(`Application '${app}' was destroyed`);
|
|
@@ -588,6 +652,11 @@ ${error}`
|
|
|
588
652
|
);
|
|
589
653
|
}
|
|
590
654
|
};
|
|
655
|
+
postgres = {
|
|
656
|
+
detach: async (cluster, app) => {
|
|
657
|
+
await this.detachPostgres(cluster, app);
|
|
658
|
+
}
|
|
659
|
+
};
|
|
591
660
|
/**
|
|
592
661
|
* Manage application secrets
|
|
593
662
|
*/
|
|
@@ -830,6 +899,9 @@ ${error}`);
|
|
|
830
899
|
for (const [key, value] of Object.entries(options?.env || {})) {
|
|
831
900
|
args.push("--env", `${key}=${this.safeArg(value)}`);
|
|
832
901
|
}
|
|
902
|
+
if (options?.optOutDepotBuilder) {
|
|
903
|
+
args.push("--depot=false");
|
|
904
|
+
}
|
|
833
905
|
args.push("--yes");
|
|
834
906
|
this.logger.info(`Deploying '${appName}'...`);
|
|
835
907
|
await this.execFly(args);
|
|
@@ -855,11 +927,19 @@ ${error}`);
|
|
|
855
927
|
}
|
|
856
928
|
/**
|
|
857
929
|
* @private
|
|
930
|
+
* @returns Log output from the detach process
|
|
858
931
|
* @throws An error if the Postgres database cannot be detached from an app
|
|
859
932
|
*/
|
|
860
933
|
async detachPostgres(postgres, app) {
|
|
861
934
|
const args = ["postgres", "detach", postgres, "--app", app];
|
|
862
|
-
await this.execFly(args
|
|
935
|
+
return await this.execFly(args, {
|
|
936
|
+
prompt: (output) => {
|
|
937
|
+
if (output.match(/select .* detach/i)) {
|
|
938
|
+
return app.replace(/-/g, "_");
|
|
939
|
+
}
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
});
|
|
863
943
|
}
|
|
864
944
|
/**
|
|
865
945
|
* @private
|
|
@@ -1083,6 +1163,7 @@ ${JSON.stringify(response, null, 2)}`);
|
|
|
1083
1163
|
this.logger.info("Authenticating with Fly.io...");
|
|
1084
1164
|
let user = await this.execFly(
|
|
1085
1165
|
["auth", "whoami"],
|
|
1166
|
+
void 0,
|
|
1086
1167
|
"nullOnError",
|
|
1087
1168
|
true
|
|
1088
1169
|
// won't use token
|
|
@@ -1100,34 +1181,43 @@ ${JSON.stringify(response, null, 2)}`);
|
|
|
1100
1181
|
throw error;
|
|
1101
1182
|
}
|
|
1102
1183
|
}
|
|
1103
|
-
async execFly(command, onError = "throwOnError", skipToken) {
|
|
1104
|
-
const
|
|
1184
|
+
async execFly(command, options, onError = "throwOnError", skipToken) {
|
|
1185
|
+
const args = Array.isArray(command) ? command : command.split(" ");
|
|
1105
1186
|
if (!skipToken && !this.authByLogin && this._config.token) {
|
|
1106
|
-
|
|
1187
|
+
args.push("--access-token", this._config.token);
|
|
1107
1188
|
}
|
|
1108
|
-
const flyCmd =
|
|
1109
|
-
|
|
1189
|
+
const flyCmd = "flyctl";
|
|
1190
|
+
const toLogCmd = `${flyCmd} ${args.join(" ")}`;
|
|
1191
|
+
let output = "";
|
|
1110
1192
|
try {
|
|
1111
|
-
this.traceCLI("CALL",
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1193
|
+
this.traceCLI("CALL", toLogCmd);
|
|
1194
|
+
if (options?.prompt) {
|
|
1195
|
+
output = await spawnPty(flyCmd, args, { prompt: options.prompt });
|
|
1196
|
+
this.traceCLI("RESULT", output);
|
|
1197
|
+
} else {
|
|
1198
|
+
const result = await spawn(flyCmd, args, options);
|
|
1199
|
+
output = result.stdout.trim();
|
|
1200
|
+
const stderr = result.stderr.trim();
|
|
1201
|
+
this.traceCLI("RESULT", `${output}${stderr ? `
|
|
1202
|
+
${stderr}` : ""}`);
|
|
1203
|
+
}
|
|
1115
1204
|
} catch (error) {
|
|
1116
|
-
|
|
1205
|
+
const errorMsg = error.message;
|
|
1206
|
+
this.traceCLI("RESULT", errorMsg);
|
|
1117
1207
|
if (onError === "throwOnError") {
|
|
1118
|
-
throw new Error(`Command failed: ${
|
|
1119
|
-
${
|
|
1208
|
+
throw new Error(`Command failed: ${toLogCmd}
|
|
1209
|
+
${errorMsg}`);
|
|
1120
1210
|
}
|
|
1121
1211
|
return null;
|
|
1122
1212
|
}
|
|
1123
1213
|
try {
|
|
1124
|
-
return JSON.parse(
|
|
1214
|
+
return JSON.parse(output);
|
|
1125
1215
|
} catch {
|
|
1126
|
-
if (
|
|
1216
|
+
if (output) {
|
|
1127
1217
|
if (this.logger.traceCLI) {
|
|
1128
1218
|
this.logger.info(`Failed to parse as JSON, returning raw output`);
|
|
1129
1219
|
}
|
|
1130
|
-
return
|
|
1220
|
+
return output;
|
|
1131
1221
|
}
|
|
1132
1222
|
}
|
|
1133
1223
|
return void 0;
|
|
@@ -1197,7 +1287,7 @@ ${error}`);
|
|
|
1197
1287
|
* @returns `true` if the Fly CLI is installed, `false` otherwise
|
|
1198
1288
|
*/
|
|
1199
1289
|
async isInstalled() {
|
|
1200
|
-
return await this.execFly("version", "nullOnError") !== null;
|
|
1290
|
+
return await this.execFly("version", void 0, "nullOnError") !== null;
|
|
1201
1291
|
}
|
|
1202
1292
|
/**
|
|
1203
1293
|
* @private
|
package/package.json
CHANGED
package/src/lib/fly.class.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { SpawnOptions, SpawnPtyOptions } from '@codeware/core/utils';
|
|
1
2
|
import type { AppOrConfig, Config, CreateAppOptions, DeployAppOptions, DeployResponse, DestroyAppOptions, ListAppResponse, ListCertForAllResponse, ListCertForAppResponse, ListSecretForAllResponse, ListSecretForAppResponse, SetAppSecretsOptions, ShowConfigOptions, ShowConfigResponse, StatusExtendedResponse, StatusResponse, UnsetAppSecretsOptions } from './types';
|
|
3
|
+
export type ExecFlyOptions = SpawnOptions & SpawnPtyOptions;
|
|
2
4
|
/**
|
|
3
5
|
* Manages deployments to Fly.io using the `flyctl` CLI tool.
|
|
4
6
|
*/
|
|
@@ -131,6 +133,9 @@ export declare class Fly {
|
|
|
131
133
|
* @throws An error if the deployment fails
|
|
132
134
|
*/
|
|
133
135
|
deploy: (options?: DeployAppOptions) => Promise<DeployResponse>;
|
|
136
|
+
postgres: {
|
|
137
|
+
detach: (cluster: string, app: string) => Promise<void>;
|
|
138
|
+
};
|
|
134
139
|
/**
|
|
135
140
|
* Manage application secrets
|
|
136
141
|
*/
|
|
@@ -199,6 +204,7 @@ export declare class Fly {
|
|
|
199
204
|
private destroyApp;
|
|
200
205
|
/**
|
|
201
206
|
* @private
|
|
207
|
+
* @returns Log output from the detach process
|
|
202
208
|
* @throws An error if the Postgres database cannot be detached from an app
|
|
203
209
|
*/
|
|
204
210
|
private detachPostgres;
|
|
@@ -13,31 +13,31 @@ export declare const AppsCreateTransformedResponseSchema: z.ZodEffects<z.ZodObje
|
|
|
13
13
|
id: z.ZodString;
|
|
14
14
|
name: z.ZodString;
|
|
15
15
|
}, "strip", z.ZodTypeAny, {
|
|
16
|
-
name: string;
|
|
17
16
|
id: string;
|
|
18
|
-
}, {
|
|
19
17
|
name: string;
|
|
18
|
+
}, {
|
|
20
19
|
id: string;
|
|
20
|
+
name: string;
|
|
21
21
|
}>;
|
|
22
22
|
}, "strip", z.ZodTypeAny, {
|
|
23
|
-
name: string;
|
|
24
23
|
id: string;
|
|
24
|
+
name: string;
|
|
25
25
|
organization: {
|
|
26
|
-
name: string;
|
|
27
26
|
id: string;
|
|
27
|
+
name: string;
|
|
28
28
|
};
|
|
29
29
|
}, {
|
|
30
|
-
name: string;
|
|
31
30
|
id: string;
|
|
31
|
+
name: string;
|
|
32
32
|
organization: {
|
|
33
|
-
name: string;
|
|
34
33
|
id: string;
|
|
34
|
+
name: string;
|
|
35
35
|
};
|
|
36
36
|
}>, {
|
|
37
|
-
name: string;
|
|
38
37
|
id: string;
|
|
38
|
+
name: string;
|
|
39
39
|
organization: {
|
|
40
|
-
name: string;
|
|
41
40
|
id: string;
|
|
41
|
+
name: string;
|
|
42
42
|
};
|
|
43
43
|
}, unknown>;
|
|
@@ -33,9 +33,9 @@ export declare const AppsListTransformedResponseSchema: z.ZodArray<z.ZodEffects<
|
|
|
33
33
|
createdAt: string;
|
|
34
34
|
}>>;
|
|
35
35
|
}, "strip", z.ZodTypeAny, {
|
|
36
|
-
name: string;
|
|
37
|
-
status: string;
|
|
38
36
|
id: string;
|
|
37
|
+
status: string;
|
|
38
|
+
name: string;
|
|
39
39
|
organization: {
|
|
40
40
|
name: string;
|
|
41
41
|
slug: string;
|
|
@@ -47,9 +47,9 @@ export declare const AppsListTransformedResponseSchema: z.ZodArray<z.ZodEffects<
|
|
|
47
47
|
createdAt: string;
|
|
48
48
|
} | null;
|
|
49
49
|
}, {
|
|
50
|
-
name: string;
|
|
51
|
-
status: string;
|
|
52
50
|
id: string;
|
|
51
|
+
status: string;
|
|
52
|
+
name: string;
|
|
53
53
|
organization: {
|
|
54
54
|
name: string;
|
|
55
55
|
slug: string;
|
|
@@ -61,9 +61,9 @@ export declare const AppsListTransformedResponseSchema: z.ZodArray<z.ZodEffects<
|
|
|
61
61
|
createdAt: string;
|
|
62
62
|
} | null;
|
|
63
63
|
}>, {
|
|
64
|
-
name: string;
|
|
65
|
-
status: string;
|
|
66
64
|
id: string;
|
|
65
|
+
status: string;
|
|
66
|
+
name: string;
|
|
67
67
|
organization: {
|
|
68
68
|
name: string;
|
|
69
69
|
slug: string;
|
|
@@ -24,9 +24,9 @@ export declare const PostgresListTransformedResponseSchema: z.ZodArray<z.ZodEffe
|
|
|
24
24
|
status: z.ZodString;
|
|
25
25
|
version: z.ZodNumber;
|
|
26
26
|
}, "strip", z.ZodTypeAny, {
|
|
27
|
-
name: string;
|
|
28
|
-
status: string;
|
|
29
27
|
id: string;
|
|
28
|
+
status: string;
|
|
29
|
+
name: string;
|
|
30
30
|
organization: {
|
|
31
31
|
id: string;
|
|
32
32
|
slug: string;
|
|
@@ -35,9 +35,9 @@ export declare const PostgresListTransformedResponseSchema: z.ZodArray<z.ZodEffe
|
|
|
35
35
|
hostname: string;
|
|
36
36
|
version: number;
|
|
37
37
|
}, {
|
|
38
|
-
name: string;
|
|
39
|
-
status: string;
|
|
40
38
|
id: string;
|
|
39
|
+
status: string;
|
|
40
|
+
name: string;
|
|
41
41
|
organization: {
|
|
42
42
|
id: string;
|
|
43
43
|
slug: string;
|
|
@@ -46,9 +46,9 @@ export declare const PostgresListTransformedResponseSchema: z.ZodArray<z.ZodEffe
|
|
|
46
46
|
hostname: string;
|
|
47
47
|
version: number;
|
|
48
48
|
}>, {
|
|
49
|
-
name: string;
|
|
50
|
-
status: string;
|
|
51
49
|
id: string;
|
|
50
|
+
status: string;
|
|
51
|
+
name: string;
|
|
52
52
|
organization: {
|
|
53
53
|
id: string;
|
|
54
54
|
slug: string;
|