@cdwr/fly-node 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +8 -1
- package/index.cjs +227 -139
- package/index.js +227 -137
- package/package.json +1 -1
- package/src/lib/fly.class.d.ts +6 -0
- package/src/lib/schemas/apps-create.schema.d.ts +8 -8
- package/src/lib/schemas/apps-list.schema.d.ts +6 -6
- package/src/lib/schemas/postgres-list.d.ts +6 -6
- package/src/lib/schemas/status-extended.schema.d.ts +18 -18
- package/src/lib/schemas/status.schema.d.ts +32 -32
- package/src/lib/types.d.ts +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## 0.2.1 (2025-02-07)
|
|
2
|
+
|
|
3
|
+
### 🐞 Bug Fixes
|
|
4
|
+
|
|
5
|
+
- **web:** remove dependency to payload and related packages ([0a7a63e](https://github.com/codeware-sthlm/codeware/commit/0a7a63e))
|
|
6
|
+
|
|
7
|
+
## 0.2.0 (2025-01-30)
|
|
8
|
+
|
|
9
|
+
### ✨ Features
|
|
10
|
+
|
|
11
|
+
- **fly-node:** optional opt out depot builder on deploy ([5bd15a0e1](https://github.com/codeware-sthlm/codeware/commit/5bd15a0e1))
|
|
12
|
+
|
|
13
|
+
### 🐞 Bug Fixes
|
|
14
|
+
|
|
15
|
+
- **fly-node:** fix fly deploy command typo ([fa79f4daf](https://github.com/codeware-sthlm/codeware/commit/fa79f4daf))
|
|
16
|
+
- **fly-node:** use spawn pty for interactive prompts ([3998bc606](https://github.com/codeware-sthlm/codeware/commit/3998bc606))
|
|
17
|
+
- **fly-node:** detach postgres must handle interactive prompt ([6e2c79036](https://github.com/codeware-sthlm/codeware/commit/6e2c79036))
|
|
18
|
+
|
|
1
19
|
## 0.1.0 (2025-01-12)
|
|
2
20
|
|
|
3
21
|
### ✨ 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,14 +65,78 @@ 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_zod28 = require("zod");
|
|
76
140
|
|
|
77
141
|
// packages/core/src/lib/zod/json.schema.ts
|
|
78
142
|
var import_zod = require("zod");
|
|
@@ -140,43 +204,40 @@ var withCamelCase = (schema, options = {}) => {
|
|
|
140
204
|
);
|
|
141
205
|
};
|
|
142
206
|
|
|
143
|
-
// packages/core/src/lib/zod/with-env-vars.preprocess.ts
|
|
144
|
-
var import_zod3 = require("zod");
|
|
145
|
-
|
|
146
207
|
// packages/core/src/lib/zod/with-replace-all.preprocess.ts
|
|
147
|
-
var
|
|
208
|
+
var import_zod3 = require("zod");
|
|
148
209
|
|
|
149
210
|
// packages/fly-node/src/lib/schemas/apps-create.schema.ts
|
|
150
|
-
var
|
|
211
|
+
var import_zod5 = require("zod");
|
|
151
212
|
var AppsCreateTransformedResponseSchema = withCamelCase(
|
|
152
|
-
|
|
153
|
-
id:
|
|
154
|
-
name:
|
|
155
|
-
organization:
|
|
156
|
-
id:
|
|
157
|
-
name:
|
|
213
|
+
import_zod5.z.object({
|
|
214
|
+
id: import_zod5.z.string(),
|
|
215
|
+
name: import_zod5.z.string(),
|
|
216
|
+
organization: import_zod5.z.object({
|
|
217
|
+
id: import_zod5.z.string(),
|
|
218
|
+
name: import_zod5.z.string()
|
|
158
219
|
})
|
|
159
220
|
})
|
|
160
221
|
);
|
|
161
222
|
|
|
162
223
|
// packages/fly-node/src/lib/schemas/apps-list.schema.ts
|
|
163
|
-
var
|
|
164
|
-
var AppsListTransformedResponseSchema =
|
|
224
|
+
var import_zod7 = require("zod");
|
|
225
|
+
var AppsListTransformedResponseSchema = import_zod7.z.array(
|
|
165
226
|
withCamelCase(
|
|
166
|
-
|
|
167
|
-
id:
|
|
168
|
-
name:
|
|
169
|
-
status:
|
|
170
|
-
deployed:
|
|
171
|
-
hostname:
|
|
172
|
-
organization:
|
|
173
|
-
name:
|
|
174
|
-
slug:
|
|
227
|
+
import_zod7.z.object({
|
|
228
|
+
id: import_zod7.z.string(),
|
|
229
|
+
name: import_zod7.z.string(),
|
|
230
|
+
status: import_zod7.z.string(),
|
|
231
|
+
deployed: import_zod7.z.boolean(),
|
|
232
|
+
hostname: import_zod7.z.string(),
|
|
233
|
+
organization: import_zod7.z.object({
|
|
234
|
+
name: import_zod7.z.string(),
|
|
235
|
+
slug: import_zod7.z.string()
|
|
175
236
|
}),
|
|
176
|
-
currentRelease:
|
|
177
|
-
|
|
178
|
-
status:
|
|
179
|
-
createdAt:
|
|
237
|
+
currentRelease: import_zod7.z.nullable(
|
|
238
|
+
import_zod7.z.object({
|
|
239
|
+
status: import_zod7.z.string(),
|
|
240
|
+
createdAt: import_zod7.z.string().datetime()
|
|
180
241
|
})
|
|
181
242
|
)
|
|
182
243
|
})
|
|
@@ -184,46 +245,46 @@ var AppsListTransformedResponseSchema = import_zod8.z.array(
|
|
|
184
245
|
);
|
|
185
246
|
|
|
186
247
|
// packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
|
|
187
|
-
var
|
|
248
|
+
var import_zod11 = require("zod");
|
|
188
249
|
|
|
189
250
|
// packages/fly-node/src/lib/schemas/certs-list.schema.ts
|
|
190
|
-
var
|
|
191
|
-
var CertsListFlyResponseElementSchema =
|
|
192
|
-
createdAt:
|
|
193
|
-
hostname:
|
|
194
|
-
clientStatus:
|
|
251
|
+
var import_zod9 = require("zod");
|
|
252
|
+
var CertsListFlyResponseElementSchema = import_zod9.z.object({
|
|
253
|
+
createdAt: import_zod9.z.string().datetime(),
|
|
254
|
+
hostname: import_zod9.z.string(),
|
|
255
|
+
clientStatus: import_zod9.z.string()
|
|
195
256
|
});
|
|
196
|
-
var CertsListTransformedResponseSchema =
|
|
257
|
+
var CertsListTransformedResponseSchema = import_zod9.z.array(
|
|
197
258
|
withCamelCase(CertsListFlyResponseElementSchema)
|
|
198
259
|
);
|
|
199
260
|
|
|
200
261
|
// packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
|
|
201
|
-
var CertsListWithAppTransformedResponseSchema =
|
|
262
|
+
var CertsListWithAppTransformedResponseSchema = import_zod11.z.array(
|
|
202
263
|
withCamelCase(
|
|
203
264
|
CertsListFlyResponseElementSchema.extend({
|
|
204
|
-
app:
|
|
265
|
+
app: import_zod11.z.string()
|
|
205
266
|
})
|
|
206
267
|
)
|
|
207
268
|
);
|
|
208
269
|
|
|
209
270
|
// packages/fly-node/src/lib/schemas/config-show.schema.ts
|
|
210
|
-
var
|
|
271
|
+
var import_zod13 = require("zod");
|
|
211
272
|
var ConfigShowResponseSchema = withCamelCase(
|
|
212
|
-
|
|
213
|
-
app:
|
|
214
|
-
primaryRegion:
|
|
215
|
-
build:
|
|
216
|
-
|
|
217
|
-
args:
|
|
218
|
-
dockerfile:
|
|
219
|
-
image:
|
|
273
|
+
import_zod13.z.object({
|
|
274
|
+
app: import_zod13.z.string(),
|
|
275
|
+
primaryRegion: import_zod13.z.string().optional(),
|
|
276
|
+
build: import_zod13.z.record(import_zod13.z.string(), import_zod13.z.any()).optional().or(
|
|
277
|
+
import_zod13.z.object({
|
|
278
|
+
args: import_zod13.z.record(import_zod13.z.string(), import_zod13.z.string()).optional(),
|
|
279
|
+
dockerfile: import_zod13.z.string().optional(),
|
|
280
|
+
image: import_zod13.z.string().optional()
|
|
220
281
|
})
|
|
221
282
|
),
|
|
222
|
-
deploy:
|
|
223
|
-
env:
|
|
224
|
-
httpService:
|
|
225
|
-
mounts:
|
|
226
|
-
services:
|
|
283
|
+
deploy: import_zod13.z.record(import_zod13.z.string(), import_zod13.z.any()).optional().or(import_zod13.z.object({ strategy: import_zod13.z.string().optional() })),
|
|
284
|
+
env: import_zod13.z.record(import_zod13.z.string(), import_zod13.z.string()).optional(),
|
|
285
|
+
httpService: import_zod13.z.record(import_zod13.z.string(), import_zod13.z.any()).optional(),
|
|
286
|
+
mounts: import_zod13.z.record(import_zod13.z.string(), import_zod13.z.any()).optional(),
|
|
287
|
+
services: import_zod13.z.array(import_zod13.z.record(import_zod13.z.string(), import_zod13.z.any())).optional()
|
|
227
288
|
}),
|
|
228
289
|
{
|
|
229
290
|
preserve: ["build.args", "env"]
|
|
@@ -231,115 +292,115 @@ var ConfigShowResponseSchema = withCamelCase(
|
|
|
231
292
|
);
|
|
232
293
|
|
|
233
294
|
// packages/fly-node/src/lib/schemas/deploy.schema.ts
|
|
234
|
-
var
|
|
235
|
-
var DeployResponseSchema =
|
|
236
|
-
app:
|
|
237
|
-
hostname:
|
|
238
|
-
url:
|
|
295
|
+
var import_zod14 = require("zod");
|
|
296
|
+
var DeployResponseSchema = import_zod14.z.object({
|
|
297
|
+
app: import_zod14.z.string(),
|
|
298
|
+
hostname: import_zod14.z.string(),
|
|
299
|
+
url: import_zod14.z.string().url()
|
|
239
300
|
});
|
|
240
301
|
|
|
241
302
|
// packages/fly-node/src/lib/schemas/helper-schemas.ts
|
|
242
|
-
var
|
|
243
|
-
var AllowEmptyUrlSchema =
|
|
244
|
-
var NameSchema =
|
|
303
|
+
var import_zod15 = require("zod");
|
|
304
|
+
var AllowEmptyUrlSchema = import_zod15.z.string().url().or(import_zod15.z.literal(""));
|
|
305
|
+
var NameSchema = import_zod15.z.string({ message: "App name must be a valid slug" }).regex(/^[a-z0-9-]+$/);
|
|
245
306
|
|
|
246
307
|
// packages/fly-node/src/lib/schemas/postgres-list.ts
|
|
247
|
-
var
|
|
248
|
-
var PostgresListTransformedResponseSchema =
|
|
308
|
+
var import_zod17 = require("zod");
|
|
309
|
+
var PostgresListTransformedResponseSchema = import_zod17.z.array(
|
|
249
310
|
withCamelCase(
|
|
250
|
-
|
|
251
|
-
deployed:
|
|
252
|
-
hostname:
|
|
253
|
-
id:
|
|
254
|
-
name:
|
|
255
|
-
organization:
|
|
256
|
-
status:
|
|
257
|
-
version:
|
|
311
|
+
import_zod17.z.object({
|
|
312
|
+
deployed: import_zod17.z.boolean(),
|
|
313
|
+
hostname: import_zod17.z.string(),
|
|
314
|
+
id: import_zod17.z.string(),
|
|
315
|
+
name: import_zod17.z.string(),
|
|
316
|
+
organization: import_zod17.z.object({ id: import_zod17.z.string(), slug: import_zod17.z.string() }),
|
|
317
|
+
status: import_zod17.z.string(),
|
|
318
|
+
version: import_zod17.z.number()
|
|
258
319
|
})
|
|
259
320
|
)
|
|
260
321
|
);
|
|
261
322
|
|
|
262
323
|
// packages/fly-node/src/lib/schemas/postgres-users-list.ts
|
|
263
|
-
var
|
|
264
|
-
var PostgresUsersListTransformedResponseSchema =
|
|
324
|
+
var import_zod19 = require("zod");
|
|
325
|
+
var PostgresUsersListTransformedResponseSchema = import_zod19.z.array(
|
|
265
326
|
withCamelCase(
|
|
266
|
-
|
|
267
|
-
username:
|
|
268
|
-
superuser:
|
|
269
|
-
databases:
|
|
327
|
+
import_zod19.z.object({
|
|
328
|
+
username: import_zod19.z.string(),
|
|
329
|
+
superuser: import_zod19.z.boolean(),
|
|
330
|
+
databases: import_zod19.z.array(import_zod19.z.string())
|
|
270
331
|
})
|
|
271
332
|
)
|
|
272
333
|
);
|
|
273
334
|
|
|
274
335
|
// packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
|
|
275
|
-
var
|
|
336
|
+
var import_zod23 = require("zod");
|
|
276
337
|
|
|
277
338
|
// packages/fly-node/src/lib/schemas/secrets-list.schema.ts
|
|
278
|
-
var
|
|
279
|
-
var SecretsListFlyResponseElementSchema =
|
|
280
|
-
name:
|
|
281
|
-
digest:
|
|
282
|
-
createdAt:
|
|
339
|
+
var import_zod21 = require("zod");
|
|
340
|
+
var SecretsListFlyResponseElementSchema = import_zod21.z.object({
|
|
341
|
+
name: import_zod21.z.string(),
|
|
342
|
+
digest: import_zod21.z.string(),
|
|
343
|
+
createdAt: import_zod21.z.string().datetime()
|
|
283
344
|
});
|
|
284
|
-
var SecretsListTransformedResponseSchema =
|
|
345
|
+
var SecretsListTransformedResponseSchema = import_zod21.z.array(
|
|
285
346
|
withCamelCase(SecretsListFlyResponseElementSchema)
|
|
286
347
|
);
|
|
287
348
|
|
|
288
349
|
// packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
|
|
289
|
-
var SecretsListWithAppTransformedResponseSchema =
|
|
350
|
+
var SecretsListWithAppTransformedResponseSchema = import_zod23.z.array(
|
|
290
351
|
withCamelCase(
|
|
291
352
|
SecretsListFlyResponseElementSchema.extend({
|
|
292
|
-
app:
|
|
353
|
+
app: import_zod23.z.string()
|
|
293
354
|
})
|
|
294
355
|
)
|
|
295
356
|
);
|
|
296
357
|
|
|
297
358
|
// packages/fly-node/src/lib/schemas/status-extended.schema.ts
|
|
298
|
-
var
|
|
359
|
+
var import_zod27 = require("zod");
|
|
299
360
|
|
|
300
361
|
// 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:
|
|
362
|
+
var import_zod25 = require("zod");
|
|
363
|
+
var statusFlyResponseSchema = import_zod25.z.object({
|
|
364
|
+
deployed: import_zod25.z.boolean(),
|
|
365
|
+
hostname: import_zod25.z.string(),
|
|
366
|
+
id: import_zod25.z.string(),
|
|
367
|
+
machines: import_zod25.z.array(
|
|
368
|
+
import_zod25.z.object({
|
|
369
|
+
id: import_zod25.z.string(),
|
|
370
|
+
name: import_zod25.z.string(),
|
|
371
|
+
state: import_zod25.z.string(),
|
|
372
|
+
region: import_zod25.z.string(),
|
|
373
|
+
createdAt: import_zod25.z.string().datetime(),
|
|
374
|
+
updatedAt: import_zod25.z.string().datetime(),
|
|
375
|
+
config: import_zod25.z.object({
|
|
376
|
+
env: import_zod25.z.record(import_zod25.z.string()),
|
|
377
|
+
metadata: import_zod25.z.record(import_zod25.z.string())
|
|
317
378
|
}),
|
|
318
|
-
events:
|
|
319
|
-
|
|
320
|
-
type:
|
|
321
|
-
status:
|
|
322
|
-
timestamp:
|
|
379
|
+
events: import_zod25.z.array(
|
|
380
|
+
import_zod25.z.object({
|
|
381
|
+
type: import_zod25.z.string(),
|
|
382
|
+
status: import_zod25.z.string(),
|
|
383
|
+
timestamp: import_zod25.z.number()
|
|
323
384
|
})
|
|
324
385
|
),
|
|
325
|
-
checks:
|
|
326
|
-
|
|
327
|
-
name:
|
|
328
|
-
status:
|
|
329
|
-
output:
|
|
330
|
-
updatedAt:
|
|
386
|
+
checks: import_zod25.z.array(
|
|
387
|
+
import_zod25.z.object({
|
|
388
|
+
name: import_zod25.z.string(),
|
|
389
|
+
status: import_zod25.z.string(),
|
|
390
|
+
output: import_zod25.z.string(),
|
|
391
|
+
updatedAt: import_zod25.z.string().datetime()
|
|
331
392
|
})
|
|
332
393
|
).optional(),
|
|
333
|
-
hostStatus:
|
|
394
|
+
hostStatus: import_zod25.z.string()
|
|
334
395
|
})
|
|
335
396
|
),
|
|
336
|
-
name:
|
|
337
|
-
organization:
|
|
338
|
-
id:
|
|
339
|
-
slug:
|
|
397
|
+
name: import_zod25.z.string(),
|
|
398
|
+
organization: import_zod25.z.object({
|
|
399
|
+
id: import_zod25.z.string(),
|
|
400
|
+
slug: import_zod25.z.string()
|
|
340
401
|
}),
|
|
341
|
-
status:
|
|
342
|
-
version:
|
|
402
|
+
status: import_zod25.z.string(),
|
|
403
|
+
version: import_zod25.z.number()
|
|
343
404
|
});
|
|
344
405
|
var StatusTransformedResponseSchema = withCamelCase(
|
|
345
406
|
statusFlyResponseSchema,
|
|
@@ -352,8 +413,8 @@ var StatusTransformedResponseSchema = withCamelCase(
|
|
|
352
413
|
// packages/fly-node/src/lib/schemas/status-extended.schema.ts
|
|
353
414
|
var StatusExtendedTransformedResponseSchema = withCamelCase(
|
|
354
415
|
statusFlyResponseSchema.extend({
|
|
355
|
-
domains:
|
|
356
|
-
secrets:
|
|
416
|
+
domains: import_zod27.z.array(import_zod27.z.object({ hostname: import_zod27.z.string() })),
|
|
417
|
+
secrets: import_zod27.z.array(import_zod27.z.object({ name: import_zod27.z.string() }))
|
|
357
418
|
}),
|
|
358
419
|
{
|
|
359
420
|
preserve: ["machines.config.env", "machines.config.metadata"]
|
|
@@ -477,7 +538,8 @@ ${error}`
|
|
|
477
538
|
this.logger.info(
|
|
478
539
|
`Detaching Postgres cluster '${cluster}' from application '${app}'`
|
|
479
540
|
);
|
|
480
|
-
await this.detachPostgres(cluster, app);
|
|
541
|
+
const output = await this.detachPostgres(cluster, app);
|
|
542
|
+
this.logger.info(output);
|
|
481
543
|
}
|
|
482
544
|
await this.destroyApp(app, options?.force);
|
|
483
545
|
this.logger.info(`Application '${app}' was destroyed`);
|
|
@@ -624,6 +686,11 @@ ${error}`
|
|
|
624
686
|
);
|
|
625
687
|
}
|
|
626
688
|
};
|
|
689
|
+
postgres = {
|
|
690
|
+
detach: async (cluster, app) => {
|
|
691
|
+
await this.detachPostgres(cluster, app);
|
|
692
|
+
}
|
|
693
|
+
};
|
|
627
694
|
/**
|
|
628
695
|
* Manage application secrets
|
|
629
696
|
*/
|
|
@@ -866,6 +933,9 @@ ${error}`);
|
|
|
866
933
|
for (const [key, value] of Object.entries(options?.env || {})) {
|
|
867
934
|
args.push("--env", `${key}=${this.safeArg(value)}`);
|
|
868
935
|
}
|
|
936
|
+
if (options?.optOutDepotBuilder) {
|
|
937
|
+
args.push("--depot=false");
|
|
938
|
+
}
|
|
869
939
|
args.push("--yes");
|
|
870
940
|
this.logger.info(`Deploying '${appName}'...`);
|
|
871
941
|
await this.execFly(args);
|
|
@@ -891,11 +961,19 @@ ${error}`);
|
|
|
891
961
|
}
|
|
892
962
|
/**
|
|
893
963
|
* @private
|
|
964
|
+
* @returns Log output from the detach process
|
|
894
965
|
* @throws An error if the Postgres database cannot be detached from an app
|
|
895
966
|
*/
|
|
896
967
|
async detachPostgres(postgres, app) {
|
|
897
968
|
const args = ["postgres", "detach", postgres, "--app", app];
|
|
898
|
-
await this.execFly(args
|
|
969
|
+
return await this.execFly(args, {
|
|
970
|
+
prompt: (output) => {
|
|
971
|
+
if (output.match(/select .* detach/i)) {
|
|
972
|
+
return app.replace(/-/g, "_");
|
|
973
|
+
}
|
|
974
|
+
return;
|
|
975
|
+
}
|
|
976
|
+
});
|
|
899
977
|
}
|
|
900
978
|
/**
|
|
901
979
|
* @private
|
|
@@ -1032,7 +1110,7 @@ ${error}`);
|
|
|
1032
1110
|
if (onError === "throwOnError") {
|
|
1033
1111
|
throw error;
|
|
1034
1112
|
}
|
|
1035
|
-
if (error instanceof
|
|
1113
|
+
if (error instanceof import_zod28.ZodError) {
|
|
1036
1114
|
this.logger.info(`Failed to parse response:
|
|
1037
1115
|
${error.message}`);
|
|
1038
1116
|
this.logger.info(`Raw response:
|
|
@@ -1119,6 +1197,7 @@ ${JSON.stringify(response, null, 2)}`);
|
|
|
1119
1197
|
this.logger.info("Authenticating with Fly.io...");
|
|
1120
1198
|
let user = await this.execFly(
|
|
1121
1199
|
["auth", "whoami"],
|
|
1200
|
+
void 0,
|
|
1122
1201
|
"nullOnError",
|
|
1123
1202
|
true
|
|
1124
1203
|
// won't use token
|
|
@@ -1136,34 +1215,43 @@ ${JSON.stringify(response, null, 2)}`);
|
|
|
1136
1215
|
throw error;
|
|
1137
1216
|
}
|
|
1138
1217
|
}
|
|
1139
|
-
async execFly(command, onError = "throwOnError", skipToken) {
|
|
1140
|
-
const
|
|
1218
|
+
async execFly(command, options, onError = "throwOnError", skipToken) {
|
|
1219
|
+
const args = Array.isArray(command) ? command : command.split(" ");
|
|
1141
1220
|
if (!skipToken && !this.authByLogin && this._config.token) {
|
|
1142
|
-
|
|
1221
|
+
args.push("--access-token", this._config.token);
|
|
1143
1222
|
}
|
|
1144
|
-
const flyCmd =
|
|
1145
|
-
|
|
1223
|
+
const flyCmd = "flyctl";
|
|
1224
|
+
const toLogCmd = `${flyCmd} ${args.join(" ")}`;
|
|
1225
|
+
let output = "";
|
|
1146
1226
|
try {
|
|
1147
|
-
this.traceCLI("CALL",
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1227
|
+
this.traceCLI("CALL", toLogCmd);
|
|
1228
|
+
if (options?.prompt) {
|
|
1229
|
+
output = await spawnPty(flyCmd, args, { prompt: options.prompt });
|
|
1230
|
+
this.traceCLI("RESULT", output);
|
|
1231
|
+
} else {
|
|
1232
|
+
const result = await spawn(flyCmd, args, options);
|
|
1233
|
+
output = result.stdout.trim();
|
|
1234
|
+
const stderr = result.stderr.trim();
|
|
1235
|
+
this.traceCLI("RESULT", `${output}${stderr ? `
|
|
1236
|
+
${stderr}` : ""}`);
|
|
1237
|
+
}
|
|
1151
1238
|
} catch (error) {
|
|
1152
|
-
|
|
1239
|
+
const errorMsg = error.message;
|
|
1240
|
+
this.traceCLI("RESULT", errorMsg);
|
|
1153
1241
|
if (onError === "throwOnError") {
|
|
1154
|
-
throw new Error(`Command failed: ${
|
|
1155
|
-
${
|
|
1242
|
+
throw new Error(`Command failed: ${toLogCmd}
|
|
1243
|
+
${errorMsg}`);
|
|
1156
1244
|
}
|
|
1157
1245
|
return null;
|
|
1158
1246
|
}
|
|
1159
1247
|
try {
|
|
1160
|
-
return JSON.parse(
|
|
1248
|
+
return JSON.parse(output);
|
|
1161
1249
|
} catch {
|
|
1162
|
-
if (
|
|
1250
|
+
if (output) {
|
|
1163
1251
|
if (this.logger.traceCLI) {
|
|
1164
1252
|
this.logger.info(`Failed to parse as JSON, returning raw output`);
|
|
1165
1253
|
}
|
|
1166
|
-
return
|
|
1254
|
+
return output;
|
|
1167
1255
|
}
|
|
1168
1256
|
}
|
|
1169
1257
|
return void 0;
|
|
@@ -1233,7 +1321,7 @@ ${error}`);
|
|
|
1233
1321
|
* @returns `true` if the Fly CLI is installed, `false` otherwise
|
|
1234
1322
|
*/
|
|
1235
1323
|
async isInstalled() {
|
|
1236
|
-
return await this.execFly("version", "nullOnError") !== null;
|
|
1324
|
+
return await this.execFly("version", void 0, "nullOnError") !== null;
|
|
1237
1325
|
}
|
|
1238
1326
|
/**
|
|
1239
1327
|
* @private
|