Add ability to specify custom volumes. If these volumes are under the user's $HOME they are created before the container, to ensure they have the correct ownership.
This commit is contained in:
parent
e7552a277a
commit
c5c5c040c1
32
otherworld
32
otherworld
@ -24,13 +24,12 @@ def create_x11_mapping ():
|
||||
"-v", f"{home}/.guix-profile/share/fonts/truetype:/user/share/fonts/truetype-guix",
|
||||
"-v", f"{home}/.guix-profile/share/fonts/opentype:/usr/share/fonts/opentype-guix",
|
||||
"-v", f"{Xauthority}:{inner_user}/.Xauthority",
|
||||
"-v", f"{home}/otherworld:{inner_user}/otherworld",
|
||||
"-w", inner_user,
|
||||
"--shm-size", "2g",
|
||||
"--privileged"]
|
||||
|
||||
DOCKER_CREATE_OPTIONS = ["-t"] + create_x11_mapping()
|
||||
|
||||
USER_VOLUMES = ["~/otherworld"]
|
||||
BACKGROUND_COMMAND = None
|
||||
DEFAULT_COMMAND = ["bash"]
|
||||
|
||||
@ -59,12 +58,36 @@ def docker_exec (container, command, user):
|
||||
def docker_rm (container):
|
||||
call(["docker", "rm", "-f", container])
|
||||
|
||||
def expand_user_volumes (volumes):
|
||||
outer_home = os.environ["HOME"]
|
||||
inner_home = outer_home
|
||||
mappings = []
|
||||
for volume in volumes:
|
||||
source = volume
|
||||
target = volume
|
||||
if ":" in source:
|
||||
(source, target) = source.split(":")
|
||||
|
||||
if source.startswith("~/"):
|
||||
source = f"{outer_home}/{source[1:]}"
|
||||
|
||||
if source.startswith(outer_home) and not os.path.exists(source):
|
||||
os.makedirs(source)
|
||||
|
||||
if target.startswith("~/"):
|
||||
target = f"{inner_home}/{target[1:]}"
|
||||
|
||||
mappings = mappings + ["-v", f"{source}:{target}"]
|
||||
|
||||
return mappings
|
||||
|
||||
user = os.environ["USER"]
|
||||
image_name = os.environ.get("OW_IMAGE", IMAGE_NAME)
|
||||
container_name = os.environ.get("OW_CONTAINER", f"{CONTAINER_NAME}_{user}")
|
||||
|
||||
command = sys.argv[1:]
|
||||
command_user = user
|
||||
user_volumes = USER_VOLUMES
|
||||
|
||||
quiet = False
|
||||
while len(command) > 0:
|
||||
@ -86,6 +109,9 @@ while len(command) > 0:
|
||||
elif arg.startswith("--image="):
|
||||
image_name = arg[len("--image="):]
|
||||
command = command[1:]
|
||||
elif arg.startswith("--volume="):
|
||||
user_volumes.append(arg[len("--volume="):])
|
||||
command = command[1:]
|
||||
else:
|
||||
break
|
||||
|
||||
@ -101,7 +127,7 @@ except Exception:
|
||||
docker_create(
|
||||
image_name,
|
||||
container_name,
|
||||
DOCKER_CREATE_OPTIONS,
|
||||
DOCKER_CREATE_OPTIONS + expand_user_volumes(user_volumes),
|
||||
BACKGROUND_COMMAND
|
||||
)
|
||||
container = docker_inspect(container_name)[0]
|
||||
|
Loading…
x
Reference in New Issue
Block a user