Skip to content

Commit

Permalink
Switch to jovyan as the default user.
Browse files Browse the repository at this point in the history
Selecting a different user is currently creating problems, see
aiidalab/aiidalab-docker-stack#297 .
  • Loading branch information
csadorf committed Sep 15, 2022
1 parent 44b2499 commit 09f39e7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
10 changes: 9 additions & 1 deletion aiidalab_launch/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -93,6 +94,12 @@ 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.warn("Resetting the system user may create issues for this image!")

def container_name(self) -> str:
return f"{CONTAINER_PREFIX}{self.name}"

Expand Down Expand Up @@ -127,6 +134,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:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion tests/test_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, user="root"
Expand Down

0 comments on commit 09f39e7

Please sign in to comment.