Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
refactor(e2e): share docker env args and add the install-image race retry
jkomyno committed
Aug 3, 2026 at 20:29 UTC
b52dd3c0af3eca261ca3abd469fa0ba6e493b67e
1 file changed
+32
-26
ts/e2e-tests/_utils/src/image-lifecycle.ts
+32
-26
@@ -135,6 +135,19 @@ function labelsToArgs(labels: Record<string, string> = {}): string[] {
135
return args;
136
}
137
138
+/**
139
+ * Converts environment variables to Docker CLI arguments array.
140
+ * Skips undefined values to avoid passing empty env vars to Docker.
141
+ */
142
+function envToArgs(env: Record<string, string | undefined> = {}): string[] {
143
+ const args: string[] = [];
144
+ for (const [k, v] of Object.entries(env)) {
145
+ if (v === undefined) continue;
146
+ args.push('-e', `${k}=${v}`);
147
+ }
148
+ return args;
149
+}
150
+
151
/**
152
* Adds a bind mount for host ~/.composio into container home.
153
* This allows E2E jobs to inject `user_data.json` once per job.
@@ -304,13 +317,7 @@ export async function runNodeContainer(options: RunNodeContainerOptions): Promis
317
addHostComposioMount(dockerArgs, '/root/.composio');
318
319
// Pass environment variables to the container for runtime configuration.
307
- if (env) {
308
- for (const [k, v] of Object.entries(env)) {
309
- // Skip undefined values to avoid passing empty env vars to Docker.
310
- if (v === undefined) continue;
311
- dockerArgs.push('-e', `${k}=${v}`);
312
- }
313
- }
320
+ dockerArgs.push(...envToArgs(env));
321
322
// Configure bind mounts to share host directories with the container.
323
if (mounts) {
@@ -489,13 +496,7 @@ export async function runDenoContainer(options: RunDenoContainerOptions): Promis
496
addHostComposioMount(dockerArgs, '/root/.composio');
497
498
// Pass environment variables to the container for runtime configuration.
492
- if (env) {
493
- for (const [k, v] of Object.entries(env)) {
494
- // Skip undefined values to avoid passing empty env vars to Docker.
495
- if (v === undefined) continue;
496
- dockerArgs.push('-e', `${k}=${v}`);
497
- }
498
- }
499
+ dockerArgs.push(...envToArgs(env));
500
501
// Configure bind mounts to share host directories with the container.
502
if (mounts) {
@@ -672,12 +673,7 @@ export async function runCliContainer(options: RunCliContainerOptions): Promise<
673
674
addHostComposioMount(dockerArgs, '/tmp/.composio');
675
675
- if (env) {
676
- for (const [k, v] of Object.entries(env)) {
677
- if (v === undefined) continue;
678
- dockerArgs.push('-e', `${k}=${v}`);
679
- }
680
- }
676
+ dockerArgs.push(...envToArgs(env));
677
678
if (mounts) {
679
for (const m of mounts) {
@@ -795,8 +791,22 @@ export async function ensureInstallImage(
791
{ cwd: repoRoot }
792
);
793
if (built.exitCode !== 0) {
794
+ // Handle race condition: concurrent builds may fail because another build
795
+ // already tagged the image. If the image now exists, treat it as success.
796
+ const output = built.stderr || built.stdout;
797
+ if (output.includes('already exists')) {
798
+ const recheck = await exec(
799
+ 'docker',
800
+ ['image', 'inspect', '--format', '{{.Architecture}}', imageTag],
801
+ { cwd: repoRoot }
802
+ );
803
+ if (recheck.exitCode === 0 && recheck.stdout.trim() === architecture) {
804
+ return { imageTag, platform };
805
+ }
806
+ }
807
+
808
const err = new Error(`Failed to build Docker image ${imageTag}`);
799
- (err as Error & { cause: Error }).cause = new Error(built.stderr || built.stdout);
809
+ (err as Error & { cause: Error }).cause = new Error(output);
810
throw err;
811
}
812
@@ -821,11 +831,7 @@ export async function runInstallContainer(
831
'host.docker.internal:host-gateway',
832
];
833
824
- for (const [key, value] of Object.entries(env ?? {})) {
825
- if (value !== undefined) {
826
- dockerArgs.push('-e', `${key}=${value}`);
827
- }
828
- }
834
+ dockerArgs.push(...envToArgs(env));
835
836
// Installer tests intentionally do not mount the host's ~/.composio directory.
837
dockerArgs.push(imageTag, ...cmd.map(String));