@cdwr/fly-node 0.3.6 → 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 +6 -0
- package/README.md +9 -0
- package/index.cjs +20 -4
- package/index.js +20 -4
- 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
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
|
@@ -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
|
package/index.js
CHANGED
|
@@ -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
|
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
|
*/
|