Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): add git user configuration to local session #2877

Merged
merged 10 commits into from
May 12, 2022
25 changes: 23 additions & 2 deletions renku/core/session/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# limitations under the License.
"""Docker based interactive session provider."""

import os.path
from pathlib import Path
from typing import Any, Dict, Iterable, List, Optional, Tuple, cast
from uuid import uuid4
Expand Down Expand Up @@ -158,16 +159,36 @@ def session_start(
docker.types.DeviceRequest(count=[gpu_request], capabilities=[["compute", "utility"]])
]

# NOTE: set git user
image_data = self.docker_client().api.inspect_image(image_name)
working_dir = image_data.get("Config", {}).get("WorkingDir", None)

if working_dir is None:
working_dir = "/home/jovyan"

environment = {}
volumes = [f"{str(client.path.resolve())}:{working_dir}/work"]
Panaetius marked this conversation as resolved.
Show resolved Hide resolved

global_git_config_path = os.path.normpath(os.path.expanduser("~/.gitconfig"))

if os.path.exists(global_git_config_path):
volumes.append(f"{global_git_config_path}:{working_dir}/.gitconfig")
else:
user = client.repository.get_global_user()
environment["GIT_AUTHOR_NAME"] = user.name
environment["GIT_AUTHOR_EMAIL"] = user.email

container = self.docker_client().containers.run(
image_name,
f'jupyter notebook --NotebookApp.ip="0.0.0.0" --NotebookApp.port={DockerSessionProvider.JUPYTER_PORT}'
f' --NotebookApp.token="{auth_token}" --NotebookApp.default_url="{default_url}"'
" --NotebookApp.notebook_dir=/home/jovyan/work",
f" --NotebookApp.notebook_dir={working_dir}/work",
detach=True,
labels={"renku_project": project_name, "jupyter_token": auth_token},
ports={f"{DockerSessionProvider.JUPYTER_PORT}/tcp": None},
remove=True,
volumes=[f"{str(client.path.resolve())}:/home/jovyan/work"],
environment=environment,
volumes=volumes,
**resource_requests,
)

Expand Down