container: Sanitize project directory name for Docker container names
Docker container names only allow [a-zA-Z0-9][a-zA-Z0-9_.-], so directories containing spaces or other characters caused container creation to fail.
This commit is contained in:
parent
eef9a66d2d
commit
7507534cf0
1 changed files with 3 additions and 1 deletions
|
|
@ -3,6 +3,7 @@
|
|||
import hashlib
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import shlex
|
||||
import signal
|
||||
import subprocess
|
||||
|
|
@ -37,8 +38,9 @@ class AgentContainer:
|
|||
self.host_uid = os.getuid()
|
||||
self.host_gid = os.getgid()
|
||||
|
||||
safe_name = re.sub(r"[^a-zA-Z0-9_.-]+", "_", self.project_path.name).strip("_.-")
|
||||
self.container_name = (
|
||||
f"{self.CONTAINER_PREFIX}{self.project_path.name}-{self.project_id}"
|
||||
f"{self.CONTAINER_PREFIX}{safe_name}-{self.project_id}"
|
||||
)
|
||||
self.docker_context_dir = Path(__file__).resolve().parent
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue