@cdwr/fly-node 0.1.0 → 0.2.0
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 +12 -0
- package/README.md +8 -1
- package/index.cjs +237 -143
- package/index.js +237 -141
- package/package.json +1 -1
- package/src/lib/fly.class.d.ts +6 -0
- package/src/lib/types.d.ts +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## 0.2.0 (2025-01-30)
|
|
2
|
+
|
|
3
|
+
### ✨ Features
|
|
4
|
+
|
|
5
|
+
- **fly-node:** optional opt out depot builder on deploy ([5bd15a0e1](https://github.com/codeware-sthlm/codeware/commit/5bd15a0e1))
|
|
6
|
+
|
|
7
|
+
### 🐞 Bug Fixes
|
|
8
|
+
|
|
9
|
+
- **fly-node:** fix fly deploy command typo ([fa79f4daf](https://github.com/codeware-sthlm/codeware/commit/fa79f4daf))
|
|
10
|
+
- **fly-node:** use spawn pty for interactive prompts ([3998bc606](https://github.com/codeware-sthlm/codeware/commit/3998bc606))
|
|
11
|
+
- **fly-node:** detach postgres must handle interactive prompt ([6e2c79036](https://github.com/codeware-sthlm/codeware/commit/6e2c79036))
|
|
12
|
+
|
|
1
13
|
## 0.1.0 (2025-01-12)
|
|
2
14
|
|
|
3
15
|
### ✨ Features
|
package/README.md
CHANGED
|
@@ -207,7 +207,14 @@ const response = await fly.deploy({
|
|
|
207
207
|
postgres: 'db-app'
|
|
208
208
|
});
|
|
209
209
|
|
|
210
|
-
//
|
|
210
|
+
// Opt out of the default depot builder
|
|
211
|
+
const response = await fly.deploy({
|
|
212
|
+
app: 'pr-19-foo-app',
|
|
213
|
+
config: 'apps/foo-app/fly.toml',
|
|
214
|
+
optOutDepotBuilder: true
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// With options that could be a pull request preview deployment
|
|
211
218
|
const response = await fly.deploy({
|
|
212
219
|
app: 'pr-19-foo-app',
|
|
213
220
|
config: 'apps/foo-app/fly.toml',
|
package/index.cjs
CHANGED
|
@@ -65,24 +65,91 @@ var import_child_process2 = require("child_process");
|
|
|
65
65
|
var import_util3 = require("util");
|
|
66
66
|
var exec = (0, import_util3.promisify)(import_child_process2.exec);
|
|
67
67
|
|
|
68
|
+
// packages/core/src/lib/utils/promisified-spawn.ts
|
|
69
|
+
var import_child_process3 = require("child_process");
|
|
70
|
+
function spawn(command, args, options) {
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
const process2 = (0, import_child_process3.spawn)(command, args, {
|
|
73
|
+
...options,
|
|
74
|
+
stdio: "pipe"
|
|
75
|
+
});
|
|
76
|
+
const stdoutChunks = [];
|
|
77
|
+
const stderrChunks = [];
|
|
78
|
+
process2.stdout.on("data", (data) => {
|
|
79
|
+
stdoutChunks.push(Buffer.from(data));
|
|
80
|
+
});
|
|
81
|
+
process2.stderr.on("data", (data) => {
|
|
82
|
+
stderrChunks.push(Buffer.from(data));
|
|
83
|
+
});
|
|
84
|
+
process2.on("close", (code) => {
|
|
85
|
+
const stdout = Buffer.concat(stdoutChunks).toString();
|
|
86
|
+
const stderr = Buffer.concat(stderrChunks).toString();
|
|
87
|
+
if (code === 0) {
|
|
88
|
+
resolve({ stdout, stderr });
|
|
89
|
+
} else {
|
|
90
|
+
reject(new Error(`Process exited with code ${code}
|
|
91
|
+
Error: ${stderr}`));
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
process2.on("error", reject);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
68
98
|
// packages/core/src/lib/utils/run-command.ts
|
|
69
99
|
var import_testing = require("@nx/plugin/testing");
|
|
70
100
|
|
|
101
|
+
// packages/core/src/lib/utils/spawn-pty.ts
|
|
102
|
+
var import_node_pty_prebuilt_multiarch = require("@homebridge/node-pty-prebuilt-multiarch");
|
|
103
|
+
function spawnPty(command, args, options) {
|
|
104
|
+
return new Promise((resolve, reject) => {
|
|
105
|
+
const ptyData = [];
|
|
106
|
+
const ptyProcess = (0, import_node_pty_prebuilt_multiarch.spawn)(command, args, {
|
|
107
|
+
cwd: process.cwd(),
|
|
108
|
+
encoding: "utf-8",
|
|
109
|
+
env: process.env
|
|
110
|
+
});
|
|
111
|
+
ptyProcess.onData((data) => {
|
|
112
|
+
ptyData.push(data);
|
|
113
|
+
if (options?.prompt) {
|
|
114
|
+
const answer = options.prompt(data);
|
|
115
|
+
if (answer) {
|
|
116
|
+
ptyProcess.write(`${answer}
|
|
117
|
+
`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
ptyProcess.onExit(({ exitCode }) => {
|
|
122
|
+
const output = ptyData.join("");
|
|
123
|
+
if (exitCode === 0) {
|
|
124
|
+
resolve(output);
|
|
125
|
+
} else {
|
|
126
|
+
reject(
|
|
127
|
+
new Error(`Process exited with code ${exitCode}
|
|
128
|
+
Output: ${output}`)
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
71
135
|
// packages/core/src/lib/utils/whoami.ts
|
|
72
136
|
var import_npm_whoami = __toESM(require("npm-whoami"), 1);
|
|
73
137
|
|
|
74
138
|
// packages/fly-node/src/lib/fly.class.ts
|
|
75
|
-
var
|
|
139
|
+
var import_zod30 = require("zod");
|
|
76
140
|
|
|
77
|
-
// packages/core/src/lib/zod/
|
|
141
|
+
// packages/core/src/lib/zod/create-lowercase-schema.ts
|
|
78
142
|
var import_zod = require("zod");
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
143
|
+
|
|
144
|
+
// packages/core/src/lib/zod/json.schema.ts
|
|
145
|
+
var import_zod2 = require("zod");
|
|
146
|
+
var LiteralSchema = import_zod2.z.union([import_zod2.z.string(), import_zod2.z.number(), import_zod2.z.boolean(), import_zod2.z.null()]);
|
|
147
|
+
var JsonSchema = import_zod2.z.lazy(
|
|
148
|
+
() => import_zod2.z.union([LiteralSchema, import_zod2.z.array(JsonSchema), import_zod2.z.record(JsonSchema)])
|
|
82
149
|
);
|
|
83
150
|
|
|
84
151
|
// packages/core/src/lib/zod/with-camel-case.preprocess.ts
|
|
85
|
-
var
|
|
152
|
+
var import_zod3 = require("zod");
|
|
86
153
|
var toCamelCase = (str, specialCases = {}) => {
|
|
87
154
|
if (specialCases[str]) {
|
|
88
155
|
return specialCases[str];
|
|
@@ -129,7 +196,7 @@ var transformKeys = (options) => {
|
|
|
129
196
|
};
|
|
130
197
|
var withCamelCase = (schema, options = {}) => {
|
|
131
198
|
const { preserve = [], specialCases = {} } = options;
|
|
132
|
-
return
|
|
199
|
+
return import_zod3.z.preprocess(
|
|
133
200
|
(data) => transformKeys({
|
|
134
201
|
currentPath: [],
|
|
135
202
|
data,
|
|
@@ -141,42 +208,42 @@ var withCamelCase = (schema, options = {}) => {
|
|
|
141
208
|
};
|
|
142
209
|
|
|
143
210
|
// packages/core/src/lib/zod/with-env-vars.preprocess.ts
|
|
144
|
-
var
|
|
211
|
+
var import_zod4 = require("zod");
|
|
145
212
|
|
|
146
213
|
// packages/core/src/lib/zod/with-replace-all.preprocess.ts
|
|
147
|
-
var
|
|
214
|
+
var import_zod5 = require("zod");
|
|
148
215
|
|
|
149
216
|
// packages/fly-node/src/lib/schemas/apps-create.schema.ts
|
|
150
|
-
var
|
|
217
|
+
var import_zod7 = require("zod");
|
|
151
218
|
var AppsCreateTransformedResponseSchema = withCamelCase(
|
|
152
|
-
|
|
153
|
-
id:
|
|
154
|
-
name:
|
|
155
|
-
organization:
|
|
156
|
-
id:
|
|
157
|
-
name:
|
|
219
|
+
import_zod7.z.object({
|
|
220
|
+
id: import_zod7.z.string(),
|
|
221
|
+
name: import_zod7.z.string(),
|
|
222
|
+
organization: import_zod7.z.object({
|
|
223
|
+
id: import_zod7.z.string(),
|
|
224
|
+
name: import_zod7.z.string()
|
|
158
225
|
})
|
|
159
226
|
})
|
|
160
227
|
);
|
|
161
228
|
|
|
162
229
|
// packages/fly-node/src/lib/schemas/apps-list.schema.ts
|
|
163
|
-
var
|
|
164
|
-
var AppsListTransformedResponseSchema =
|
|
230
|
+
var import_zod9 = require("zod");
|
|
231
|
+
var AppsListTransformedResponseSchema = import_zod9.z.array(
|
|
165
232
|
withCamelCase(
|
|
166
|
-
|
|
167
|
-
id:
|
|
168
|
-
name:
|
|
169
|
-
status:
|
|
170
|
-
deployed:
|
|
171
|
-
hostname:
|
|
172
|
-
organization:
|
|
173
|
-
name:
|
|
174
|
-
slug:
|
|
233
|
+
import_zod9.z.object({
|
|
234
|
+
id: import_zod9.z.string(),
|
|
235
|
+
name: import_zod9.z.string(),
|
|
236
|
+
status: import_zod9.z.string(),
|
|
237
|
+
deployed: import_zod9.z.boolean(),
|
|
238
|
+
hostname: import_zod9.z.string(),
|
|
239
|
+
organization: import_zod9.z.object({
|
|
240
|
+
name: import_zod9.z.string(),
|
|
241
|
+
slug: import_zod9.z.string()
|
|
175
242
|
}),
|
|
176
|
-
currentRelease:
|
|
177
|
-
|
|
178
|
-
status:
|
|
179
|
-
createdAt:
|
|
243
|
+
currentRelease: import_zod9.z.nullable(
|
|
244
|
+
import_zod9.z.object({
|
|
245
|
+
status: import_zod9.z.string(),
|
|
246
|
+
createdAt: import_zod9.z.string().datetime()
|
|
180
247
|
})
|
|
181
248
|
)
|
|
182
249
|
})
|
|
@@ -184,46 +251,46 @@ var AppsListTransformedResponseSchema = import_zod8.z.array(
|
|
|
184
251
|
);
|
|
185
252
|
|
|
186
253
|
// packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
|
|
187
|
-
var
|
|
254
|
+
var import_zod13 = require("zod");
|
|
188
255
|
|
|
189
256
|
// packages/fly-node/src/lib/schemas/certs-list.schema.ts
|
|
190
|
-
var
|
|
191
|
-
var CertsListFlyResponseElementSchema =
|
|
192
|
-
createdAt:
|
|
193
|
-
hostname:
|
|
194
|
-
clientStatus:
|
|
257
|
+
var import_zod11 = require("zod");
|
|
258
|
+
var CertsListFlyResponseElementSchema = import_zod11.z.object({
|
|
259
|
+
createdAt: import_zod11.z.string().datetime(),
|
|
260
|
+
hostname: import_zod11.z.string(),
|
|
261
|
+
clientStatus: import_zod11.z.string()
|
|
195
262
|
});
|
|
196
|
-
var CertsListTransformedResponseSchema =
|
|
263
|
+
var CertsListTransformedResponseSchema = import_zod11.z.array(
|
|
197
264
|
withCamelCase(CertsListFlyResponseElementSchema)
|
|
198
265
|
);
|
|
199
266
|
|
|
200
267
|
// packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
|
|
201
|
-
var CertsListWithAppTransformedResponseSchema =
|
|
268
|
+
var CertsListWithAppTransformedResponseSchema = import_zod13.z.array(
|
|
202
269
|
withCamelCase(
|
|
203
270
|
CertsListFlyResponseElementSchema.extend({
|
|
204
|
-
app:
|
|
271
|
+
app: import_zod13.z.string()
|
|
205
272
|
})
|
|
206
273
|
)
|
|
207
274
|
);
|
|
208
275
|
|
|
209
276
|
// packages/fly-node/src/lib/schemas/config-show.schema.ts
|
|
210
|
-
var
|
|
277
|
+
var import_zod15 = require("zod");
|
|
211
278
|
var ConfigShowResponseSchema = withCamelCase(
|
|
212
|
-
|
|
213
|
-
app:
|
|
214
|
-
primaryRegion:
|
|
215
|
-
build:
|
|
216
|
-
|
|
217
|
-
args:
|
|
218
|
-
dockerfile:
|
|
219
|
-
image:
|
|
279
|
+
import_zod15.z.object({
|
|
280
|
+
app: import_zod15.z.string(),
|
|
281
|
+
primaryRegion: import_zod15.z.string().optional(),
|
|
282
|
+
build: import_zod15.z.record(import_zod15.z.string(), import_zod15.z.any()).optional().or(
|
|
283
|
+
import_zod15.z.object({
|
|
284
|
+
args: import_zod15.z.record(import_zod15.z.string(), import_zod15.z.string()).optional(),
|
|
285
|
+
dockerfile: import_zod15.z.string().optional(),
|
|
286
|
+
image: import_zod15.z.string().optional()
|
|
220
287
|
})
|
|
221
288
|
),
|
|
222
|
-
deploy:
|
|
223
|
-
env:
|
|
224
|
-
httpService:
|
|
225
|
-
mounts:
|
|
226
|
-
services:
|
|
289
|
+
deploy: import_zod15.z.record(import_zod15.z.string(), import_zod15.z.any()).optional().or(import_zod15.z.object({ strategy: import_zod15.z.string().optional() })),
|
|
290
|
+
env: import_zod15.z.record(import_zod15.z.string(), import_zod15.z.string()).optional(),
|
|
291
|
+
httpService: import_zod15.z.record(import_zod15.z.string(), import_zod15.z.any()).optional(),
|
|
292
|
+
mounts: import_zod15.z.record(import_zod15.z.string(), import_zod15.z.any()).optional(),
|
|
293
|
+
services: import_zod15.z.array(import_zod15.z.record(import_zod15.z.string(), import_zod15.z.any())).optional()
|
|
227
294
|
}),
|
|
228
295
|
{
|
|
229
296
|
preserve: ["build.args", "env"]
|
|
@@ -231,115 +298,115 @@ var ConfigShowResponseSchema = withCamelCase(
|
|
|
231
298
|
);
|
|
232
299
|
|
|
233
300
|
// packages/fly-node/src/lib/schemas/deploy.schema.ts
|
|
234
|
-
var
|
|
235
|
-
var DeployResponseSchema =
|
|
236
|
-
app:
|
|
237
|
-
hostname:
|
|
238
|
-
url:
|
|
301
|
+
var import_zod16 = require("zod");
|
|
302
|
+
var DeployResponseSchema = import_zod16.z.object({
|
|
303
|
+
app: import_zod16.z.string(),
|
|
304
|
+
hostname: import_zod16.z.string(),
|
|
305
|
+
url: import_zod16.z.string().url()
|
|
239
306
|
});
|
|
240
307
|
|
|
241
308
|
// packages/fly-node/src/lib/schemas/helper-schemas.ts
|
|
242
|
-
var
|
|
243
|
-
var AllowEmptyUrlSchema =
|
|
244
|
-
var NameSchema =
|
|
309
|
+
var import_zod17 = require("zod");
|
|
310
|
+
var AllowEmptyUrlSchema = import_zod17.z.string().url().or(import_zod17.z.literal(""));
|
|
311
|
+
var NameSchema = import_zod17.z.string({ message: "App name must be a valid slug" }).regex(/^[a-z0-9-]+$/);
|
|
245
312
|
|
|
246
313
|
// packages/fly-node/src/lib/schemas/postgres-list.ts
|
|
247
|
-
var
|
|
248
|
-
var PostgresListTransformedResponseSchema =
|
|
314
|
+
var import_zod19 = require("zod");
|
|
315
|
+
var PostgresListTransformedResponseSchema = import_zod19.z.array(
|
|
249
316
|
withCamelCase(
|
|
250
|
-
|
|
251
|
-
deployed:
|
|
252
|
-
hostname:
|
|
253
|
-
id:
|
|
254
|
-
name:
|
|
255
|
-
organization:
|
|
256
|
-
status:
|
|
257
|
-
version:
|
|
317
|
+
import_zod19.z.object({
|
|
318
|
+
deployed: import_zod19.z.boolean(),
|
|
319
|
+
hostname: import_zod19.z.string(),
|
|
320
|
+
id: import_zod19.z.string(),
|
|
321
|
+
name: import_zod19.z.string(),
|
|
322
|
+
organization: import_zod19.z.object({ id: import_zod19.z.string(), slug: import_zod19.z.string() }),
|
|
323
|
+
status: import_zod19.z.string(),
|
|
324
|
+
version: import_zod19.z.number()
|
|
258
325
|
})
|
|
259
326
|
)
|
|
260
327
|
);
|
|
261
328
|
|
|
262
329
|
// packages/fly-node/src/lib/schemas/postgres-users-list.ts
|
|
263
|
-
var
|
|
264
|
-
var PostgresUsersListTransformedResponseSchema =
|
|
330
|
+
var import_zod21 = require("zod");
|
|
331
|
+
var PostgresUsersListTransformedResponseSchema = import_zod21.z.array(
|
|
265
332
|
withCamelCase(
|
|
266
|
-
|
|
267
|
-
username:
|
|
268
|
-
superuser:
|
|
269
|
-
databases:
|
|
333
|
+
import_zod21.z.object({
|
|
334
|
+
username: import_zod21.z.string(),
|
|
335
|
+
superuser: import_zod21.z.boolean(),
|
|
336
|
+
databases: import_zod21.z.array(import_zod21.z.string())
|
|
270
337
|
})
|
|
271
338
|
)
|
|
272
339
|
);
|
|
273
340
|
|
|
274
341
|
// packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
|
|
275
|
-
var
|
|
342
|
+
var import_zod25 = require("zod");
|
|
276
343
|
|
|
277
344
|
// packages/fly-node/src/lib/schemas/secrets-list.schema.ts
|
|
278
|
-
var
|
|
279
|
-
var SecretsListFlyResponseElementSchema =
|
|
280
|
-
name:
|
|
281
|
-
digest:
|
|
282
|
-
createdAt:
|
|
345
|
+
var import_zod23 = require("zod");
|
|
346
|
+
var SecretsListFlyResponseElementSchema = import_zod23.z.object({
|
|
347
|
+
name: import_zod23.z.string(),
|
|
348
|
+
digest: import_zod23.z.string(),
|
|
349
|
+
createdAt: import_zod23.z.string().datetime()
|
|
283
350
|
});
|
|
284
|
-
var SecretsListTransformedResponseSchema =
|
|
351
|
+
var SecretsListTransformedResponseSchema = import_zod23.z.array(
|
|
285
352
|
withCamelCase(SecretsListFlyResponseElementSchema)
|
|
286
353
|
);
|
|
287
354
|
|
|
288
355
|
// packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
|
|
289
|
-
var SecretsListWithAppTransformedResponseSchema =
|
|
356
|
+
var SecretsListWithAppTransformedResponseSchema = import_zod25.z.array(
|
|
290
357
|
withCamelCase(
|
|
291
358
|
SecretsListFlyResponseElementSchema.extend({
|
|
292
|
-
app:
|
|
359
|
+
app: import_zod25.z.string()
|
|
293
360
|
})
|
|
294
361
|
)
|
|
295
362
|
);
|
|
296
363
|
|
|
297
364
|
// packages/fly-node/src/lib/schemas/status-extended.schema.ts
|
|
298
|
-
var
|
|
365
|
+
var import_zod29 = require("zod");
|
|
299
366
|
|
|
300
367
|
// packages/fly-node/src/lib/schemas/status.schema.ts
|
|
301
|
-
var
|
|
302
|
-
var statusFlyResponseSchema =
|
|
303
|
-
deployed:
|
|
304
|
-
hostname:
|
|
305
|
-
id:
|
|
306
|
-
machines:
|
|
307
|
-
|
|
308
|
-
id:
|
|
309
|
-
name:
|
|
310
|
-
state:
|
|
311
|
-
region:
|
|
312
|
-
createdAt:
|
|
313
|
-
updatedAt:
|
|
314
|
-
config:
|
|
315
|
-
env:
|
|
316
|
-
metadata:
|
|
368
|
+
var import_zod27 = require("zod");
|
|
369
|
+
var statusFlyResponseSchema = import_zod27.z.object({
|
|
370
|
+
deployed: import_zod27.z.boolean(),
|
|
371
|
+
hostname: import_zod27.z.string(),
|
|
372
|
+
id: import_zod27.z.string(),
|
|
373
|
+
machines: import_zod27.z.array(
|
|
374
|
+
import_zod27.z.object({
|
|
375
|
+
id: import_zod27.z.string(),
|
|
376
|
+
name: import_zod27.z.string(),
|
|
377
|
+
state: import_zod27.z.string(),
|
|
378
|
+
region: import_zod27.z.string(),
|
|
379
|
+
createdAt: import_zod27.z.string().datetime(),
|
|
380
|
+
updatedAt: import_zod27.z.string().datetime(),
|
|
381
|
+
config: import_zod27.z.object({
|
|
382
|
+
env: import_zod27.z.record(import_zod27.z.string()),
|
|
383
|
+
metadata: import_zod27.z.record(import_zod27.z.string())
|
|
317
384
|
}),
|
|
318
|
-
events:
|
|
319
|
-
|
|
320
|
-
type:
|
|
321
|
-
status:
|
|
322
|
-
timestamp:
|
|
385
|
+
events: import_zod27.z.array(
|
|
386
|
+
import_zod27.z.object({
|
|
387
|
+
type: import_zod27.z.string(),
|
|
388
|
+
status: import_zod27.z.string(),
|
|
389
|
+
timestamp: import_zod27.z.number()
|
|
323
390
|
})
|
|
324
391
|
),
|
|
325
|
-
checks:
|
|
326
|
-
|
|
327
|
-
name:
|
|
328
|
-
status:
|
|
329
|
-
output:
|
|
330
|
-
updatedAt:
|
|
392
|
+
checks: import_zod27.z.array(
|
|
393
|
+
import_zod27.z.object({
|
|
394
|
+
name: import_zod27.z.string(),
|
|
395
|
+
status: import_zod27.z.string(),
|
|
396
|
+
output: import_zod27.z.string(),
|
|
397
|
+
updatedAt: import_zod27.z.string().datetime()
|
|
331
398
|
})
|
|
332
399
|
).optional(),
|
|
333
|
-
hostStatus:
|
|
400
|
+
hostStatus: import_zod27.z.string()
|
|
334
401
|
})
|
|
335
402
|
),
|
|
336
|
-
name:
|
|
337
|
-
organization:
|
|
338
|
-
id:
|
|
339
|
-
slug:
|
|
403
|
+
name: import_zod27.z.string(),
|
|
404
|
+
organization: import_zod27.z.object({
|
|
405
|
+
id: import_zod27.z.string(),
|
|
406
|
+
slug: import_zod27.z.string()
|
|
340
407
|
}),
|
|
341
|
-
status:
|
|
342
|
-
version:
|
|
408
|
+
status: import_zod27.z.string(),
|
|
409
|
+
version: import_zod27.z.number()
|
|
343
410
|
});
|
|
344
411
|
var StatusTransformedResponseSchema = withCamelCase(
|
|
345
412
|
statusFlyResponseSchema,
|
|
@@ -352,8 +419,8 @@ var StatusTransformedResponseSchema = withCamelCase(
|
|
|
352
419
|
// packages/fly-node/src/lib/schemas/status-extended.schema.ts
|
|
353
420
|
var StatusExtendedTransformedResponseSchema = withCamelCase(
|
|
354
421
|
statusFlyResponseSchema.extend({
|
|
355
|
-
domains:
|
|
356
|
-
secrets:
|
|
422
|
+
domains: import_zod29.z.array(import_zod29.z.object({ hostname: import_zod29.z.string() })),
|
|
423
|
+
secrets: import_zod29.z.array(import_zod29.z.object({ name: import_zod29.z.string() }))
|
|
357
424
|
}),
|
|
358
425
|
{
|
|
359
426
|
preserve: ["machines.config.env", "machines.config.metadata"]
|
|
@@ -477,7 +544,8 @@ ${error}`
|
|
|
477
544
|
this.logger.info(
|
|
478
545
|
`Detaching Postgres cluster '${cluster}' from application '${app}'`
|
|
479
546
|
);
|
|
480
|
-
await this.detachPostgres(cluster, app);
|
|
547
|
+
const output = await this.detachPostgres(cluster, app);
|
|
548
|
+
this.logger.info(output);
|
|
481
549
|
}
|
|
482
550
|
await this.destroyApp(app, options?.force);
|
|
483
551
|
this.logger.info(`Application '${app}' was destroyed`);
|
|
@@ -624,6 +692,11 @@ ${error}`
|
|
|
624
692
|
);
|
|
625
693
|
}
|
|
626
694
|
};
|
|
695
|
+
postgres = {
|
|
696
|
+
detach: async (cluster, app) => {
|
|
697
|
+
await this.detachPostgres(cluster, app);
|
|
698
|
+
}
|
|
699
|
+
};
|
|
627
700
|
/**
|
|
628
701
|
* Manage application secrets
|
|
629
702
|
*/
|
|
@@ -866,6 +939,9 @@ ${error}`);
|
|
|
866
939
|
for (const [key, value] of Object.entries(options?.env || {})) {
|
|
867
940
|
args.push("--env", `${key}=${this.safeArg(value)}`);
|
|
868
941
|
}
|
|
942
|
+
if (options?.optOutDepotBuilder) {
|
|
943
|
+
args.push("--depot=false");
|
|
944
|
+
}
|
|
869
945
|
args.push("--yes");
|
|
870
946
|
this.logger.info(`Deploying '${appName}'...`);
|
|
871
947
|
await this.execFly(args);
|
|
@@ -891,11 +967,19 @@ ${error}`);
|
|
|
891
967
|
}
|
|
892
968
|
/**
|
|
893
969
|
* @private
|
|
970
|
+
* @returns Log output from the detach process
|
|
894
971
|
* @throws An error if the Postgres database cannot be detached from an app
|
|
895
972
|
*/
|
|
896
973
|
async detachPostgres(postgres, app) {
|
|
897
974
|
const args = ["postgres", "detach", postgres, "--app", app];
|
|
898
|
-
await this.execFly(args
|
|
975
|
+
return await this.execFly(args, {
|
|
976
|
+
prompt: (output) => {
|
|
977
|
+
if (output.match(/select .* detach/i)) {
|
|
978
|
+
return app.replace(/-/g, "_");
|
|
979
|
+
}
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
});
|
|
899
983
|
}
|
|
900
984
|
/**
|
|
901
985
|
* @private
|
|
@@ -1032,7 +1116,7 @@ ${error}`);
|
|
|
1032
1116
|
if (onError === "throwOnError") {
|
|
1033
1117
|
throw error;
|
|
1034
1118
|
}
|
|
1035
|
-
if (error instanceof
|
|
1119
|
+
if (error instanceof import_zod30.ZodError) {
|
|
1036
1120
|
this.logger.info(`Failed to parse response:
|
|
1037
1121
|
${error.message}`);
|
|
1038
1122
|
this.logger.info(`Raw response:
|
|
@@ -1119,6 +1203,7 @@ ${JSON.stringify(response, null, 2)}`);
|
|
|
1119
1203
|
this.logger.info("Authenticating with Fly.io...");
|
|
1120
1204
|
let user = await this.execFly(
|
|
1121
1205
|
["auth", "whoami"],
|
|
1206
|
+
void 0,
|
|
1122
1207
|
"nullOnError",
|
|
1123
1208
|
true
|
|
1124
1209
|
// won't use token
|
|
@@ -1136,34 +1221,43 @@ ${JSON.stringify(response, null, 2)}`);
|
|
|
1136
1221
|
throw error;
|
|
1137
1222
|
}
|
|
1138
1223
|
}
|
|
1139
|
-
async execFly(command, onError = "throwOnError", skipToken) {
|
|
1140
|
-
const
|
|
1224
|
+
async execFly(command, options, onError = "throwOnError", skipToken) {
|
|
1225
|
+
const args = Array.isArray(command) ? command : command.split(" ");
|
|
1141
1226
|
if (!skipToken && !this.authByLogin && this._config.token) {
|
|
1142
|
-
|
|
1227
|
+
args.push("--access-token", this._config.token);
|
|
1143
1228
|
}
|
|
1144
|
-
const flyCmd =
|
|
1145
|
-
|
|
1229
|
+
const flyCmd = "flyctl";
|
|
1230
|
+
const toLogCmd = `${flyCmd} ${args.join(" ")}`;
|
|
1231
|
+
let output = "";
|
|
1146
1232
|
try {
|
|
1147
|
-
this.traceCLI("CALL",
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1233
|
+
this.traceCLI("CALL", toLogCmd);
|
|
1234
|
+
if (options?.prompt) {
|
|
1235
|
+
output = await spawnPty(flyCmd, args, { prompt: options.prompt });
|
|
1236
|
+
this.traceCLI("RESULT", output);
|
|
1237
|
+
} else {
|
|
1238
|
+
const result = await spawn(flyCmd, args, options);
|
|
1239
|
+
output = result.stdout.trim();
|
|
1240
|
+
const stderr = result.stderr.trim();
|
|
1241
|
+
this.traceCLI("RESULT", `${output}${stderr ? `
|
|
1242
|
+
${stderr}` : ""}`);
|
|
1243
|
+
}
|
|
1151
1244
|
} catch (error) {
|
|
1152
|
-
|
|
1245
|
+
const errorMsg = error.message;
|
|
1246
|
+
this.traceCLI("RESULT", errorMsg);
|
|
1153
1247
|
if (onError === "throwOnError") {
|
|
1154
|
-
throw new Error(`Command failed: ${
|
|
1155
|
-
${
|
|
1248
|
+
throw new Error(`Command failed: ${toLogCmd}
|
|
1249
|
+
${errorMsg}`);
|
|
1156
1250
|
}
|
|
1157
1251
|
return null;
|
|
1158
1252
|
}
|
|
1159
1253
|
try {
|
|
1160
|
-
return JSON.parse(
|
|
1254
|
+
return JSON.parse(output);
|
|
1161
1255
|
} catch {
|
|
1162
|
-
if (
|
|
1256
|
+
if (output) {
|
|
1163
1257
|
if (this.logger.traceCLI) {
|
|
1164
1258
|
this.logger.info(`Failed to parse as JSON, returning raw output`);
|
|
1165
1259
|
}
|
|
1166
|
-
return
|
|
1260
|
+
return output;
|
|
1167
1261
|
}
|
|
1168
1262
|
}
|
|
1169
1263
|
return void 0;
|
|
@@ -1233,7 +1327,7 @@ ${error}`);
|
|
|
1233
1327
|
* @returns `true` if the Fly CLI is installed, `false` otherwise
|
|
1234
1328
|
*/
|
|
1235
1329
|
async isInstalled() {
|
|
1236
|
-
return await this.execFly("version", "nullOnError") !== null;
|
|
1330
|
+
return await this.execFly("version", void 0, "nullOnError") !== null;
|
|
1237
1331
|
}
|
|
1238
1332
|
/**
|
|
1239
1333
|
* @private
|
package/index.js
CHANGED
|
@@ -29,24 +29,93 @@ 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
|
|
|
38
104
|
// packages/fly-node/src/lib/fly.class.ts
|
|
39
105
|
import { ZodError } from "zod";
|
|
40
106
|
|
|
41
|
-
// packages/core/src/lib/zod/
|
|
107
|
+
// packages/core/src/lib/zod/create-lowercase-schema.ts
|
|
42
108
|
import { z } from "zod";
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
109
|
+
|
|
110
|
+
// packages/core/src/lib/zod/json.schema.ts
|
|
111
|
+
import { z as z2 } from "zod";
|
|
112
|
+
var LiteralSchema = z2.union([z2.string(), z2.number(), z2.boolean(), z2.null()]);
|
|
113
|
+
var JsonSchema = z2.lazy(
|
|
114
|
+
() => z2.union([LiteralSchema, z2.array(JsonSchema), z2.record(JsonSchema)])
|
|
46
115
|
);
|
|
47
116
|
|
|
48
117
|
// packages/core/src/lib/zod/with-camel-case.preprocess.ts
|
|
49
|
-
import { z as
|
|
118
|
+
import { z as z3 } from "zod";
|
|
50
119
|
var toCamelCase = (str, specialCases = {}) => {
|
|
51
120
|
if (specialCases[str]) {
|
|
52
121
|
return specialCases[str];
|
|
@@ -93,7 +162,7 @@ var transformKeys = (options) => {
|
|
|
93
162
|
};
|
|
94
163
|
var withCamelCase = (schema, options = {}) => {
|
|
95
164
|
const { preserve = [], specialCases = {} } = options;
|
|
96
|
-
return
|
|
165
|
+
return z3.preprocess(
|
|
97
166
|
(data) => transformKeys({
|
|
98
167
|
currentPath: [],
|
|
99
168
|
data,
|
|
@@ -105,42 +174,42 @@ var withCamelCase = (schema, options = {}) => {
|
|
|
105
174
|
};
|
|
106
175
|
|
|
107
176
|
// packages/core/src/lib/zod/with-env-vars.preprocess.ts
|
|
108
|
-
import { z as
|
|
177
|
+
import { z as z4 } from "zod";
|
|
109
178
|
|
|
110
179
|
// packages/core/src/lib/zod/with-replace-all.preprocess.ts
|
|
111
|
-
import { z as
|
|
180
|
+
import { z as z5 } from "zod";
|
|
112
181
|
|
|
113
182
|
// packages/fly-node/src/lib/schemas/apps-create.schema.ts
|
|
114
|
-
import { z as
|
|
183
|
+
import { z as z6 } from "zod";
|
|
115
184
|
var AppsCreateTransformedResponseSchema = withCamelCase(
|
|
116
|
-
|
|
117
|
-
id:
|
|
118
|
-
name:
|
|
119
|
-
organization:
|
|
120
|
-
id:
|
|
121
|
-
name:
|
|
185
|
+
z6.object({
|
|
186
|
+
id: z6.string(),
|
|
187
|
+
name: z6.string(),
|
|
188
|
+
organization: z6.object({
|
|
189
|
+
id: z6.string(),
|
|
190
|
+
name: z6.string()
|
|
122
191
|
})
|
|
123
192
|
})
|
|
124
193
|
);
|
|
125
194
|
|
|
126
195
|
// packages/fly-node/src/lib/schemas/apps-list.schema.ts
|
|
127
|
-
import { z as
|
|
128
|
-
var AppsListTransformedResponseSchema =
|
|
196
|
+
import { z as z7 } from "zod";
|
|
197
|
+
var AppsListTransformedResponseSchema = z7.array(
|
|
129
198
|
withCamelCase(
|
|
130
|
-
|
|
131
|
-
id:
|
|
132
|
-
name:
|
|
133
|
-
status:
|
|
134
|
-
deployed:
|
|
135
|
-
hostname:
|
|
136
|
-
organization:
|
|
137
|
-
name:
|
|
138
|
-
slug:
|
|
199
|
+
z7.object({
|
|
200
|
+
id: z7.string(),
|
|
201
|
+
name: z7.string(),
|
|
202
|
+
status: z7.string(),
|
|
203
|
+
deployed: z7.boolean(),
|
|
204
|
+
hostname: z7.string(),
|
|
205
|
+
organization: z7.object({
|
|
206
|
+
name: z7.string(),
|
|
207
|
+
slug: z7.string()
|
|
139
208
|
}),
|
|
140
|
-
currentRelease:
|
|
141
|
-
|
|
142
|
-
status:
|
|
143
|
-
createdAt:
|
|
209
|
+
currentRelease: z7.nullable(
|
|
210
|
+
z7.object({
|
|
211
|
+
status: z7.string(),
|
|
212
|
+
createdAt: z7.string().datetime()
|
|
144
213
|
})
|
|
145
214
|
)
|
|
146
215
|
})
|
|
@@ -148,46 +217,46 @@ var AppsListTransformedResponseSchema = z6.array(
|
|
|
148
217
|
);
|
|
149
218
|
|
|
150
219
|
// packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
|
|
151
|
-
import { z as
|
|
220
|
+
import { z as z9 } from "zod";
|
|
152
221
|
|
|
153
222
|
// packages/fly-node/src/lib/schemas/certs-list.schema.ts
|
|
154
|
-
import { z as
|
|
155
|
-
var CertsListFlyResponseElementSchema =
|
|
156
|
-
createdAt:
|
|
157
|
-
hostname:
|
|
158
|
-
clientStatus:
|
|
223
|
+
import { z as z8 } from "zod";
|
|
224
|
+
var CertsListFlyResponseElementSchema = z8.object({
|
|
225
|
+
createdAt: z8.string().datetime(),
|
|
226
|
+
hostname: z8.string(),
|
|
227
|
+
clientStatus: z8.string()
|
|
159
228
|
});
|
|
160
|
-
var CertsListTransformedResponseSchema =
|
|
229
|
+
var CertsListTransformedResponseSchema = z8.array(
|
|
161
230
|
withCamelCase(CertsListFlyResponseElementSchema)
|
|
162
231
|
);
|
|
163
232
|
|
|
164
233
|
// packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
|
|
165
|
-
var CertsListWithAppTransformedResponseSchema =
|
|
234
|
+
var CertsListWithAppTransformedResponseSchema = z9.array(
|
|
166
235
|
withCamelCase(
|
|
167
236
|
CertsListFlyResponseElementSchema.extend({
|
|
168
|
-
app:
|
|
237
|
+
app: z9.string()
|
|
169
238
|
})
|
|
170
239
|
)
|
|
171
240
|
);
|
|
172
241
|
|
|
173
242
|
// packages/fly-node/src/lib/schemas/config-show.schema.ts
|
|
174
|
-
import { z as
|
|
243
|
+
import { z as z10 } from "zod";
|
|
175
244
|
var ConfigShowResponseSchema = withCamelCase(
|
|
176
|
-
|
|
177
|
-
app:
|
|
178
|
-
primaryRegion:
|
|
179
|
-
build:
|
|
180
|
-
|
|
181
|
-
args:
|
|
182
|
-
dockerfile:
|
|
183
|
-
image:
|
|
245
|
+
z10.object({
|
|
246
|
+
app: z10.string(),
|
|
247
|
+
primaryRegion: z10.string().optional(),
|
|
248
|
+
build: z10.record(z10.string(), z10.any()).optional().or(
|
|
249
|
+
z10.object({
|
|
250
|
+
args: z10.record(z10.string(), z10.string()).optional(),
|
|
251
|
+
dockerfile: z10.string().optional(),
|
|
252
|
+
image: z10.string().optional()
|
|
184
253
|
})
|
|
185
254
|
),
|
|
186
|
-
deploy:
|
|
187
|
-
env:
|
|
188
|
-
httpService:
|
|
189
|
-
mounts:
|
|
190
|
-
services:
|
|
255
|
+
deploy: z10.record(z10.string(), z10.any()).optional().or(z10.object({ strategy: z10.string().optional() })),
|
|
256
|
+
env: z10.record(z10.string(), z10.string()).optional(),
|
|
257
|
+
httpService: z10.record(z10.string(), z10.any()).optional(),
|
|
258
|
+
mounts: z10.record(z10.string(), z10.any()).optional(),
|
|
259
|
+
services: z10.array(z10.record(z10.string(), z10.any())).optional()
|
|
191
260
|
}),
|
|
192
261
|
{
|
|
193
262
|
preserve: ["build.args", "env"]
|
|
@@ -195,115 +264,115 @@ var ConfigShowResponseSchema = withCamelCase(
|
|
|
195
264
|
);
|
|
196
265
|
|
|
197
266
|
// packages/fly-node/src/lib/schemas/deploy.schema.ts
|
|
198
|
-
import { z as
|
|
199
|
-
var DeployResponseSchema =
|
|
200
|
-
app:
|
|
201
|
-
hostname:
|
|
202
|
-
url:
|
|
267
|
+
import { z as z11 } from "zod";
|
|
268
|
+
var DeployResponseSchema = z11.object({
|
|
269
|
+
app: z11.string(),
|
|
270
|
+
hostname: z11.string(),
|
|
271
|
+
url: z11.string().url()
|
|
203
272
|
});
|
|
204
273
|
|
|
205
274
|
// packages/fly-node/src/lib/schemas/helper-schemas.ts
|
|
206
|
-
import { z as
|
|
207
|
-
var AllowEmptyUrlSchema =
|
|
208
|
-
var NameSchema =
|
|
275
|
+
import { z as z12 } from "zod";
|
|
276
|
+
var AllowEmptyUrlSchema = z12.string().url().or(z12.literal(""));
|
|
277
|
+
var NameSchema = z12.string({ message: "App name must be a valid slug" }).regex(/^[a-z0-9-]+$/);
|
|
209
278
|
|
|
210
279
|
// packages/fly-node/src/lib/schemas/postgres-list.ts
|
|
211
|
-
import { z as
|
|
212
|
-
var PostgresListTransformedResponseSchema =
|
|
280
|
+
import { z as z13 } from "zod";
|
|
281
|
+
var PostgresListTransformedResponseSchema = z13.array(
|
|
213
282
|
withCamelCase(
|
|
214
|
-
|
|
215
|
-
deployed:
|
|
216
|
-
hostname:
|
|
217
|
-
id:
|
|
218
|
-
name:
|
|
219
|
-
organization:
|
|
220
|
-
status:
|
|
221
|
-
version:
|
|
283
|
+
z13.object({
|
|
284
|
+
deployed: z13.boolean(),
|
|
285
|
+
hostname: z13.string(),
|
|
286
|
+
id: z13.string(),
|
|
287
|
+
name: z13.string(),
|
|
288
|
+
organization: z13.object({ id: z13.string(), slug: z13.string() }),
|
|
289
|
+
status: z13.string(),
|
|
290
|
+
version: z13.number()
|
|
222
291
|
})
|
|
223
292
|
)
|
|
224
293
|
);
|
|
225
294
|
|
|
226
295
|
// packages/fly-node/src/lib/schemas/postgres-users-list.ts
|
|
227
|
-
import { z as
|
|
228
|
-
var PostgresUsersListTransformedResponseSchema =
|
|
296
|
+
import { z as z14 } from "zod";
|
|
297
|
+
var PostgresUsersListTransformedResponseSchema = z14.array(
|
|
229
298
|
withCamelCase(
|
|
230
|
-
|
|
231
|
-
username:
|
|
232
|
-
superuser:
|
|
233
|
-
databases:
|
|
299
|
+
z14.object({
|
|
300
|
+
username: z14.string(),
|
|
301
|
+
superuser: z14.boolean(),
|
|
302
|
+
databases: z14.array(z14.string())
|
|
234
303
|
})
|
|
235
304
|
)
|
|
236
305
|
);
|
|
237
306
|
|
|
238
307
|
// packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
|
|
239
|
-
import { z as
|
|
308
|
+
import { z as z16 } from "zod";
|
|
240
309
|
|
|
241
310
|
// packages/fly-node/src/lib/schemas/secrets-list.schema.ts
|
|
242
|
-
import { z as
|
|
243
|
-
var SecretsListFlyResponseElementSchema =
|
|
244
|
-
name:
|
|
245
|
-
digest:
|
|
246
|
-
createdAt:
|
|
311
|
+
import { z as z15 } from "zod";
|
|
312
|
+
var SecretsListFlyResponseElementSchema = z15.object({
|
|
313
|
+
name: z15.string(),
|
|
314
|
+
digest: z15.string(),
|
|
315
|
+
createdAt: z15.string().datetime()
|
|
247
316
|
});
|
|
248
|
-
var SecretsListTransformedResponseSchema =
|
|
317
|
+
var SecretsListTransformedResponseSchema = z15.array(
|
|
249
318
|
withCamelCase(SecretsListFlyResponseElementSchema)
|
|
250
319
|
);
|
|
251
320
|
|
|
252
321
|
// packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
|
|
253
|
-
var SecretsListWithAppTransformedResponseSchema =
|
|
322
|
+
var SecretsListWithAppTransformedResponseSchema = z16.array(
|
|
254
323
|
withCamelCase(
|
|
255
324
|
SecretsListFlyResponseElementSchema.extend({
|
|
256
|
-
app:
|
|
325
|
+
app: z16.string()
|
|
257
326
|
})
|
|
258
327
|
)
|
|
259
328
|
);
|
|
260
329
|
|
|
261
330
|
// packages/fly-node/src/lib/schemas/status-extended.schema.ts
|
|
262
|
-
import { z as
|
|
331
|
+
import { z as z18 } from "zod";
|
|
263
332
|
|
|
264
333
|
// 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:
|
|
334
|
+
import { z as z17 } from "zod";
|
|
335
|
+
var statusFlyResponseSchema = z17.object({
|
|
336
|
+
deployed: z17.boolean(),
|
|
337
|
+
hostname: z17.string(),
|
|
338
|
+
id: z17.string(),
|
|
339
|
+
machines: z17.array(
|
|
340
|
+
z17.object({
|
|
341
|
+
id: z17.string(),
|
|
342
|
+
name: z17.string(),
|
|
343
|
+
state: z17.string(),
|
|
344
|
+
region: z17.string(),
|
|
345
|
+
createdAt: z17.string().datetime(),
|
|
346
|
+
updatedAt: z17.string().datetime(),
|
|
347
|
+
config: z17.object({
|
|
348
|
+
env: z17.record(z17.string()),
|
|
349
|
+
metadata: z17.record(z17.string())
|
|
281
350
|
}),
|
|
282
|
-
events:
|
|
283
|
-
|
|
284
|
-
type:
|
|
285
|
-
status:
|
|
286
|
-
timestamp:
|
|
351
|
+
events: z17.array(
|
|
352
|
+
z17.object({
|
|
353
|
+
type: z17.string(),
|
|
354
|
+
status: z17.string(),
|
|
355
|
+
timestamp: z17.number()
|
|
287
356
|
})
|
|
288
357
|
),
|
|
289
|
-
checks:
|
|
290
|
-
|
|
291
|
-
name:
|
|
292
|
-
status:
|
|
293
|
-
output:
|
|
294
|
-
updatedAt:
|
|
358
|
+
checks: z17.array(
|
|
359
|
+
z17.object({
|
|
360
|
+
name: z17.string(),
|
|
361
|
+
status: z17.string(),
|
|
362
|
+
output: z17.string(),
|
|
363
|
+
updatedAt: z17.string().datetime()
|
|
295
364
|
})
|
|
296
365
|
).optional(),
|
|
297
|
-
hostStatus:
|
|
366
|
+
hostStatus: z17.string()
|
|
298
367
|
})
|
|
299
368
|
),
|
|
300
|
-
name:
|
|
301
|
-
organization:
|
|
302
|
-
id:
|
|
303
|
-
slug:
|
|
369
|
+
name: z17.string(),
|
|
370
|
+
organization: z17.object({
|
|
371
|
+
id: z17.string(),
|
|
372
|
+
slug: z17.string()
|
|
304
373
|
}),
|
|
305
|
-
status:
|
|
306
|
-
version:
|
|
374
|
+
status: z17.string(),
|
|
375
|
+
version: z17.number()
|
|
307
376
|
});
|
|
308
377
|
var StatusTransformedResponseSchema = withCamelCase(
|
|
309
378
|
statusFlyResponseSchema,
|
|
@@ -316,8 +385,8 @@ var StatusTransformedResponseSchema = withCamelCase(
|
|
|
316
385
|
// packages/fly-node/src/lib/schemas/status-extended.schema.ts
|
|
317
386
|
var StatusExtendedTransformedResponseSchema = withCamelCase(
|
|
318
387
|
statusFlyResponseSchema.extend({
|
|
319
|
-
domains:
|
|
320
|
-
secrets:
|
|
388
|
+
domains: z18.array(z18.object({ hostname: z18.string() })),
|
|
389
|
+
secrets: z18.array(z18.object({ name: z18.string() }))
|
|
321
390
|
}),
|
|
322
391
|
{
|
|
323
392
|
preserve: ["machines.config.env", "machines.config.metadata"]
|
|
@@ -441,7 +510,8 @@ ${error}`
|
|
|
441
510
|
this.logger.info(
|
|
442
511
|
`Detaching Postgres cluster '${cluster}' from application '${app}'`
|
|
443
512
|
);
|
|
444
|
-
await this.detachPostgres(cluster, app);
|
|
513
|
+
const output = await this.detachPostgres(cluster, app);
|
|
514
|
+
this.logger.info(output);
|
|
445
515
|
}
|
|
446
516
|
await this.destroyApp(app, options?.force);
|
|
447
517
|
this.logger.info(`Application '${app}' was destroyed`);
|
|
@@ -588,6 +658,11 @@ ${error}`
|
|
|
588
658
|
);
|
|
589
659
|
}
|
|
590
660
|
};
|
|
661
|
+
postgres = {
|
|
662
|
+
detach: async (cluster, app) => {
|
|
663
|
+
await this.detachPostgres(cluster, app);
|
|
664
|
+
}
|
|
665
|
+
};
|
|
591
666
|
/**
|
|
592
667
|
* Manage application secrets
|
|
593
668
|
*/
|
|
@@ -830,6 +905,9 @@ ${error}`);
|
|
|
830
905
|
for (const [key, value] of Object.entries(options?.env || {})) {
|
|
831
906
|
args.push("--env", `${key}=${this.safeArg(value)}`);
|
|
832
907
|
}
|
|
908
|
+
if (options?.optOutDepotBuilder) {
|
|
909
|
+
args.push("--depot=false");
|
|
910
|
+
}
|
|
833
911
|
args.push("--yes");
|
|
834
912
|
this.logger.info(`Deploying '${appName}'...`);
|
|
835
913
|
await this.execFly(args);
|
|
@@ -855,11 +933,19 @@ ${error}`);
|
|
|
855
933
|
}
|
|
856
934
|
/**
|
|
857
935
|
* @private
|
|
936
|
+
* @returns Log output from the detach process
|
|
858
937
|
* @throws An error if the Postgres database cannot be detached from an app
|
|
859
938
|
*/
|
|
860
939
|
async detachPostgres(postgres, app) {
|
|
861
940
|
const args = ["postgres", "detach", postgres, "--app", app];
|
|
862
|
-
await this.execFly(args
|
|
941
|
+
return await this.execFly(args, {
|
|
942
|
+
prompt: (output) => {
|
|
943
|
+
if (output.match(/select .* detach/i)) {
|
|
944
|
+
return app.replace(/-/g, "_");
|
|
945
|
+
}
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
});
|
|
863
949
|
}
|
|
864
950
|
/**
|
|
865
951
|
* @private
|
|
@@ -1083,6 +1169,7 @@ ${JSON.stringify(response, null, 2)}`);
|
|
|
1083
1169
|
this.logger.info("Authenticating with Fly.io...");
|
|
1084
1170
|
let user = await this.execFly(
|
|
1085
1171
|
["auth", "whoami"],
|
|
1172
|
+
void 0,
|
|
1086
1173
|
"nullOnError",
|
|
1087
1174
|
true
|
|
1088
1175
|
// won't use token
|
|
@@ -1100,34 +1187,43 @@ ${JSON.stringify(response, null, 2)}`);
|
|
|
1100
1187
|
throw error;
|
|
1101
1188
|
}
|
|
1102
1189
|
}
|
|
1103
|
-
async execFly(command, onError = "throwOnError", skipToken) {
|
|
1104
|
-
const
|
|
1190
|
+
async execFly(command, options, onError = "throwOnError", skipToken) {
|
|
1191
|
+
const args = Array.isArray(command) ? command : command.split(" ");
|
|
1105
1192
|
if (!skipToken && !this.authByLogin && this._config.token) {
|
|
1106
|
-
|
|
1193
|
+
args.push("--access-token", this._config.token);
|
|
1107
1194
|
}
|
|
1108
|
-
const flyCmd =
|
|
1109
|
-
|
|
1195
|
+
const flyCmd = "flyctl";
|
|
1196
|
+
const toLogCmd = `${flyCmd} ${args.join(" ")}`;
|
|
1197
|
+
let output = "";
|
|
1110
1198
|
try {
|
|
1111
|
-
this.traceCLI("CALL",
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1199
|
+
this.traceCLI("CALL", toLogCmd);
|
|
1200
|
+
if (options?.prompt) {
|
|
1201
|
+
output = await spawnPty(flyCmd, args, { prompt: options.prompt });
|
|
1202
|
+
this.traceCLI("RESULT", output);
|
|
1203
|
+
} else {
|
|
1204
|
+
const result = await spawn(flyCmd, args, options);
|
|
1205
|
+
output = result.stdout.trim();
|
|
1206
|
+
const stderr = result.stderr.trim();
|
|
1207
|
+
this.traceCLI("RESULT", `${output}${stderr ? `
|
|
1208
|
+
${stderr}` : ""}`);
|
|
1209
|
+
}
|
|
1115
1210
|
} catch (error) {
|
|
1116
|
-
|
|
1211
|
+
const errorMsg = error.message;
|
|
1212
|
+
this.traceCLI("RESULT", errorMsg);
|
|
1117
1213
|
if (onError === "throwOnError") {
|
|
1118
|
-
throw new Error(`Command failed: ${
|
|
1119
|
-
${
|
|
1214
|
+
throw new Error(`Command failed: ${toLogCmd}
|
|
1215
|
+
${errorMsg}`);
|
|
1120
1216
|
}
|
|
1121
1217
|
return null;
|
|
1122
1218
|
}
|
|
1123
1219
|
try {
|
|
1124
|
-
return JSON.parse(
|
|
1220
|
+
return JSON.parse(output);
|
|
1125
1221
|
} catch {
|
|
1126
|
-
if (
|
|
1222
|
+
if (output) {
|
|
1127
1223
|
if (this.logger.traceCLI) {
|
|
1128
1224
|
this.logger.info(`Failed to parse as JSON, returning raw output`);
|
|
1129
1225
|
}
|
|
1130
|
-
return
|
|
1226
|
+
return output;
|
|
1131
1227
|
}
|
|
1132
1228
|
}
|
|
1133
1229
|
return void 0;
|
|
@@ -1197,7 +1293,7 @@ ${error}`);
|
|
|
1197
1293
|
* @returns `true` if the Fly CLI is installed, `false` otherwise
|
|
1198
1294
|
*/
|
|
1199
1295
|
async isInstalled() {
|
|
1200
|
-
return await this.execFly("version", "nullOnError") !== null;
|
|
1296
|
+
return await this.execFly("version", void 0, "nullOnError") !== null;
|
|
1201
1297
|
}
|
|
1202
1298
|
/**
|
|
1203
1299
|
* @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;
|
package/src/lib/types.d.ts
CHANGED
|
@@ -173,6 +173,12 @@ export type DeployAppOptions = {
|
|
|
173
173
|
* Spaces are supported in values.
|
|
174
174
|
*/
|
|
175
175
|
secrets?: Record<string, string>;
|
|
176
|
+
/**
|
|
177
|
+
* Whether to opt out of the Depot Builder.
|
|
178
|
+
*
|
|
179
|
+
* Defaults to `false`.
|
|
180
|
+
*/
|
|
181
|
+
optOutDepotBuilder?: boolean;
|
|
176
182
|
};
|
|
177
183
|
/**
|
|
178
184
|
* Options for destroying an application
|