@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 04:45 UTC

next
ts 74 lines 1.89 KB
Raw
1 #!/usr/bin/env bun
2 /**
3 * Removes all Docker images used by Node.js and CLI e2e tests.
4 * Images are identified by the label `composio.e2e=true`.
5 */
6
7 import { $ } from 'bun';
8
9 async function cleanImages(runtime: 'node' | 'cli'): Promise<number> {
10 const runtimeLabel = runtime === 'node' ? 'Node.js' : 'CLI';
11 console.log(`Finding e2e ${runtimeLabel} Docker images...`);
12
13 // Find all images with the e2e labels
14 const result = await $`docker images --filter label=composio.e2e=true --filter label=composio.runtime=${runtime} --format {{.Repository}}:{{.Tag}}`
15 .nothrow()
16 .quiet();
17
18 if (result.exitCode !== 0) {
19 console.error(`Failed to list Docker images:`, result.stderr.toString());
20 return 1;
21 }
22
23 const images = result.stdout
24 .toString()
25 .trim()
26 .split('\n')
27 .filter((img) => img.length > 0 && !img.includes('<none>'));
28
29 if (images.length === 0) {
30 console.log(`No e2e ${runtimeLabel} Docker images found.`);
31 return 0;
32 }
33
34 console.log(`Found ${images.length} image(s) to remove:`);
35 for (const img of images) {
36 console.log(` - ${img}`);
37 }
38
39 console.log('\nRemoving images...');
40
41 // Remove images one by one to safely handle each image name
42 let removeFailures = 0;
43 for (const img of images) {
44 const removeResult = await $`docker rmi ${img}`.nothrow().quiet();
45 if (removeResult.exitCode !== 0) {
46 console.error(` Failed to remove ${img}:`, removeResult.stderr.toString());
47 removeFailures++;
48 }
49 }
50
51 return removeFailures;
52 }
53
54 async function main() {
55 let totalFailures = 0;
56
57 // Clean Node.js images
58 totalFailures += await cleanImages('node');
59
60 // Clean CLI images
61 totalFailures += await cleanImages('cli');
62
63 if (totalFailures > 0) {
64 console.error(`\nFailed to remove ${totalFailures} image(s).`);
65 process.exit(1);
66 }
67
68 console.log('\nDone.');
69 }
70
71 main().catch((err) => {
72 console.error('Error:', err);
73 process.exit(1);
74 });