From af56deead007ecd7f742b04c6d47571cd623dd42 Mon Sep 17 00:00:00 2001 From: Sven Sauleau Date: Thu, 22 Jun 2023 11:50:12 +0200 Subject: [PATCH] remove special characters from docker container names Closes https://github.com/cdnjs/tools/issues/264 --- sandbox/sandbox.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sandbox/sandbox.go b/sandbox/sandbox.go index 6eaae09..d6fb196 100644 --- a/sandbox/sandbox.go +++ b/sandbox/sandbox.go @@ -6,6 +6,7 @@ import ( "io" "io/ioutil" "os" + "regexp" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" @@ -16,7 +17,8 @@ import ( ) var ( - DOCKER_IMAGE = os.Getenv("DOCKER_IMAGE") + DOCKER_IMAGE = os.Getenv("DOCKER_IMAGE") + CONTAINER_NAME_RE = regexp.MustCompile(`[^a-zA-Z0-9-_]+`) ) func Setup() (string, string, error) { @@ -68,6 +70,10 @@ func Run(ctx context.Context, containerName, in, out string) (string, error) { return "", errors.Wrap(err, "could not create client") } + // Sanitize the container's name because some package use special character + // in their versions and Docker doesn't accept that. + containerName = CONTAINER_NAME_RE.ReplaceAllString(containerName, "-") + resp, err := cli.ContainerCreate(ctx, &container.Config{ Image: DOCKER_IMAGE,