@cdwr/fly-node 0.3.5 → 0.3.7
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 +9 -0
- package/index.cjs +27 -11
- package/index.js +28 -12
- package/package.json +1 -1
- package/src/index.d.ts +1 -1
- package/src/lib/fly.class.d.ts +5 -3
- package/src/lib/types.d.ts +28 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## 0.3.7 (2026-11-26)
|
|
2
|
+
|
|
3
|
+
### ✨ Features
|
|
4
|
+
|
|
5
|
+
- **fly-node:** apps.destroy can allow a failed postgres detach ([1ff50a98](https://github.com/codeware-sthlm/codeware/commit/1ff50a98))
|
|
6
|
+
|
|
7
|
+
## 0.3.6 (2026-11-23)
|
|
8
|
+
|
|
9
|
+
### 🐞 Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **fly-node:** an absolute config path is found by config show ([edbfd5c86](https://github.com/codeware-sthlm/cdwr/commit/edbfd5c86))
|
|
12
|
+
|
|
1
13
|
## 0.3.5 (2026-11-15)
|
|
2
14
|
|
|
3
15
|
### 🐞 Bug Fixes
|
package/README.md
CHANGED
|
@@ -220,6 +220,15 @@ This will destroy the application completely.
|
|
|
220
220
|
await fly.apps.destroy('foo-app');
|
|
221
221
|
```
|
|
222
222
|
|
|
223
|
+
A failed detach throws and leaves the application in place. Pass `allowDetachFailure` to destroy it anyway. Each failed detach is logged and returned, and a failed destroy still throws.
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
const { detachFailures } = await fly.apps.destroy('foo-app', {
|
|
227
|
+
allowDetachFailure: true
|
|
228
|
+
});
|
|
229
|
+
// [{ cluster: 'pg-cluster', error: '...' }]
|
|
230
|
+
```
|
|
231
|
+
|
|
223
232
|
#### Deploy an application
|
|
224
233
|
|
|
225
234
|
> [!IMPORTANT]
|
package/index.cjs
CHANGED
|
@@ -613,7 +613,7 @@ var SpawnError = class extends Error {
|
|
|
613
613
|
}
|
|
614
614
|
};
|
|
615
615
|
function spawn(command, args, options) {
|
|
616
|
-
return new Promise((
|
|
616
|
+
return new Promise((resolve2, reject) => {
|
|
617
617
|
const { streamToConsole, ...spawnOptions } = options || {};
|
|
618
618
|
const process2 = (0, import_child_process2.spawn)(command, args, {
|
|
619
619
|
...spawnOptions,
|
|
@@ -637,7 +637,7 @@ function spawn(command, args, options) {
|
|
|
637
637
|
const stdout = Buffer.concat(stdoutChunks).toString();
|
|
638
638
|
const stderr = Buffer.concat(stderrChunks).toString();
|
|
639
639
|
if (code === 0) {
|
|
640
|
-
|
|
640
|
+
resolve2({ stdout, stderr });
|
|
641
641
|
} else {
|
|
642
642
|
const lines = stderr.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
643
643
|
const message = streamToConsole && lines.length > STREAMED_STDERR_TAIL_LINES ? `Process exited with code ${code}
|
|
@@ -654,7 +654,7 @@ Error: ${stderr}`;
|
|
|
654
654
|
// libs/shared/util/misc/src/lib/spawn-pty.ts
|
|
655
655
|
var import_node_pty_prebuilt_multiarch = require("@homebridge/node-pty-prebuilt-multiarch");
|
|
656
656
|
function spawnPty(command, args, options) {
|
|
657
|
-
return new Promise((
|
|
657
|
+
return new Promise((resolve2, reject) => {
|
|
658
658
|
const ptyData = [];
|
|
659
659
|
const ptyProcess = (0, import_node_pty_prebuilt_multiarch.spawn)(command, args, {
|
|
660
660
|
cwd: process.cwd(),
|
|
@@ -674,7 +674,7 @@ function spawnPty(command, args, options) {
|
|
|
674
674
|
ptyProcess.onExit(({ exitCode }) => {
|
|
675
675
|
const output = ptyData.join("");
|
|
676
676
|
if (exitCode === 0) {
|
|
677
|
-
|
|
677
|
+
resolve2(output);
|
|
678
678
|
} else {
|
|
679
679
|
reject(
|
|
680
680
|
new Error(`Process exited with code ${exitCode}
|
|
@@ -1194,21 +1194,37 @@ ${error}`,
|
|
|
1194
1194
|
* Destroy an application and make sure it gets detached from any Postgres clusters
|
|
1195
1195
|
*
|
|
1196
1196
|
* @param app - The name of the app to destroy
|
|
1197
|
-
* @
|
|
1197
|
+
* @param options - Options for destroying an application
|
|
1198
|
+
* @returns The Postgres clusters that could not be detached, when `allowDetachFailure` is set
|
|
1199
|
+
* @throws An error if the app cannot be destroyed, or a cluster cannot be detached without `allowDetachFailure`
|
|
1198
1200
|
*/
|
|
1199
|
-
destroy: async (app) => {
|
|
1201
|
+
destroy: async (app, options) => {
|
|
1200
1202
|
try {
|
|
1201
1203
|
await this.ensureInitialized();
|
|
1204
|
+
const detachFailures = [];
|
|
1202
1205
|
const attachedClusters = await this.getAttachedPostgresClusters(app);
|
|
1203
1206
|
for (const cluster of attachedClusters) {
|
|
1204
1207
|
this.logger.info(
|
|
1205
1208
|
`Detaching Postgres cluster '${cluster}' from application '${app}'`
|
|
1206
1209
|
);
|
|
1207
|
-
|
|
1208
|
-
|
|
1210
|
+
try {
|
|
1211
|
+
const output = await this.detachPostgres(cluster, app);
|
|
1212
|
+
this.logger.info(output);
|
|
1213
|
+
} catch (error) {
|
|
1214
|
+
if (!options?.allowDetachFailure) {
|
|
1215
|
+
throw error;
|
|
1216
|
+
}
|
|
1217
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1218
|
+
this.logger.info(
|
|
1219
|
+
`Failed to detach Postgres cluster '${cluster}' from application '${app}', destroying it anyway
|
|
1220
|
+
${message}`
|
|
1221
|
+
);
|
|
1222
|
+
detachFailures.push({ cluster, error: message });
|
|
1223
|
+
}
|
|
1209
1224
|
}
|
|
1210
1225
|
await this.destroyApp(app);
|
|
1211
1226
|
this.logger.info(`Application '${app}' was destroyed`);
|
|
1227
|
+
return { detachFailures };
|
|
1212
1228
|
} catch (error) {
|
|
1213
1229
|
throw new Error(
|
|
1214
1230
|
`[destroy app] something broke, check your apps
|
|
@@ -2141,7 +2157,7 @@ ${error}`);
|
|
|
2141
2157
|
return;
|
|
2142
2158
|
}
|
|
2143
2159
|
await new Promise(
|
|
2144
|
-
(
|
|
2160
|
+
(resolve2) => setTimeout(resolve2, MACHINE_STATE_INTERVAL_MS)
|
|
2145
2161
|
);
|
|
2146
2162
|
}
|
|
2147
2163
|
throw new Error(
|
|
@@ -2317,7 +2333,7 @@ ${JSON.stringify(response, null, 2)}`);
|
|
|
2317
2333
|
async showConfig(onError, options) {
|
|
2318
2334
|
const normalized = this.normalizeOptions(options);
|
|
2319
2335
|
const config = normalized.config || this.instanceConfig;
|
|
2320
|
-
if (config && !(0, import_fs.existsSync)((0, import_path.
|
|
2336
|
+
if (config && !(0, import_fs.existsSync)((0, import_path.resolve)((0, import_process.cwd)(), config))) {
|
|
2321
2337
|
throw new Error(`Config file '${config}' does not exist`);
|
|
2322
2338
|
}
|
|
2323
2339
|
const args = ["config", "show"];
|
|
@@ -2414,7 +2430,7 @@ ${JSON.stringify(response, null, 2)}`);
|
|
|
2414
2430
|
this.logger.info(
|
|
2415
2431
|
`Transient Fly error (${cause}), retrying in ${delay / 1e3}s (attempt ${attempt + 1} of ${TRANSIENT_RETRY_DELAYS_MS.length + 1}): ${toLogCmd}`
|
|
2416
2432
|
);
|
|
2417
|
-
await new Promise((
|
|
2433
|
+
await new Promise((resolve2) => setTimeout(resolve2, delay));
|
|
2418
2434
|
continue;
|
|
2419
2435
|
}
|
|
2420
2436
|
if (onError === "throwOnError") {
|
package/index.js
CHANGED
|
@@ -527,7 +527,7 @@ var HOSTNAME_CHECK_FIELDS = `
|
|
|
527
527
|
|
|
528
528
|
// packages/fly-node/src/lib/fly.class.ts
|
|
529
529
|
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
530
|
-
import { dirname, join } from "path";
|
|
530
|
+
import { dirname, join, resolve } from "path";
|
|
531
531
|
import { cwd } from "process";
|
|
532
532
|
|
|
533
533
|
// libs/shared/util/misc/src/lib/docker-build.ts
|
|
@@ -569,7 +569,7 @@ var SpawnError = class extends Error {
|
|
|
569
569
|
}
|
|
570
570
|
};
|
|
571
571
|
function spawn(command, args, options) {
|
|
572
|
-
return new Promise((
|
|
572
|
+
return new Promise((resolve2, reject) => {
|
|
573
573
|
const { streamToConsole, ...spawnOptions } = options || {};
|
|
574
574
|
const process2 = cpSpawn(command, args, {
|
|
575
575
|
...spawnOptions,
|
|
@@ -593,7 +593,7 @@ function spawn(command, args, options) {
|
|
|
593
593
|
const stdout = Buffer.concat(stdoutChunks).toString();
|
|
594
594
|
const stderr = Buffer.concat(stderrChunks).toString();
|
|
595
595
|
if (code === 0) {
|
|
596
|
-
|
|
596
|
+
resolve2({ stdout, stderr });
|
|
597
597
|
} else {
|
|
598
598
|
const lines = stderr.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
599
599
|
const message = streamToConsole && lines.length > STREAMED_STDERR_TAIL_LINES ? `Process exited with code ${code}
|
|
@@ -610,7 +610,7 @@ Error: ${stderr}`;
|
|
|
610
610
|
// libs/shared/util/misc/src/lib/spawn-pty.ts
|
|
611
611
|
import { spawn as spawn2 } from "@homebridge/node-pty-prebuilt-multiarch";
|
|
612
612
|
function spawnPty(command, args, options) {
|
|
613
|
-
return new Promise((
|
|
613
|
+
return new Promise((resolve2, reject) => {
|
|
614
614
|
const ptyData = [];
|
|
615
615
|
const ptyProcess = spawn2(command, args, {
|
|
616
616
|
cwd: process.cwd(),
|
|
@@ -630,7 +630,7 @@ function spawnPty(command, args, options) {
|
|
|
630
630
|
ptyProcess.onExit(({ exitCode }) => {
|
|
631
631
|
const output = ptyData.join("");
|
|
632
632
|
if (exitCode === 0) {
|
|
633
|
-
|
|
633
|
+
resolve2(output);
|
|
634
634
|
} else {
|
|
635
635
|
reject(
|
|
636
636
|
new Error(`Process exited with code ${exitCode}
|
|
@@ -1150,21 +1150,37 @@ ${error}`,
|
|
|
1150
1150
|
* Destroy an application and make sure it gets detached from any Postgres clusters
|
|
1151
1151
|
*
|
|
1152
1152
|
* @param app - The name of the app to destroy
|
|
1153
|
-
* @
|
|
1153
|
+
* @param options - Options for destroying an application
|
|
1154
|
+
* @returns The Postgres clusters that could not be detached, when `allowDetachFailure` is set
|
|
1155
|
+
* @throws An error if the app cannot be destroyed, or a cluster cannot be detached without `allowDetachFailure`
|
|
1154
1156
|
*/
|
|
1155
|
-
destroy: async (app) => {
|
|
1157
|
+
destroy: async (app, options) => {
|
|
1156
1158
|
try {
|
|
1157
1159
|
await this.ensureInitialized();
|
|
1160
|
+
const detachFailures = [];
|
|
1158
1161
|
const attachedClusters = await this.getAttachedPostgresClusters(app);
|
|
1159
1162
|
for (const cluster of attachedClusters) {
|
|
1160
1163
|
this.logger.info(
|
|
1161
1164
|
`Detaching Postgres cluster '${cluster}' from application '${app}'`
|
|
1162
1165
|
);
|
|
1163
|
-
|
|
1164
|
-
|
|
1166
|
+
try {
|
|
1167
|
+
const output = await this.detachPostgres(cluster, app);
|
|
1168
|
+
this.logger.info(output);
|
|
1169
|
+
} catch (error) {
|
|
1170
|
+
if (!options?.allowDetachFailure) {
|
|
1171
|
+
throw error;
|
|
1172
|
+
}
|
|
1173
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1174
|
+
this.logger.info(
|
|
1175
|
+
`Failed to detach Postgres cluster '${cluster}' from application '${app}', destroying it anyway
|
|
1176
|
+
${message}`
|
|
1177
|
+
);
|
|
1178
|
+
detachFailures.push({ cluster, error: message });
|
|
1179
|
+
}
|
|
1165
1180
|
}
|
|
1166
1181
|
await this.destroyApp(app);
|
|
1167
1182
|
this.logger.info(`Application '${app}' was destroyed`);
|
|
1183
|
+
return { detachFailures };
|
|
1168
1184
|
} catch (error) {
|
|
1169
1185
|
throw new Error(
|
|
1170
1186
|
`[destroy app] something broke, check your apps
|
|
@@ -2097,7 +2113,7 @@ ${error}`);
|
|
|
2097
2113
|
return;
|
|
2098
2114
|
}
|
|
2099
2115
|
await new Promise(
|
|
2100
|
-
(
|
|
2116
|
+
(resolve2) => setTimeout(resolve2, MACHINE_STATE_INTERVAL_MS)
|
|
2101
2117
|
);
|
|
2102
2118
|
}
|
|
2103
2119
|
throw new Error(
|
|
@@ -2273,7 +2289,7 @@ ${JSON.stringify(response, null, 2)}`);
|
|
|
2273
2289
|
async showConfig(onError, options) {
|
|
2274
2290
|
const normalized = this.normalizeOptions(options);
|
|
2275
2291
|
const config = normalized.config || this.instanceConfig;
|
|
2276
|
-
if (config && !existsSync(
|
|
2292
|
+
if (config && !existsSync(resolve(cwd(), config))) {
|
|
2277
2293
|
throw new Error(`Config file '${config}' does not exist`);
|
|
2278
2294
|
}
|
|
2279
2295
|
const args = ["config", "show"];
|
|
@@ -2370,7 +2386,7 @@ ${JSON.stringify(response, null, 2)}`);
|
|
|
2370
2386
|
this.logger.info(
|
|
2371
2387
|
`Transient Fly error (${cause}), retrying in ${delay / 1e3}s (attempt ${attempt + 1} of ${TRANSIENT_RETRY_DELAYS_MS.length + 1}): ${toLogCmd}`
|
|
2372
2388
|
);
|
|
2373
|
-
await new Promise((
|
|
2389
|
+
await new Promise((resolve2) => setTimeout(resolve2, delay));
|
|
2374
2390
|
continue;
|
|
2375
2391
|
}
|
|
2376
2392
|
if (onError === "throwOnError") {
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export * from './api';
|
|
2
2
|
export * from './lib/fly.class';
|
|
3
|
-
export type { AllocateIpOptions, BuildResponse, Config, DeployAppOptions, DeployResponse, ListIpResponse, MachineOperationOptions, SaveConfigOptions, StatusResponse } from './lib/types';
|
|
3
|
+
export type { AllocateIpOptions, BuildResponse, Config, DeployAppOptions, DeployResponse, DestroyAppOptions, DestroyAppResponse, ListIpResponse, MachineOperationOptions, SaveConfigOptions, StatusResponse } from './lib/types';
|
package/src/lib/fly.class.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SpawnOptions, SpawnPtyOptions } from '@codeware/shared/util/misc';
|
|
2
|
-
import type { AllocateIpOptions, AppOrConfig, BuildResponse, Config, CreateAppOptions, CreateAppResponse, DeployAppOptions, DeployResponse, ListAppResponse, ListCertForAllResponse, ListCertForAppResponse, ListIpResponse, ListSecretForAllResponse, ListSecretForAppResponse, SaveConfigOptions, SetAppSecretsOptions, ShowConfigOptions, ShowConfigResponse, StatusExtendedResponse, StatusResponse, UnsetAppSecretsOptions, VersionResponse } from './types';
|
|
2
|
+
import type { AllocateIpOptions, AppOrConfig, BuildResponse, Config, CreateAppOptions, CreateAppResponse, DeployAppOptions, DeployResponse, DestroyAppOptions, DestroyAppResponse, ListAppResponse, ListCertForAllResponse, ListCertForAppResponse, ListIpResponse, ListSecretForAllResponse, ListSecretForAppResponse, SaveConfigOptions, SetAppSecretsOptions, ShowConfigOptions, ShowConfigResponse, StatusExtendedResponse, StatusResponse, UnsetAppSecretsOptions, VersionResponse } from './types';
|
|
3
3
|
export type ExecFlyOptions = SpawnOptions & SpawnPtyOptions & {
|
|
4
4
|
/**
|
|
5
5
|
* How to assemble the returned output string from the spawned process.
|
|
@@ -79,9 +79,11 @@ export declare class Fly {
|
|
|
79
79
|
* Destroy an application and make sure it gets detached from any Postgres clusters
|
|
80
80
|
*
|
|
81
81
|
* @param app - The name of the app to destroy
|
|
82
|
-
* @
|
|
82
|
+
* @param options - Options for destroying an application
|
|
83
|
+
* @returns The Postgres clusters that could not be detached, when `allowDetachFailure` is set
|
|
84
|
+
* @throws An error if the app cannot be destroyed, or a cluster cannot be detached without `allowDetachFailure`
|
|
83
85
|
*/
|
|
84
|
-
destroy: (app: string) => Promise<
|
|
86
|
+
destroy: (app: string, options?: DestroyAppOptions) => Promise<DestroyAppResponse>;
|
|
85
87
|
/**
|
|
86
88
|
* List all applications
|
|
87
89
|
*
|
package/src/lib/types.d.ts
CHANGED
|
@@ -135,6 +135,34 @@ export type CreateAppOptions = {
|
|
|
135
135
|
*/
|
|
136
136
|
org?: string;
|
|
137
137
|
};
|
|
138
|
+
/**
|
|
139
|
+
* Options for destroying an application
|
|
140
|
+
*/
|
|
141
|
+
export type DestroyAppOptions = {
|
|
142
|
+
/**
|
|
143
|
+
* Destroy the application even when detaching it from a Postgres cluster fails.
|
|
144
|
+
*
|
|
145
|
+
* Each failed detach is logged and returned in `detachFailures`.
|
|
146
|
+
* A failed destroy still throws.
|
|
147
|
+
*
|
|
148
|
+
* @default false
|
|
149
|
+
*/
|
|
150
|
+
allowDetachFailure?: boolean;
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Result of destroying an application
|
|
154
|
+
*/
|
|
155
|
+
export type DestroyAppResponse = {
|
|
156
|
+
/**
|
|
157
|
+
* Postgres clusters that could not be detached before the application was destroyed.
|
|
158
|
+
*
|
|
159
|
+
* Always empty unless `allowDetachFailure` is set, since a failed detach throws.
|
|
160
|
+
*/
|
|
161
|
+
detachFailures: Array<{
|
|
162
|
+
cluster: string;
|
|
163
|
+
error: string;
|
|
164
|
+
}>;
|
|
165
|
+
};
|
|
138
166
|
/**
|
|
139
167
|
* Options for deploying an application
|
|
140
168
|
*/
|