@cdwr/fly-node 0.3.2 → 0.3.3
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 +26 -0
- package/README.md +4 -0
- package/api.cjs +115 -58
- package/api.js +113 -58
- package/index.cjs +482 -277
- package/index.js +478 -275
- package/package.json +1 -1
- package/src/api.d.ts +1 -0
- package/src/lib/fly-api.class.d.ts +21 -1
- package/src/lib/fly.class.d.ts +38 -1
- package/src/lib/mocks.d.ts +62 -0
- package/src/lib/schemas/app-ip-addresses.schema.d.ts +66 -0
- package/src/lib/schemas/apps-list.schema.d.ts +8 -8
- package/src/lib/schemas/certificate.schema.d.ts +12 -12
- package/src/lib/schemas/ip-type.schema.d.ts +14 -0
- package/src/lib/schemas/ips-list.schema.d.ts +10 -20
- package/src/lib/schemas/postgres-list.d.ts +3 -3
- package/src/lib/schemas/status-extended.schema.d.ts +3 -3
- package/src/lib/schemas/status.schema.d.ts +68 -5
package/index.js
CHANGED
|
@@ -1,46 +1,63 @@
|
|
|
1
|
-
// packages/fly-node/src/lib/schemas/
|
|
1
|
+
// packages/fly-node/src/lib/schemas/app-ip-addresses.schema.ts
|
|
2
|
+
import { z as z2 } from "zod";
|
|
3
|
+
|
|
4
|
+
// packages/fly-node/src/lib/schemas/ip-type.schema.ts
|
|
2
5
|
import { z } from "zod";
|
|
3
|
-
var
|
|
4
|
-
|
|
6
|
+
var IpTypeSchema = z.enum(["v4", "v6", "shared_v4", "private_v6"]).or(z.string());
|
|
7
|
+
|
|
8
|
+
// packages/fly-node/src/lib/schemas/app-ip-addresses.schema.ts
|
|
9
|
+
var AppIpAddressSchema = z2.object({
|
|
10
|
+
address: z2.string(),
|
|
11
|
+
type: IpTypeSchema
|
|
12
|
+
});
|
|
13
|
+
var AppIpAddressesApiResponseSchema = z2.object({
|
|
14
|
+
sharedIpAddress: z2.string().nullish(),
|
|
15
|
+
ipAddresses: z2.object({ nodes: z2.array(AppIpAddressSchema) })
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// packages/fly-node/src/lib/schemas/certificate.schema.ts
|
|
19
|
+
import { z as z3 } from "zod";
|
|
20
|
+
var CertificateApiResponseSchema = z3.object({
|
|
21
|
+
hostname: z3.string(),
|
|
5
22
|
/** Issued and serving. This is what decides whether a domain is usable */
|
|
6
|
-
isConfigured:
|
|
7
|
-
id:
|
|
23
|
+
isConfigured: z3.boolean(),
|
|
24
|
+
id: z3.string().optional(),
|
|
8
25
|
/** The apex or a subdomain — apex domains cannot use a CNAME */
|
|
9
|
-
isApex:
|
|
10
|
-
isWildcard:
|
|
26
|
+
isApex: z3.boolean().optional(),
|
|
27
|
+
isWildcard: z3.boolean().optional(),
|
|
11
28
|
/** Which ACME challenge has been satisfied, if any */
|
|
12
|
-
isAcmeDnsConfigured:
|
|
13
|
-
isAcmeAlpnConfigured:
|
|
14
|
-
isAcmeHttpConfigured:
|
|
15
|
-
certificateAuthority:
|
|
16
|
-
certificateRequestedAt:
|
|
17
|
-
createdAt:
|
|
18
|
-
domain:
|
|
19
|
-
dnsProvider:
|
|
29
|
+
isAcmeDnsConfigured: z3.boolean().optional(),
|
|
30
|
+
isAcmeAlpnConfigured: z3.boolean().optional(),
|
|
31
|
+
isAcmeHttpConfigured: z3.boolean().optional(),
|
|
32
|
+
certificateAuthority: z3.string().nullish(),
|
|
33
|
+
certificateRequestedAt: z3.string().nullish(),
|
|
34
|
+
createdAt: z3.string().nullish(),
|
|
35
|
+
domain: z3.string().nullish(),
|
|
36
|
+
dnsProvider: z3.string().nullish(),
|
|
20
37
|
/** Hostname the validation record must be created on */
|
|
21
|
-
dnsValidationHostname:
|
|
38
|
+
dnsValidationHostname: z3.string().nullish(),
|
|
22
39
|
/** Value that record must contain */
|
|
23
|
-
dnsValidationTarget:
|
|
40
|
+
dnsValidationTarget: z3.string().nullish(),
|
|
24
41
|
/** Fly's own prose describing the records to create */
|
|
25
|
-
dnsValidationInstructions:
|
|
42
|
+
dnsValidationInstructions: z3.string().nullish(),
|
|
26
43
|
/** Fly's summary of where issuance has got to */
|
|
27
|
-
clientStatus:
|
|
44
|
+
clientStatus: z3.string().nullish(),
|
|
28
45
|
/**
|
|
29
46
|
* Set when Let's Encrypt has rate-limited further attempts for this domain.
|
|
30
47
|
*
|
|
31
48
|
* Worth surfacing rather than swallowing: it is the one failure a customer
|
|
32
49
|
* cannot fix by correcting DNS, and retrying only makes it worse.
|
|
33
50
|
*/
|
|
34
|
-
rateLimitedUntil:
|
|
35
|
-
source:
|
|
51
|
+
rateLimitedUntil: z3.string().nullish(),
|
|
52
|
+
source: z3.string().nullish(),
|
|
36
53
|
/**
|
|
37
54
|
* Fly's own prose for a failed issuance attempt — what the dashboard shows,
|
|
38
55
|
* unlike `HostnameCheck.errors`, which is SCREAMING_SNAKE_CASE codes
|
|
39
56
|
*/
|
|
40
|
-
validationErrors:
|
|
41
|
-
|
|
42
|
-
message:
|
|
43
|
-
timestamp:
|
|
57
|
+
validationErrors: z3.array(
|
|
58
|
+
z3.object({
|
|
59
|
+
message: z3.string(),
|
|
60
|
+
timestamp: z3.string()
|
|
44
61
|
})
|
|
45
62
|
).nullish(),
|
|
46
63
|
/**
|
|
@@ -50,52 +67,52 @@ var CertificateApiResponseSchema = z.object({
|
|
|
50
67
|
* nodes is the normal count — one RSA and one ECDSA — sharing an expiry,
|
|
51
68
|
* which is why a caller usually wants the expiry rather than the rows.
|
|
52
69
|
*/
|
|
53
|
-
issued:
|
|
54
|
-
nodes:
|
|
55
|
-
|
|
56
|
-
id:
|
|
70
|
+
issued: z3.object({
|
|
71
|
+
nodes: z3.array(
|
|
72
|
+
z3.object({
|
|
73
|
+
id: z3.string().nullish(),
|
|
57
74
|
/** Key type, e.g. `RSA` or `ECDSA` */
|
|
58
|
-
type:
|
|
59
|
-
hostname:
|
|
60
|
-
expiresAt:
|
|
75
|
+
type: z3.string().nullish(),
|
|
76
|
+
hostname: z3.string().nullish(),
|
|
77
|
+
expiresAt: z3.string().nullish()
|
|
61
78
|
})
|
|
62
79
|
).nullish()
|
|
63
80
|
}).nullish()
|
|
64
81
|
});
|
|
65
|
-
var HostnameCheckApiResponseSchema =
|
|
66
|
-
aRecords:
|
|
67
|
-
aaaaRecords:
|
|
68
|
-
cnameRecords:
|
|
69
|
-
caaRecords:
|
|
70
|
-
soa:
|
|
71
|
-
dnsProvider:
|
|
72
|
-
dnsVerificationRecord:
|
|
73
|
-
dnsConfigured:
|
|
74
|
-
acmeDnsConfigured:
|
|
75
|
-
resolvedAddresses:
|
|
76
|
-
isProxied:
|
|
77
|
-
errors:
|
|
82
|
+
var HostnameCheckApiResponseSchema = z3.object({
|
|
83
|
+
aRecords: z3.array(z3.string()).nullish(),
|
|
84
|
+
aaaaRecords: z3.array(z3.string()).nullish(),
|
|
85
|
+
cnameRecords: z3.array(z3.string()).nullish(),
|
|
86
|
+
caaRecords: z3.array(z3.string()).nullish(),
|
|
87
|
+
soa: z3.string().nullish(),
|
|
88
|
+
dnsProvider: z3.string().nullish(),
|
|
89
|
+
dnsVerificationRecord: z3.string().nullish(),
|
|
90
|
+
dnsConfigured: z3.boolean().nullish(),
|
|
91
|
+
acmeDnsConfigured: z3.boolean().nullish(),
|
|
92
|
+
resolvedAddresses: z3.array(z3.string()).nullish(),
|
|
93
|
+
isProxied: z3.boolean().nullish(),
|
|
94
|
+
errors: z3.array(z3.string()).nullish()
|
|
78
95
|
});
|
|
79
|
-
var DnsInstructionsSchema =
|
|
80
|
-
hostname:
|
|
81
|
-
target:
|
|
82
|
-
instructions:
|
|
83
|
-
isApex:
|
|
96
|
+
var DnsInstructionsSchema = z3.object({
|
|
97
|
+
hostname: z3.string().nullish(),
|
|
98
|
+
target: z3.string().nullish(),
|
|
99
|
+
instructions: z3.string().nullish(),
|
|
100
|
+
isApex: z3.boolean().optional()
|
|
84
101
|
});
|
|
85
|
-
var CertificateListApiResponseSchema =
|
|
102
|
+
var CertificateListApiResponseSchema = z3.array(
|
|
86
103
|
CertificateApiResponseSchema
|
|
87
104
|
);
|
|
88
105
|
|
|
89
106
|
// packages/fly-node/src/lib/schemas/machine.schema.ts
|
|
90
|
-
import { z as
|
|
91
|
-
var MachineApiResponseSchema =
|
|
92
|
-
id:
|
|
93
|
-
name:
|
|
107
|
+
import { z as z4 } from "zod";
|
|
108
|
+
var MachineApiResponseSchema = z4.object({
|
|
109
|
+
id: z4.string(),
|
|
110
|
+
name: z4.string().nullish(),
|
|
94
111
|
/** `started`, `stopped`, `suspended`, … — Fly owns this vocabulary */
|
|
95
|
-
state:
|
|
96
|
-
region:
|
|
112
|
+
state: z4.string().nullish(),
|
|
113
|
+
region: z4.string().nullish()
|
|
97
114
|
});
|
|
98
|
-
var MachineListApiResponseSchema =
|
|
115
|
+
var MachineListApiResponseSchema = z4.array(MachineApiResponseSchema);
|
|
99
116
|
|
|
100
117
|
// packages/fly-node/src/lib/fly-api.class.ts
|
|
101
118
|
var FLY_API_URL = "https://api.fly.io/graphql";
|
|
@@ -288,6 +305,42 @@ var FlyApi = class {
|
|
|
288
305
|
);
|
|
289
306
|
}
|
|
290
307
|
};
|
|
308
|
+
/** Read an app's addresses */
|
|
309
|
+
ips = {
|
|
310
|
+
/**
|
|
311
|
+
* The addresses an app answers on: `shared_v4`, `v4`, `v6`, and its
|
|
312
|
+
* `private_v6`.
|
|
313
|
+
*
|
|
314
|
+
* The shared v4 is folded in as a `shared_v4` row, the way `fly ips list`
|
|
315
|
+
* shows it; Fly's API keeps it in a separate field. Egress addresses,
|
|
316
|
+
* which the CLI also lists, are not part of this API and never appear.
|
|
317
|
+
* Pick the public types before pointing DNS at them.
|
|
318
|
+
*
|
|
319
|
+
* Rejects for an unknown app, like `certs.list`: a typo in an app name
|
|
320
|
+
* must not read as "this app has no addresses".
|
|
321
|
+
*
|
|
322
|
+
* @returns The addresses, empty when the app has none
|
|
323
|
+
*/
|
|
324
|
+
list: async (app) => {
|
|
325
|
+
const data = await this.request(
|
|
326
|
+
`query AppIpAddresses($appName: String!) {
|
|
327
|
+
app(name: $appName) {
|
|
328
|
+
sharedIpAddress
|
|
329
|
+
ipAddresses { nodes { address type } }
|
|
330
|
+
}
|
|
331
|
+
}`,
|
|
332
|
+
{ appName: app }
|
|
333
|
+
);
|
|
334
|
+
if (!data.app) {
|
|
335
|
+
return [];
|
|
336
|
+
}
|
|
337
|
+
const { sharedIpAddress, ipAddresses } = AppIpAddressesApiResponseSchema.parse(data.app);
|
|
338
|
+
return [
|
|
339
|
+
...sharedIpAddress ? [{ address: sharedIpAddress, type: "shared_v4" }] : [],
|
|
340
|
+
...ipAddresses.nodes
|
|
341
|
+
];
|
|
342
|
+
}
|
|
343
|
+
};
|
|
291
344
|
/**
|
|
292
345
|
* Operate an app's machines.
|
|
293
346
|
*
|
|
@@ -503,6 +556,18 @@ var killProcessTree = promisify2(treeKill);
|
|
|
503
556
|
import {
|
|
504
557
|
spawn as cpSpawn
|
|
505
558
|
} from "child_process";
|
|
559
|
+
var STREAMED_STDERR_TAIL_LINES = 20;
|
|
560
|
+
var SpawnError = class extends Error {
|
|
561
|
+
exitCode;
|
|
562
|
+
stdout;
|
|
563
|
+
stderr;
|
|
564
|
+
constructor(message, details) {
|
|
565
|
+
super(message);
|
|
566
|
+
this.exitCode = details.exitCode;
|
|
567
|
+
this.stdout = details.stdout;
|
|
568
|
+
this.stderr = details.stderr;
|
|
569
|
+
}
|
|
570
|
+
};
|
|
506
571
|
function spawn(command, args, options) {
|
|
507
572
|
return new Promise((resolve, reject) => {
|
|
508
573
|
const { streamToConsole, ...spawnOptions } = options || {};
|
|
@@ -530,8 +595,12 @@ function spawn(command, args, options) {
|
|
|
530
595
|
if (code === 0) {
|
|
531
596
|
resolve({ stdout, stderr });
|
|
532
597
|
} else {
|
|
533
|
-
|
|
534
|
-
|
|
598
|
+
const lines = stderr.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
599
|
+
const message = streamToConsole && lines.length > STREAMED_STDERR_TAIL_LINES ? `Process exited with code ${code}
|
|
600
|
+
Error (last ${STREAMED_STDERR_TAIL_LINES} lines; the full output is above):
|
|
601
|
+
${lines.slice(-STREAMED_STDERR_TAIL_LINES).join("\n")}` : `Process exited with code ${code}
|
|
602
|
+
Error: ${stderr}`;
|
|
603
|
+
reject(new SpawnError(message, { exitCode: code, stdout, stderr }));
|
|
535
604
|
}
|
|
536
605
|
});
|
|
537
606
|
process2.on("error", reject);
|
|
@@ -576,20 +645,20 @@ Output: ${output}`)
|
|
|
576
645
|
import { ZodError } from "zod";
|
|
577
646
|
|
|
578
647
|
// libs/shared/util/zod/src/lib/coerce-boolean.ts
|
|
579
|
-
import { z as
|
|
648
|
+
import { z as z5 } from "zod";
|
|
580
649
|
|
|
581
650
|
// libs/shared/util/zod/src/lib/create-lowercase-schema.ts
|
|
582
|
-
import { z as
|
|
651
|
+
import { z as z6 } from "zod";
|
|
583
652
|
|
|
584
653
|
// libs/shared/util/zod/src/lib/json.schema.ts
|
|
585
|
-
import { z as
|
|
586
|
-
var LiteralSchema =
|
|
587
|
-
var JsonSchema =
|
|
588
|
-
() =>
|
|
654
|
+
import { z as z7 } from "zod";
|
|
655
|
+
var LiteralSchema = z7.union([z7.string(), z7.number(), z7.boolean(), z7.null()]);
|
|
656
|
+
var JsonSchema = z7.lazy(
|
|
657
|
+
() => z7.union([LiteralSchema, z7.array(JsonSchema), z7.record(JsonSchema)])
|
|
589
658
|
);
|
|
590
659
|
|
|
591
660
|
// libs/shared/util/zod/src/lib/with-camel-case.preprocess.ts
|
|
592
|
-
import { z as
|
|
661
|
+
import { z as z8 } from "zod";
|
|
593
662
|
var toCamelCase = (str, specialCases = {}) => {
|
|
594
663
|
if (specialCases[str]) {
|
|
595
664
|
return specialCases[str];
|
|
@@ -639,7 +708,7 @@ var transformKeys = (options) => {
|
|
|
639
708
|
};
|
|
640
709
|
var withCamelCase = (schema, options = {}) => {
|
|
641
710
|
const { preserve = [], specialCases = {} } = options;
|
|
642
|
-
return
|
|
711
|
+
return z8.preprocess(
|
|
643
712
|
(data) => transformKeys({
|
|
644
713
|
currentPath: [],
|
|
645
714
|
data,
|
|
@@ -651,38 +720,38 @@ var withCamelCase = (schema, options = {}) => {
|
|
|
651
720
|
};
|
|
652
721
|
|
|
653
722
|
// libs/shared/util/zod/src/lib/with-env-vars.preprocess.ts
|
|
654
|
-
import { z as
|
|
723
|
+
import { z as z9 } from "zod";
|
|
655
724
|
|
|
656
725
|
// libs/shared/util/zod/src/lib/with-replace-all.preprocess.ts
|
|
657
|
-
import { z as
|
|
726
|
+
import { z as z10 } from "zod";
|
|
658
727
|
|
|
659
728
|
// packages/fly-node/src/lib/schemas/apps-create.schema.ts
|
|
660
|
-
import { z as
|
|
729
|
+
import { z as z11 } from "zod";
|
|
661
730
|
var AppsCreateTransformedResponseSchema = withCamelCase(
|
|
662
|
-
|
|
663
|
-
id:
|
|
664
|
-
name:
|
|
731
|
+
z11.object({
|
|
732
|
+
id: z11.string(),
|
|
733
|
+
name: z11.string()
|
|
665
734
|
})
|
|
666
735
|
);
|
|
667
736
|
|
|
668
737
|
// packages/fly-node/src/lib/schemas/apps-list.schema.ts
|
|
669
|
-
import { z as
|
|
670
|
-
var AppsListTransformedResponseSchema =
|
|
738
|
+
import { z as z12 } from "zod";
|
|
739
|
+
var AppsListTransformedResponseSchema = z12.array(
|
|
671
740
|
withCamelCase(
|
|
672
|
-
|
|
673
|
-
id:
|
|
674
|
-
name:
|
|
675
|
-
status:
|
|
676
|
-
deployed:
|
|
677
|
-
hostname:
|
|
678
|
-
organization:
|
|
679
|
-
name:
|
|
680
|
-
slug:
|
|
741
|
+
z12.object({
|
|
742
|
+
id: z12.string(),
|
|
743
|
+
name: z12.string(),
|
|
744
|
+
status: z12.string(),
|
|
745
|
+
deployed: z12.boolean(),
|
|
746
|
+
hostname: z12.string(),
|
|
747
|
+
organization: z12.object({
|
|
748
|
+
name: z12.string(),
|
|
749
|
+
slug: z12.string()
|
|
681
750
|
}),
|
|
682
|
-
currentRelease:
|
|
683
|
-
|
|
684
|
-
status:
|
|
685
|
-
createdAt:
|
|
751
|
+
currentRelease: z12.nullable(
|
|
752
|
+
z12.object({
|
|
753
|
+
status: z12.string(),
|
|
754
|
+
createdAt: z12.string().datetime()
|
|
686
755
|
})
|
|
687
756
|
)
|
|
688
757
|
})
|
|
@@ -690,53 +759,53 @@ var AppsListTransformedResponseSchema = z10.array(
|
|
|
690
759
|
);
|
|
691
760
|
|
|
692
761
|
// packages/fly-node/src/lib/schemas/build-response.schema.ts
|
|
693
|
-
import { z as
|
|
694
|
-
var BuildResponseSchema =
|
|
695
|
-
appName:
|
|
696
|
-
imageRef:
|
|
762
|
+
import { z as z13 } from "zod";
|
|
763
|
+
var BuildResponseSchema = z13.object({
|
|
764
|
+
appName: z13.string(),
|
|
765
|
+
imageRef: z13.string()
|
|
697
766
|
});
|
|
698
767
|
|
|
699
768
|
// packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
|
|
700
|
-
import { z as
|
|
769
|
+
import { z as z15 } from "zod";
|
|
701
770
|
|
|
702
771
|
// packages/fly-node/src/lib/schemas/certs-list.schema.ts
|
|
703
|
-
import { z as
|
|
704
|
-
var CertsListFlyResponseElementSchema =
|
|
705
|
-
createdAt:
|
|
706
|
-
hostname:
|
|
707
|
-
clientStatus:
|
|
772
|
+
import { z as z14 } from "zod";
|
|
773
|
+
var CertsListFlyResponseElementSchema = z14.object({
|
|
774
|
+
createdAt: z14.string().datetime(),
|
|
775
|
+
hostname: z14.string(),
|
|
776
|
+
clientStatus: z14.string()
|
|
708
777
|
});
|
|
709
|
-
var CertsListTransformedResponseSchema =
|
|
778
|
+
var CertsListTransformedResponseSchema = z14.array(
|
|
710
779
|
withCamelCase(CertsListFlyResponseElementSchema)
|
|
711
780
|
);
|
|
712
781
|
|
|
713
782
|
// packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
|
|
714
|
-
var CertsListWithAppTransformedResponseSchema =
|
|
783
|
+
var CertsListWithAppTransformedResponseSchema = z15.array(
|
|
715
784
|
withCamelCase(
|
|
716
785
|
CertsListFlyResponseElementSchema.extend({
|
|
717
|
-
app:
|
|
786
|
+
app: z15.string()
|
|
718
787
|
})
|
|
719
788
|
)
|
|
720
789
|
);
|
|
721
790
|
|
|
722
791
|
// packages/fly-node/src/lib/schemas/config-show.schema.ts
|
|
723
|
-
import { z as
|
|
792
|
+
import { z as z16 } from "zod";
|
|
724
793
|
var ConfigShowResponseSchema = withCamelCase(
|
|
725
|
-
|
|
726
|
-
app:
|
|
727
|
-
primaryRegion:
|
|
728
|
-
build:
|
|
729
|
-
|
|
730
|
-
args:
|
|
731
|
-
dockerfile:
|
|
732
|
-
image:
|
|
794
|
+
z16.object({
|
|
795
|
+
app: z16.string(),
|
|
796
|
+
primaryRegion: z16.string().optional(),
|
|
797
|
+
build: z16.record(z16.string(), z16.any()).optional().or(
|
|
798
|
+
z16.object({
|
|
799
|
+
args: z16.record(z16.string(), z16.string()).optional(),
|
|
800
|
+
dockerfile: z16.string().optional(),
|
|
801
|
+
image: z16.string().optional()
|
|
733
802
|
})
|
|
734
803
|
),
|
|
735
|
-
deploy:
|
|
736
|
-
env:
|
|
737
|
-
httpService:
|
|
738
|
-
mounts:
|
|
739
|
-
services:
|
|
804
|
+
deploy: z16.record(z16.string(), z16.any()).optional().or(z16.object({ strategy: z16.string().optional() })),
|
|
805
|
+
env: z16.record(z16.string(), z16.string()).optional(),
|
|
806
|
+
httpService: z16.record(z16.string(), z16.any()).optional(),
|
|
807
|
+
mounts: z16.record(z16.string(), z16.any()).optional(),
|
|
808
|
+
services: z16.array(z16.record(z16.string(), z16.any())).optional()
|
|
740
809
|
}),
|
|
741
810
|
{
|
|
742
811
|
preserve: ["build.args", "env"]
|
|
@@ -744,140 +813,139 @@ var ConfigShowResponseSchema = withCamelCase(
|
|
|
744
813
|
);
|
|
745
814
|
|
|
746
815
|
// packages/fly-node/src/lib/schemas/deploy.schema.ts
|
|
747
|
-
import { z as
|
|
748
|
-
var DeployResponseSchema =
|
|
749
|
-
app:
|
|
750
|
-
hostname:
|
|
751
|
-
url:
|
|
816
|
+
import { z as z17 } from "zod";
|
|
817
|
+
var DeployResponseSchema = z17.object({
|
|
818
|
+
app: z17.string(),
|
|
819
|
+
hostname: z17.string(),
|
|
820
|
+
url: z17.string().url()
|
|
752
821
|
});
|
|
753
822
|
|
|
754
823
|
// packages/fly-node/src/lib/schemas/helper-schemas.ts
|
|
755
|
-
import { z as
|
|
756
|
-
var AllowEmptyUrlSchema =
|
|
757
|
-
var NameSchema =
|
|
824
|
+
import { z as z18 } from "zod";
|
|
825
|
+
var AllowEmptyUrlSchema = z18.string().url().or(z18.literal(""));
|
|
826
|
+
var NameSchema = z18.string({ message: "App name must be a valid slug" }).regex(/^[a-z0-9-]+$/);
|
|
758
827
|
|
|
759
828
|
// packages/fly-node/src/lib/schemas/ips-list.schema.ts
|
|
760
|
-
import { z as
|
|
761
|
-
var
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
address: z17.string(),
|
|
829
|
+
import { z as z19 } from "zod";
|
|
830
|
+
var IpsListFlyResponseElementSchema = z19.object({
|
|
831
|
+
id: z19.string(),
|
|
832
|
+
address: z19.string(),
|
|
765
833
|
type: IpTypeSchema,
|
|
766
|
-
region:
|
|
767
|
-
createdAt:
|
|
834
|
+
region: z19.string(),
|
|
835
|
+
createdAt: z19.string()
|
|
768
836
|
});
|
|
769
|
-
var IpsListTransformedResponseSchema =
|
|
837
|
+
var IpsListTransformedResponseSchema = z19.array(
|
|
770
838
|
withCamelCase(IpsListFlyResponseElementSchema)
|
|
771
839
|
);
|
|
772
840
|
|
|
773
841
|
// packages/fly-node/src/lib/schemas/postgres-list.ts
|
|
774
|
-
import { z as
|
|
775
|
-
var PostgresListTransformedResponseSchema =
|
|
842
|
+
import { z as z20 } from "zod";
|
|
843
|
+
var PostgresListTransformedResponseSchema = z20.array(
|
|
776
844
|
withCamelCase(
|
|
777
|
-
|
|
778
|
-
deployed:
|
|
779
|
-
hostname:
|
|
780
|
-
id:
|
|
781
|
-
name:
|
|
782
|
-
organization:
|
|
783
|
-
status:
|
|
784
|
-
version:
|
|
845
|
+
z20.object({
|
|
846
|
+
deployed: z20.boolean(),
|
|
847
|
+
hostname: z20.string(),
|
|
848
|
+
id: z20.string(),
|
|
849
|
+
name: z20.string(),
|
|
850
|
+
organization: z20.object({ id: z20.string(), slug: z20.string() }),
|
|
851
|
+
status: z20.string(),
|
|
852
|
+
version: z20.number()
|
|
785
853
|
})
|
|
786
854
|
)
|
|
787
|
-
).or(
|
|
855
|
+
).or(z20.string());
|
|
788
856
|
|
|
789
857
|
// packages/fly-node/src/lib/schemas/postgres-users-list.ts
|
|
790
|
-
import { z as
|
|
791
|
-
var PostgresUsersListTransformedResponseSchema =
|
|
858
|
+
import { z as z21 } from "zod";
|
|
859
|
+
var PostgresUsersListTransformedResponseSchema = z21.array(
|
|
792
860
|
withCamelCase(
|
|
793
|
-
|
|
794
|
-
username:
|
|
795
|
-
superuser:
|
|
796
|
-
databases:
|
|
861
|
+
z21.object({
|
|
862
|
+
username: z21.string(),
|
|
863
|
+
superuser: z21.boolean(),
|
|
864
|
+
databases: z21.array(z21.string())
|
|
797
865
|
})
|
|
798
866
|
)
|
|
799
867
|
);
|
|
800
868
|
|
|
801
869
|
// packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
|
|
802
|
-
import { z as
|
|
870
|
+
import { z as z23 } from "zod";
|
|
803
871
|
|
|
804
872
|
// packages/fly-node/src/lib/schemas/secrets-list.schema.ts
|
|
805
|
-
import { z as
|
|
806
|
-
var SecretsListFlyResponseElementSchema =
|
|
807
|
-
name:
|
|
808
|
-
digest:
|
|
873
|
+
import { z as z22 } from "zod";
|
|
874
|
+
var SecretsListFlyResponseElementSchema = z22.object({
|
|
875
|
+
name: z22.string(),
|
|
876
|
+
digest: z22.string()
|
|
809
877
|
});
|
|
810
|
-
var SecretsListTransformedResponseSchema =
|
|
878
|
+
var SecretsListTransformedResponseSchema = z22.array(
|
|
811
879
|
withCamelCase(SecretsListFlyResponseElementSchema)
|
|
812
880
|
);
|
|
813
881
|
|
|
814
882
|
// packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
|
|
815
|
-
var SecretsListWithAppTransformedResponseSchema =
|
|
883
|
+
var SecretsListWithAppTransformedResponseSchema = z23.array(
|
|
816
884
|
withCamelCase(
|
|
817
885
|
SecretsListFlyResponseElementSchema.extend({
|
|
818
|
-
app:
|
|
886
|
+
app: z23.string()
|
|
819
887
|
})
|
|
820
888
|
)
|
|
821
889
|
);
|
|
822
890
|
|
|
823
891
|
// packages/fly-node/src/lib/schemas/status-extended.schema.ts
|
|
824
|
-
import { z as
|
|
892
|
+
import { z as z25 } from "zod";
|
|
825
893
|
|
|
826
894
|
// packages/fly-node/src/lib/schemas/status.schema.ts
|
|
827
|
-
import { z as
|
|
828
|
-
var statusFlyResponseSchema =
|
|
829
|
-
deployed:
|
|
830
|
-
hostname:
|
|
831
|
-
id:
|
|
832
|
-
machines:
|
|
833
|
-
|
|
834
|
-
id:
|
|
835
|
-
name:
|
|
836
|
-
state:
|
|
837
|
-
region:
|
|
838
|
-
imageRef:
|
|
839
|
-
registry:
|
|
840
|
-
repository:
|
|
841
|
-
tag:
|
|
842
|
-
digest:
|
|
843
|
-
labels:
|
|
895
|
+
import { z as z24 } from "zod";
|
|
896
|
+
var statusFlyResponseSchema = z24.object({
|
|
897
|
+
deployed: z24.boolean(),
|
|
898
|
+
hostname: z24.string(),
|
|
899
|
+
id: z24.string(),
|
|
900
|
+
machines: z24.array(
|
|
901
|
+
z24.object({
|
|
902
|
+
id: z24.string(),
|
|
903
|
+
name: z24.string(),
|
|
904
|
+
state: z24.string(),
|
|
905
|
+
region: z24.string(),
|
|
906
|
+
imageRef: z24.object({
|
|
907
|
+
registry: z24.string(),
|
|
908
|
+
repository: z24.string(),
|
|
909
|
+
tag: z24.string(),
|
|
910
|
+
digest: z24.string(),
|
|
911
|
+
labels: z24.record(z24.string()).optional()
|
|
844
912
|
}),
|
|
845
|
-
createdAt:
|
|
846
|
-
updatedAt:
|
|
847
|
-
config:
|
|
848
|
-
env:
|
|
849
|
-
metadata:
|
|
850
|
-
guest:
|
|
851
|
-
cpu_kind:
|
|
852
|
-
cpus:
|
|
853
|
-
memory_mb:
|
|
913
|
+
createdAt: z24.string().datetime(),
|
|
914
|
+
updatedAt: z24.string().datetime(),
|
|
915
|
+
config: z24.object({
|
|
916
|
+
env: z24.record(z24.string()),
|
|
917
|
+
metadata: z24.record(z24.string()),
|
|
918
|
+
guest: z24.object({
|
|
919
|
+
cpu_kind: z24.string().optional(),
|
|
920
|
+
cpus: z24.number().optional(),
|
|
921
|
+
memory_mb: z24.number().optional()
|
|
854
922
|
}).optional()
|
|
855
923
|
}),
|
|
856
|
-
events:
|
|
857
|
-
|
|
858
|
-
type:
|
|
859
|
-
status:
|
|
860
|
-
timestamp:
|
|
924
|
+
events: z24.array(
|
|
925
|
+
z24.object({
|
|
926
|
+
type: z24.string(),
|
|
927
|
+
status: z24.string(),
|
|
928
|
+
timestamp: z24.number()
|
|
861
929
|
})
|
|
862
930
|
),
|
|
863
|
-
checks:
|
|
864
|
-
|
|
865
|
-
name:
|
|
866
|
-
status:
|
|
867
|
-
output:
|
|
868
|
-
updatedAt:
|
|
931
|
+
checks: z24.array(
|
|
932
|
+
z24.object({
|
|
933
|
+
name: z24.string(),
|
|
934
|
+
status: z24.string(),
|
|
935
|
+
output: z24.string(),
|
|
936
|
+
updatedAt: z24.string().datetime()
|
|
869
937
|
})
|
|
870
938
|
).optional(),
|
|
871
|
-
hostStatus:
|
|
939
|
+
hostStatus: z24.string()
|
|
872
940
|
})
|
|
873
941
|
),
|
|
874
|
-
name:
|
|
875
|
-
organization:
|
|
876
|
-
id:
|
|
877
|
-
slug:
|
|
942
|
+
name: z24.string(),
|
|
943
|
+
organization: z24.object({
|
|
944
|
+
id: z24.string(),
|
|
945
|
+
slug: z24.string()
|
|
878
946
|
}),
|
|
879
|
-
status:
|
|
880
|
-
version:
|
|
947
|
+
status: z24.string(),
|
|
948
|
+
version: z24.number()
|
|
881
949
|
});
|
|
882
950
|
var StatusTransformedResponseSchema = withCamelCase(
|
|
883
951
|
statusFlyResponseSchema,
|
|
@@ -890,12 +958,24 @@ var StatusTransformedResponseSchema = withCamelCase(
|
|
|
890
958
|
specialCases: { AppURL: "appUrl" }
|
|
891
959
|
}
|
|
892
960
|
);
|
|
961
|
+
var statusLookupSchema = withCamelCase(
|
|
962
|
+
z24.object({
|
|
963
|
+
name: z24.string(),
|
|
964
|
+
hostname: z24.string(),
|
|
965
|
+
machines: z24.array(
|
|
966
|
+
z24.object({
|
|
967
|
+
id: z24.string(),
|
|
968
|
+
state: z24.string()
|
|
969
|
+
}).passthrough()
|
|
970
|
+
)
|
|
971
|
+
}).passthrough()
|
|
972
|
+
);
|
|
893
973
|
|
|
894
974
|
// packages/fly-node/src/lib/schemas/status-extended.schema.ts
|
|
895
975
|
var StatusExtendedTransformedResponseSchema = withCamelCase(
|
|
896
976
|
statusFlyResponseSchema.extend({
|
|
897
|
-
domains:
|
|
898
|
-
secrets:
|
|
977
|
+
domains: z25.array(z25.object({ hostname: z25.string() })),
|
|
978
|
+
secrets: z25.array(z25.object({ name: z25.string() }))
|
|
899
979
|
}),
|
|
900
980
|
{
|
|
901
981
|
preserve: [
|
|
@@ -907,21 +987,33 @@ var StatusExtendedTransformedResponseSchema = withCamelCase(
|
|
|
907
987
|
);
|
|
908
988
|
|
|
909
989
|
// packages/fly-node/src/lib/schemas/version.schema.ts
|
|
910
|
-
import { z as
|
|
990
|
+
import { z as z26 } from "zod";
|
|
911
991
|
var VersionTransformedResponseSchema = withCamelCase(
|
|
912
|
-
|
|
913
|
-
name:
|
|
914
|
-
version:
|
|
915
|
-
commit:
|
|
916
|
-
branchName:
|
|
917
|
-
buildDate:
|
|
918
|
-
os:
|
|
919
|
-
architecture:
|
|
920
|
-
environment:
|
|
992
|
+
z26.object({
|
|
993
|
+
name: z26.string(),
|
|
994
|
+
version: z26.string(),
|
|
995
|
+
commit: z26.string(),
|
|
996
|
+
branchName: z26.string(),
|
|
997
|
+
buildDate: z26.string().datetime(),
|
|
998
|
+
os: z26.string(),
|
|
999
|
+
architecture: z26.string(),
|
|
1000
|
+
environment: z26.string()
|
|
921
1001
|
})
|
|
922
1002
|
);
|
|
923
1003
|
|
|
924
1004
|
// packages/fly-node/src/lib/fly.class.ts
|
|
1005
|
+
var TRANSIENT_FLY_ERRORS = [
|
|
1006
|
+
{ cause: "no capacity available", pattern: /no capacity available/i },
|
|
1007
|
+
{ cause: "builder deadline exceeded", pattern: /deadline_exceeded/i },
|
|
1008
|
+
{
|
|
1009
|
+
cause: "timed out connecting to machine",
|
|
1010
|
+
pattern: /timed out connecting to machine/i
|
|
1011
|
+
},
|
|
1012
|
+
// The status text, not a bare 503: an app whose health check answers
|
|
1013
|
+
// 503 is broken, not unlucky, and must not be deployed three times
|
|
1014
|
+
{ cause: "Fly API 503", pattern: /503 Service Unavailable/i }
|
|
1015
|
+
];
|
|
1016
|
+
var TRANSIENT_RETRY_DELAYS_MS = [1e4, 3e4];
|
|
925
1017
|
var MACHINE_STATE_INTERVAL_MS = 2e3;
|
|
926
1018
|
var MACHINE_STATE_TIMEOUT_MS = 12e4;
|
|
927
1019
|
var Fly = class {
|
|
@@ -1007,7 +1099,9 @@ ${error}`);
|
|
|
1007
1099
|
return await this.version();
|
|
1008
1100
|
} catch (error) {
|
|
1009
1101
|
throw new Error(`[version] something broke
|
|
1010
|
-
${error}
|
|
1102
|
+
${error}`, {
|
|
1103
|
+
cause: error
|
|
1104
|
+
});
|
|
1011
1105
|
}
|
|
1012
1106
|
}
|
|
1013
1107
|
};
|
|
@@ -1034,7 +1128,8 @@ ${error}`);
|
|
|
1034
1128
|
} catch (error) {
|
|
1035
1129
|
throw new Error(
|
|
1036
1130
|
`[create app] something broke, check your apps
|
|
1037
|
-
${error}
|
|
1131
|
+
${error}`,
|
|
1132
|
+
{ cause: error }
|
|
1038
1133
|
);
|
|
1039
1134
|
}
|
|
1040
1135
|
},
|
|
@@ -1060,7 +1155,8 @@ ${error}`
|
|
|
1060
1155
|
} catch (error) {
|
|
1061
1156
|
throw new Error(
|
|
1062
1157
|
`[destroy app] something broke, check your apps
|
|
1063
|
-
${error}
|
|
1158
|
+
${error}`,
|
|
1159
|
+
{ cause: error }
|
|
1064
1160
|
);
|
|
1065
1161
|
}
|
|
1066
1162
|
},
|
|
@@ -1075,7 +1171,7 @@ ${error}`
|
|
|
1075
1171
|
return await this.fetchAllApps("throwOnError");
|
|
1076
1172
|
} catch (error) {
|
|
1077
1173
|
throw new Error(`[list] something broke
|
|
1078
|
-
${error}
|
|
1174
|
+
${error}`, { cause: error });
|
|
1079
1175
|
}
|
|
1080
1176
|
}
|
|
1081
1177
|
};
|
|
@@ -1100,7 +1196,8 @@ ${error}`);
|
|
|
1100
1196
|
} catch (error) {
|
|
1101
1197
|
throw new Error(
|
|
1102
1198
|
`[add certificate] something broke, check your app certificates
|
|
1103
|
-
${error}
|
|
1199
|
+
${error}`,
|
|
1200
|
+
{ cause: error }
|
|
1104
1201
|
);
|
|
1105
1202
|
}
|
|
1106
1203
|
},
|
|
@@ -1118,7 +1215,9 @@ ${error}`
|
|
|
1118
1215
|
return result;
|
|
1119
1216
|
} catch (error) {
|
|
1120
1217
|
throw new Error(`[list certificates] something broke
|
|
1121
|
-
${error}
|
|
1218
|
+
${error}`, {
|
|
1219
|
+
cause: error
|
|
1220
|
+
});
|
|
1122
1221
|
}
|
|
1123
1222
|
},
|
|
1124
1223
|
/**
|
|
@@ -1138,7 +1237,8 @@ ${error}`);
|
|
|
1138
1237
|
} catch (error) {
|
|
1139
1238
|
throw new Error(
|
|
1140
1239
|
`[remove certificate] something broke, check your app certificates
|
|
1141
|
-
${error}
|
|
1240
|
+
${error}`,
|
|
1241
|
+
{ cause: error }
|
|
1142
1242
|
);
|
|
1143
1243
|
}
|
|
1144
1244
|
}
|
|
@@ -1165,7 +1265,9 @@ ${error}`
|
|
|
1165
1265
|
);
|
|
1166
1266
|
} catch (error) {
|
|
1167
1267
|
throw new Error(`[save config] something broke
|
|
1168
|
-
${error}
|
|
1268
|
+
${error}`, {
|
|
1269
|
+
cause: error
|
|
1270
|
+
});
|
|
1169
1271
|
}
|
|
1170
1272
|
},
|
|
1171
1273
|
/**
|
|
@@ -1181,7 +1283,9 @@ ${error}`);
|
|
|
1181
1283
|
return await this.showConfig("throwOnError", options);
|
|
1182
1284
|
} catch (error) {
|
|
1183
1285
|
throw new Error(`[show config] something broke
|
|
1184
|
-
${error}
|
|
1286
|
+
${error}`, {
|
|
1287
|
+
cause: error
|
|
1288
|
+
});
|
|
1185
1289
|
}
|
|
1186
1290
|
}
|
|
1187
1291
|
};
|
|
@@ -1224,7 +1328,7 @@ ${error}`);
|
|
|
1224
1328
|
}
|
|
1225
1329
|
const { appName } = await this.deployApp(options);
|
|
1226
1330
|
this.logger.info(`Application '${appName}' was deployed`);
|
|
1227
|
-
const status = await this.
|
|
1331
|
+
const status = await this.fetchAppLookup("throwOnError", {
|
|
1228
1332
|
app: appName
|
|
1229
1333
|
});
|
|
1230
1334
|
return DeployResponseSchema.parse({
|
|
@@ -1235,7 +1339,8 @@ ${error}`);
|
|
|
1235
1339
|
} catch (error) {
|
|
1236
1340
|
throw new Error(
|
|
1237
1341
|
`[deploy] something broke, check your ${isBuildOnly ? "builds" : "deployments"}
|
|
1238
|
-
${error}
|
|
1342
|
+
${error}`,
|
|
1343
|
+
{ cause: error }
|
|
1239
1344
|
);
|
|
1240
1345
|
}
|
|
1241
1346
|
};
|
|
@@ -1256,7 +1361,9 @@ ${error}`
|
|
|
1256
1361
|
return await this.fetchAppIps("throwOnError", options);
|
|
1257
1362
|
} catch (error) {
|
|
1258
1363
|
throw new Error(`[list ips] something broke
|
|
1259
|
-
${error}
|
|
1364
|
+
${error}`, {
|
|
1365
|
+
cause: error
|
|
1366
|
+
});
|
|
1260
1367
|
}
|
|
1261
1368
|
},
|
|
1262
1369
|
/**
|
|
@@ -1266,7 +1373,8 @@ ${error}`);
|
|
|
1266
1373
|
* safe on every deploy rather than only on create. That matters because
|
|
1267
1374
|
* `flyctl` allocates addresses only for an app it creates itself — an app
|
|
1268
1375
|
* that arrives any other way, such as a registry push auto-creating it,
|
|
1269
|
-
* deploys green and answers nothing.
|
|
1376
|
+
* deploys green and answers nothing. `deploy` runs it before every
|
|
1377
|
+
* deploy that is not build-only.
|
|
1270
1378
|
*
|
|
1271
1379
|
* @param options - The application, and which addresses to ensure
|
|
1272
1380
|
* @returns The addresses the application holds afterwards
|
|
@@ -1278,19 +1386,23 @@ ${error}`);
|
|
|
1278
1386
|
const { sharedV4 = true, v6 = true } = options ?? {};
|
|
1279
1387
|
const existing = await this.fetchAppIps("throwOnError", options);
|
|
1280
1388
|
const has = (...types) => existing.some((ip) => types.includes(ip.type));
|
|
1389
|
+
let allocated = false;
|
|
1281
1390
|
if (sharedV4 && !has("v4", "shared_v4")) {
|
|
1282
1391
|
await this.allocateIp("allocate-v4", options);
|
|
1283
1392
|
this.logger.info("Allocated a shared IPv4 address");
|
|
1393
|
+
allocated = true;
|
|
1284
1394
|
}
|
|
1285
1395
|
if (v6 && !has("v6")) {
|
|
1286
1396
|
await this.allocateIp("allocate-v6", options);
|
|
1287
1397
|
this.logger.info("Allocated a dedicated IPv6 address");
|
|
1398
|
+
allocated = true;
|
|
1288
1399
|
}
|
|
1289
|
-
return await this.fetchAppIps("throwOnError", options);
|
|
1400
|
+
return allocated ? await this.fetchAppIps("throwOnError", options) : existing;
|
|
1290
1401
|
} catch (error) {
|
|
1291
1402
|
throw new Error(
|
|
1292
1403
|
`[ensure ips] something broke, check your app addresses
|
|
1293
|
-
${error}
|
|
1404
|
+
${error}`,
|
|
1405
|
+
{ cause: error }
|
|
1294
1406
|
);
|
|
1295
1407
|
}
|
|
1296
1408
|
}
|
|
@@ -1313,7 +1425,9 @@ ${error}`
|
|
|
1313
1425
|
this.logger.info(`Machine '${machineId}' in app '${app}' was started`);
|
|
1314
1426
|
} catch (error) {
|
|
1315
1427
|
throw new Error(`[start machine] something broke
|
|
1316
|
-
${error}
|
|
1428
|
+
${error}`, {
|
|
1429
|
+
cause: error
|
|
1430
|
+
});
|
|
1317
1431
|
}
|
|
1318
1432
|
},
|
|
1319
1433
|
/**
|
|
@@ -1330,7 +1444,9 @@ ${error}`);
|
|
|
1330
1444
|
this.logger.info(`Machine '${machineId}' in app '${app}' was stopped`);
|
|
1331
1445
|
} catch (error) {
|
|
1332
1446
|
throw new Error(`[stop machine] something broke
|
|
1333
|
-
${error}
|
|
1447
|
+
${error}`, {
|
|
1448
|
+
cause: error
|
|
1449
|
+
});
|
|
1334
1450
|
}
|
|
1335
1451
|
},
|
|
1336
1452
|
/**
|
|
@@ -1353,7 +1469,9 @@ ${error}`);
|
|
|
1353
1469
|
);
|
|
1354
1470
|
} catch (error) {
|
|
1355
1471
|
throw new Error(`[restart machine] something broke
|
|
1356
|
-
${error}
|
|
1472
|
+
${error}`, {
|
|
1473
|
+
cause: error
|
|
1474
|
+
});
|
|
1357
1475
|
}
|
|
1358
1476
|
},
|
|
1359
1477
|
/**
|
|
@@ -1374,7 +1492,9 @@ ${error}`);
|
|
|
1374
1492
|
this.logger.info(`Machine '${machineId}' in app '${app}' was updated`);
|
|
1375
1493
|
} catch (error) {
|
|
1376
1494
|
throw new Error(`[update machine] something broke
|
|
1377
|
-
${error}
|
|
1495
|
+
${error}`, {
|
|
1496
|
+
cause: error
|
|
1497
|
+
});
|
|
1378
1498
|
}
|
|
1379
1499
|
}
|
|
1380
1500
|
};
|
|
@@ -1408,7 +1528,9 @@ ${error}`);
|
|
|
1408
1528
|
return await this.sshExec(app, command);
|
|
1409
1529
|
} catch (error) {
|
|
1410
1530
|
throw new Error(`[ssh exec] something broke
|
|
1411
|
-
${error}
|
|
1531
|
+
${error}`, {
|
|
1532
|
+
cause: error
|
|
1533
|
+
});
|
|
1412
1534
|
}
|
|
1413
1535
|
}
|
|
1414
1536
|
};
|
|
@@ -1434,7 +1556,8 @@ ${error}`);
|
|
|
1434
1556
|
} catch (error) {
|
|
1435
1557
|
throw new Error(
|
|
1436
1558
|
`[set secrets] something broke, check your app secrets
|
|
1437
|
-
${error}
|
|
1559
|
+
${error}`,
|
|
1560
|
+
{ cause: error }
|
|
1438
1561
|
);
|
|
1439
1562
|
}
|
|
1440
1563
|
},
|
|
@@ -1457,7 +1580,9 @@ ${error}`
|
|
|
1457
1580
|
this.logger.info(`Staged secrets were deployed for '${app}'`);
|
|
1458
1581
|
} catch (error) {
|
|
1459
1582
|
throw new Error(`[deploy secrets] something broke
|
|
1460
|
-
${error}
|
|
1583
|
+
${error}`, {
|
|
1584
|
+
cause: error
|
|
1585
|
+
});
|
|
1461
1586
|
}
|
|
1462
1587
|
},
|
|
1463
1588
|
/**
|
|
@@ -1474,7 +1599,9 @@ ${error}`);
|
|
|
1474
1599
|
return result;
|
|
1475
1600
|
} catch (error) {
|
|
1476
1601
|
throw new Error(`[list secrets] something broke
|
|
1477
|
-
${error}
|
|
1602
|
+
${error}`, {
|
|
1603
|
+
cause: error
|
|
1604
|
+
});
|
|
1478
1605
|
}
|
|
1479
1606
|
},
|
|
1480
1607
|
/**
|
|
@@ -1495,7 +1622,8 @@ ${error}`);
|
|
|
1495
1622
|
} catch (error) {
|
|
1496
1623
|
throw new Error(
|
|
1497
1624
|
`[unset secrets] something broke, check your app secrets
|
|
1498
|
-
${error}
|
|
1625
|
+
${error}`,
|
|
1626
|
+
{ cause: error }
|
|
1499
1627
|
);
|
|
1500
1628
|
}
|
|
1501
1629
|
}
|
|
@@ -1608,7 +1736,7 @@ ${error}`);
|
|
|
1608
1736
|
lookupApp = appConfig.app;
|
|
1609
1737
|
}
|
|
1610
1738
|
if (lookupApp) {
|
|
1611
|
-
const status = await this.
|
|
1739
|
+
const status = await this.fetchAppLookup("nullOnError", {
|
|
1612
1740
|
app: lookupApp
|
|
1613
1741
|
});
|
|
1614
1742
|
if (status) {
|
|
@@ -1710,6 +1838,10 @@ ${error}`);
|
|
|
1710
1838
|
);
|
|
1711
1839
|
}
|
|
1712
1840
|
}
|
|
1841
|
+
const servesTraffic = !!appConfig.httpService || (appConfig.services?.length ?? 0) > 0;
|
|
1842
|
+
if (!options?.buildOnly && servesTraffic) {
|
|
1843
|
+
await this.ips.ensure({ app: appName });
|
|
1844
|
+
}
|
|
1713
1845
|
const args = ["deploy", "--app", appName, "--config", deployConfig];
|
|
1714
1846
|
if (options?.region) {
|
|
1715
1847
|
args.push("--region", options.region);
|
|
@@ -1736,10 +1868,10 @@ ${error}`);
|
|
|
1736
1868
|
this.logger.info(
|
|
1737
1869
|
options?.buildOnly ? `Building image for '${appName}'...` : `Deploying '${appName}'...`
|
|
1738
1870
|
);
|
|
1739
|
-
const output = await this.execFly(
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
);
|
|
1871
|
+
const output = await this.execFly(args, {
|
|
1872
|
+
streamStrategy: options?.buildOnly ? "combined" : "stdout",
|
|
1873
|
+
retry: true
|
|
1874
|
+
});
|
|
1743
1875
|
const imageRef = options?.buildOnly ? output?.match(/registry\.fly\.io\/\S+/)?.[0] : void 0;
|
|
1744
1876
|
return { appName, imageRef };
|
|
1745
1877
|
}
|
|
@@ -1785,7 +1917,7 @@ ${error}`);
|
|
|
1785
1917
|
* @throws An error if the secrets cannot be set
|
|
1786
1918
|
*/
|
|
1787
1919
|
async setAppSecrets(secrets, options) {
|
|
1788
|
-
const status = await this.
|
|
1920
|
+
const status = await this.fetchAppLookup("throwOnError", options);
|
|
1789
1921
|
const args = ["secrets", "set"];
|
|
1790
1922
|
args.push(...this.getAppOrConfigArgs(options));
|
|
1791
1923
|
if (options?.stage) {
|
|
@@ -1794,7 +1926,7 @@ ${error}`);
|
|
|
1794
1926
|
for (const [key, value] of Object.entries(secrets)) {
|
|
1795
1927
|
args.push(`${key}=${this.safeArg(value)}`);
|
|
1796
1928
|
}
|
|
1797
|
-
await this.execFly(args);
|
|
1929
|
+
await this.execFly(args, { retry: options?.stage === true });
|
|
1798
1930
|
return NameSchema.parse(status.name);
|
|
1799
1931
|
}
|
|
1800
1932
|
/**
|
|
@@ -1803,7 +1935,7 @@ ${error}`);
|
|
|
1803
1935
|
* @throws An error if the secrets cannot be unset
|
|
1804
1936
|
*/
|
|
1805
1937
|
async unsetAppSecrets(keys, options) {
|
|
1806
|
-
const status = await this.
|
|
1938
|
+
const status = await this.fetchAppLookup("throwOnError", options);
|
|
1807
1939
|
const args = ["secrets", "unset"];
|
|
1808
1940
|
args.push(...this.getAppOrConfigArgs(options));
|
|
1809
1941
|
if (options?.stage) {
|
|
@@ -1819,7 +1951,7 @@ ${error}`);
|
|
|
1819
1951
|
* @throws An error if the domain cannot be added
|
|
1820
1952
|
*/
|
|
1821
1953
|
async addAppCertificate(hostname, options) {
|
|
1822
|
-
const status = await this.
|
|
1954
|
+
const status = await this.fetchAppLookup("throwOnError", options);
|
|
1823
1955
|
const args = ["certs", "add", hostname];
|
|
1824
1956
|
args.push(...this.getAppOrConfigArgs(options));
|
|
1825
1957
|
args.push("--json");
|
|
@@ -1856,7 +1988,7 @@ ${error}`);
|
|
|
1856
1988
|
args.push("--json");
|
|
1857
1989
|
try {
|
|
1858
1990
|
return await IpsListTransformedResponseSchema.parseAsync(
|
|
1859
|
-
await this.execFly(args)
|
|
1991
|
+
await this.execFly(args, { retry: true })
|
|
1860
1992
|
);
|
|
1861
1993
|
} catch (error) {
|
|
1862
1994
|
if (onError === "throwOnError") {
|
|
@@ -1871,7 +2003,7 @@ ${error}`);
|
|
|
1871
2003
|
* @throws An error if the domain cannot be removed
|
|
1872
2004
|
*/
|
|
1873
2005
|
async removeAppCertificate(hostname, options) {
|
|
1874
|
-
const status = await this.
|
|
2006
|
+
const status = await this.fetchAppLookup("throwOnError", options);
|
|
1875
2007
|
const args = ["certs", "remove", hostname];
|
|
1876
2008
|
args.push(...this.getAppOrConfigArgs(options));
|
|
1877
2009
|
args.push("--yes");
|
|
@@ -1946,7 +2078,7 @@ ${error}`);
|
|
|
1946
2078
|
async waitForMachineState(app, machineId, states) {
|
|
1947
2079
|
const deadline = Date.now() + MACHINE_STATE_TIMEOUT_MS;
|
|
1948
2080
|
while (Date.now() < deadline) {
|
|
1949
|
-
const status = await this.
|
|
2081
|
+
const status = await this.fetchAppLookup("nullOnError", { app });
|
|
1950
2082
|
const machine = status?.machines.find(({ id }) => id === machineId);
|
|
1951
2083
|
if (machine && states.includes(machine.state)) {
|
|
1952
2084
|
return;
|
|
@@ -2057,6 +2189,27 @@ ${error}`);
|
|
|
2057
2189
|
this.logger.info(`Failed to parse response:
|
|
2058
2190
|
${error.message}`);
|
|
2059
2191
|
this.logger.info(`Raw response:
|
|
2192
|
+
${JSON.stringify(response, null, 2)}`);
|
|
2193
|
+
}
|
|
2194
|
+
return null;
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
async fetchAppLookup(onError, options) {
|
|
2198
|
+
const args = ["status"];
|
|
2199
|
+
args.push(...this.getAppOrConfigArgs(options));
|
|
2200
|
+
args.push("--json");
|
|
2201
|
+
let response = null;
|
|
2202
|
+
try {
|
|
2203
|
+
response = await this.execFly(args);
|
|
2204
|
+
return statusLookupSchema.parse(response);
|
|
2205
|
+
} catch (error) {
|
|
2206
|
+
if (onError === "throwOnError") {
|
|
2207
|
+
throw error;
|
|
2208
|
+
}
|
|
2209
|
+
if (error instanceof ZodError) {
|
|
2210
|
+
this.logger.info(`Failed to parse response:
|
|
2211
|
+
${error.message}`);
|
|
2212
|
+
this.logger.info(`Raw response:
|
|
2060
2213
|
${JSON.stringify(response, null, 2)}`);
|
|
2061
2214
|
}
|
|
2062
2215
|
return null;
|
|
@@ -2189,33 +2342,32 @@ ${JSON.stringify(response, null, 2)}`);
|
|
|
2189
2342
|
}
|
|
2190
2343
|
const flyCmd = "flyctl";
|
|
2191
2344
|
const toLogCmd = `${flyCmd} ${args.join(" ")}`;
|
|
2345
|
+
const { retry = false, ...execOpts } = options ?? {};
|
|
2192
2346
|
let output = "";
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
const
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
${errorMsg}`);
|
|
2347
|
+
for (let attempt = 1; ; attempt++) {
|
|
2348
|
+
try {
|
|
2349
|
+
output = await this.spawnFly(flyCmd, args, toLogCmd, execOpts);
|
|
2350
|
+
break;
|
|
2351
|
+
} catch (error) {
|
|
2352
|
+
const errorMsg = error.message;
|
|
2353
|
+
this.traceCLI("RESULT", errorMsg);
|
|
2354
|
+
const cause = retry ? this.transientCause(error) : null;
|
|
2355
|
+
const delay = TRANSIENT_RETRY_DELAYS_MS[attempt - 1];
|
|
2356
|
+
if (cause && delay !== void 0) {
|
|
2357
|
+
this.logger.info(
|
|
2358
|
+
`Transient Fly error (${cause}), retrying in ${delay / 1e3}s (attempt ${attempt + 1} of ${TRANSIENT_RETRY_DELAYS_MS.length + 1}): ${toLogCmd}`
|
|
2359
|
+
);
|
|
2360
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
2361
|
+
continue;
|
|
2362
|
+
}
|
|
2363
|
+
if (onError === "throwOnError") {
|
|
2364
|
+
throw new Error(`Command failed: ${toLogCmd}
|
|
2365
|
+
${errorMsg}`, {
|
|
2366
|
+
cause: error
|
|
2367
|
+
});
|
|
2368
|
+
}
|
|
2369
|
+
return null;
|
|
2217
2370
|
}
|
|
2218
|
-
return null;
|
|
2219
2371
|
}
|
|
2220
2372
|
try {
|
|
2221
2373
|
return JSON.parse(output);
|
|
@@ -2229,6 +2381,55 @@ ${errorMsg}`);
|
|
|
2229
2381
|
}
|
|
2230
2382
|
return void 0;
|
|
2231
2383
|
}
|
|
2384
|
+
/**
|
|
2385
|
+
* @private
|
|
2386
|
+
* Run one fly command and assemble its output
|
|
2387
|
+
*
|
|
2388
|
+
* @returns The output selected by `streamStrategy`
|
|
2389
|
+
* @throws An error if the command fails
|
|
2390
|
+
*/
|
|
2391
|
+
async spawnFly(flyCmd, args, toLogCmd, options) {
|
|
2392
|
+
this.traceCLI("CALL", toLogCmd);
|
|
2393
|
+
if (options.prompt) {
|
|
2394
|
+
const output = await spawnPty(flyCmd, args, { prompt: options.prompt });
|
|
2395
|
+
this.traceCLI("RESULT", output);
|
|
2396
|
+
return output;
|
|
2397
|
+
}
|
|
2398
|
+
const { streamStrategy = "stdout", ...spawnOpts } = options;
|
|
2399
|
+
const result = await spawn(flyCmd, args, {
|
|
2400
|
+
...spawnOpts,
|
|
2401
|
+
streamToConsole: this.logger.streamToConsole
|
|
2402
|
+
});
|
|
2403
|
+
const stdout = result.stdout.trim();
|
|
2404
|
+
const stderr = result.stderr.trim();
|
|
2405
|
+
this.traceCLI("RESULT", `${stdout}${stderr ? `
|
|
2406
|
+
${stderr}` : ""}`);
|
|
2407
|
+
return streamStrategy === "combined" ? `${stdout}
|
|
2408
|
+
${stderr}` : streamStrategy === "stderr" ? stderr : stdout;
|
|
2409
|
+
}
|
|
2410
|
+
/**
|
|
2411
|
+
* @private
|
|
2412
|
+
* Name the transient Fly error behind a failed command, if it was one.
|
|
2413
|
+
*
|
|
2414
|
+
* Only the error flyctl ended with counts: from its last `Error` line to
|
|
2415
|
+
* the end of stderr, or the last few lines when there is none. A deploy
|
|
2416
|
+
* streams the app's own output and errors flyctl recovered from, and
|
|
2417
|
+
* matching those would repeat a deploy that failed for a real reason.
|
|
2418
|
+
*
|
|
2419
|
+
* @returns The cause, or `null` when the failure is not a known transient one
|
|
2420
|
+
*/
|
|
2421
|
+
transientCause(error) {
|
|
2422
|
+
let text;
|
|
2423
|
+
if (error instanceof SpawnError) {
|
|
2424
|
+
const lines = error.stderr.split(/\r?\n/).filter((line) => line.trim());
|
|
2425
|
+
const errorLines = lines.map((line) => /^\s*Error\b/.test(line));
|
|
2426
|
+
const last = errorLines.lastIndexOf(true);
|
|
2427
|
+
text = lines.slice(last >= 0 ? last : -3).join("\n");
|
|
2428
|
+
} else {
|
|
2429
|
+
text = String(error?.message ?? error);
|
|
2430
|
+
}
|
|
2431
|
+
return TRANSIENT_FLY_ERRORS.find(({ pattern }) => pattern.test(text))?.cause ?? null;
|
|
2432
|
+
}
|
|
2232
2433
|
/**
|
|
2233
2434
|
* @private
|
|
2234
2435
|
* Get the arguments for `AppOrConfig` options
|
|
@@ -2376,6 +2577,8 @@ ${errorMsg}`);
|
|
|
2376
2577
|
}
|
|
2377
2578
|
};
|
|
2378
2579
|
export {
|
|
2580
|
+
AppIpAddressSchema,
|
|
2581
|
+
AppIpAddressesApiResponseSchema,
|
|
2379
2582
|
CertificateApiResponseSchema,
|
|
2380
2583
|
CertificateListApiResponseSchema,
|
|
2381
2584
|
DnsInstructionsSchema,
|