Skip to content

Commit

Permalink
Merge pull request #265 from cdnjs/sven/container-name
Browse files Browse the repository at this point in the history
remove special characters from docker container names
  • Loading branch information
xtuc authored Dec 18, 2023
2 parents 0326b50 + af56dee commit dbe86eb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"io/ioutil"
"os"
"regexp"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
Expand All @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit dbe86eb

Please sign in to comment.