From c30c1c429f2f6159d3b343eb0ba374fbaf3ed731 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Sat, 8 Apr 2023 12:31:25 -0700 Subject: [PATCH] Sanitize name before saving to compose file (#164) --- multidim-interop/src/compose-runner.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/multidim-interop/src/compose-runner.ts b/multidim-interop/src/compose-runner.ts index b4e9e28..ee32ea1 100644 --- a/multidim-interop/src/compose-runner.ts +++ b/multidim-interop/src/compose-runner.ts @@ -33,7 +33,9 @@ export async function run(namespace: string, compose: ComposeSpecification, opts await fs.mkdir(dir, { recursive: true }) // Create compose.yaml file - await fs.writeFile(path.join(dir, "compose.yaml"), stringify(compose)) + // Some docker compose environments don't like the name field to have special characters + const sanitizedComposeName = compose?.name.replace(/[^a-zA-Z0-9_-]/g, "_") + await fs.writeFile(path.join(dir, "compose.yaml"), stringify({...compose, name: sanitizedComposeName})) const upFlags: Array = [] if (opts.up.exitCodeFrom) { @@ -66,4 +68,4 @@ export async function run(namespace: string, compose: ComposeSpecification, opts } await fs.rm(dir, { recursive: true, force: true }) } -} \ No newline at end of file +}