From 000f426b3a341892eca790e8d90eec55fa2144d8 Mon Sep 17 00:00:00 2001 From: Carl Simon Adorf Date: Thu, 15 Sep 2022 12:32:19 +0200 Subject: [PATCH] Switch to jovyan as the default user. Selecting a different user is currently creating problems, see https://github.com/aiidalab/aiidalab-docker-stack/issues/297 . --- aiidalab_launch/profile.py | 12 +++++++++++- tests/test_cli.py | 4 ++-- tests/test_instance.py | 5 ++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/aiidalab_launch/profile.py b/aiidalab_launch/profile.py index 52eb9fd..4a3c392 100644 --- a/aiidalab_launch/profile.py +++ b/aiidalab_launch/profile.py @@ -10,6 +10,7 @@ import toml from docker.models.containers import Container +from .core import LOGGER from .util import docker_mount_for, get_docker_env, is_volume_readonly MAIN_PROFILE_NAME = "default" @@ -65,7 +66,7 @@ class Profile: name: str = MAIN_PROFILE_NAME port: int | None = field(default_factory=_default_port) default_apps: list[str] = field(default_factory=lambda: ["aiidalab-widgets-base"]) - system_user: str = "aiida" + system_user: str = "jovyan" image: str = _DEFAULT_IMAGE home_mount: str | None = None extra_mounts: set[str] = field(default_factory=set) @@ -93,6 +94,14 @@ def __post_init__(self): self.extra_mounts.remove(extra_mount) self.extra_mounts.add(f"{extra_mount}:rw") + if ( + self.image.split(":")[0] == "aiidalab/full-stack" + and self.system_user != "jovyan" + ): + LOGGER.warning( + "Resetting the system user may create issues for this image!" + ) + def container_name(self) -> str: return f"{CONTAINER_PREFIX}{self.name}" @@ -127,6 +136,7 @@ def environment(self, jupyter_token: str) -> dict: "AIIDALAB_DEFAULT_APPS": " ".join(self.default_apps), "JUPYTER_TOKEN": str(jupyter_token), "SYSTEM_USER": self.system_user, + "NB_USER": self.system_user, } def dumps(self) -> str: diff --git a/tests/test_cli.py b/tests/test_cli.py index 36c155d..0e4c00f 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -161,11 +161,11 @@ def test_status(self, started_instance): assert started_instance.profile.home_mount in result.output assert started_instance.url() in result.output - def test_exec(self): + def test_exec(self, started_instance): runner: CliRunner = CliRunner() result: Result = runner.invoke(cli.cli, ["exec", "--", "whoami"]) assert result.exit_code == 0 - assert "aiida" in result.output + assert started_instance.profile.system_user in result.output def test_logs(self): runner: CliRunner = CliRunner() diff --git a/tests/test_instance.py b/tests/test_instance.py index 3d03b20..4bda23e 100644 --- a/tests/test_instance.py +++ b/tests/test_instance.py @@ -159,7 +159,10 @@ def test_instance_host_ports(self, started_instance): def test_instance_exec_create(self, docker_client, started_instance): exec_id = started_instance.exec_create(cmd="whoami") - assert docker_client.api.exec_start(exec_id).decode().strip() == "aiida" + assert ( + docker_client.api.exec_start(exec_id).decode().strip() + == started_instance.profile.system_user + ) exec_id_privileged = started_instance.exec_create(cmd="whoami", privileged=True) assert (