Sanitize name before saving to compose file (#164)

This commit is contained in:
Marco Munizaga 2023-04-08 12:31:25 -07:00 committed by GitHub
parent 9c67a406a5
commit c30c1c429f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<string> = []
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 })
}
}
}