Ignore destroyed deployments for AMI deletion
This commit is contained in:
+12
-6
@@ -22,7 +22,7 @@ Options:
|
|||||||
--name <name> AMI project tag (default: nixos-zfs-ec2)
|
--name <name> AMI project tag (default: nixos-zfs-ec2)
|
||||||
--architecture <arm64|x86_64> Filter by architecture
|
--architecture <arm64|x86_64> Filter by architecture
|
||||||
--runtime-state-bucket <name> S3 bucket with qx-deploy registry objects
|
--runtime-state-bucket <name> S3 bucket with qx-deploy registry objects
|
||||||
--force Delete even when registry deployments reference the AMI
|
--force Delete even when active registry deployments reference the AMI
|
||||||
-h, --help Show this help
|
-h, --help Show this help
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@@ -211,6 +211,11 @@ const deploymentRegistry = (state) => {
|
|||||||
return records;
|
return records;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const deploymentReferenceLabel = (record) =>
|
||||||
|
`${record.id}${record.status ? `:${record.status}` : ""}`;
|
||||||
|
|
||||||
|
const isDestroyedDeployment = (record) => record.status === "destroyed";
|
||||||
|
|
||||||
const listArtifacts = (state) => {
|
const listArtifacts = (state) => {
|
||||||
const registry = deploymentRegistry(state);
|
const registry = deploymentRegistry(state);
|
||||||
const references = new Map();
|
const references = new Map();
|
||||||
@@ -220,7 +225,7 @@ const listArtifacts = (state) => {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const entries = references.get(amiId) ?? [];
|
const entries = references.get(amiId) ?? [];
|
||||||
entries.push(record.id);
|
entries.push(deploymentReferenceLabel(record));
|
||||||
references.set(amiId, entries);
|
references.set(amiId, entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,11 +251,12 @@ const deleteArtifact = (state) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const registry = deploymentRegistry(state);
|
const registry = deploymentRegistry(state);
|
||||||
const refs = registry
|
const activeRefs = registry
|
||||||
.filter((record) => record.config?.amiId === state.amiId)
|
.filter((record) => record.config?.amiId === state.amiId)
|
||||||
.map((record) => record.id);
|
.filter((record) => !isDestroyedDeployment(record))
|
||||||
if (refs.length > 0 && !state.force) {
|
.map(deploymentReferenceLabel);
|
||||||
throw new Error(`Refusing to delete ${state.amiId}; referenced by deployments: ${refs.join(", ")}\nPass --force after those deployments are destroyed or intentionally orphaned.`);
|
if (activeRefs.length > 0 && !state.force) {
|
||||||
|
throw new Error(`Refusing to delete ${state.amiId}; referenced by active deployments: ${activeRefs.join(", ")}\nDestroy those deployments first, or pass --force if they are intentionally orphaned.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = awsJson([
|
const result = awsJson([
|
||||||
|
|||||||
Reference in New Issue
Block a user