mirror of
https://github.com/clearml/clearml-session
synced 2025-03-13 07:08:08 +00:00
Fix support for pre-installed vscode-server in container
This commit is contained in:
parent
363764b332
commit
9192a64729
@ -263,10 +263,22 @@ def start_vscode_server(hostname, hostnames, param, task, env):
|
||||
env = dict(**env)
|
||||
env.pop('PYTHONPATH', None)
|
||||
|
||||
pre_installed = False
|
||||
python_ext = None
|
||||
|
||||
# find a free tcp port
|
||||
port = get_free_port(9000, 9100)
|
||||
|
||||
if os.geteuid() == 0:
|
||||
# check if preinstalled
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
vscode_path = subprocess.check_output('which code-server', shell=True).decode().strip()
|
||||
pre_installed = bool(vscode_path)
|
||||
except Exception:
|
||||
vscode_path = None
|
||||
|
||||
if not vscode_path:
|
||||
# installing VSCODE:
|
||||
try:
|
||||
python_ext = StorageManager.get_local_copy(
|
||||
@ -284,6 +296,7 @@ def start_vscode_server(hostname, hostnames, param, task, env):
|
||||
vscode_path = 'code-server'
|
||||
else:
|
||||
python_ext = None
|
||||
pre_installed = True
|
||||
# check if code-server exists
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
@ -312,6 +325,14 @@ def start_vscode_server(hostname, hostnames, param, task, env):
|
||||
|
||||
try:
|
||||
fd, local_filename = mkstemp()
|
||||
if pre_installed:
|
||||
user_folder = os.path.expanduser("~/.local/share/code-server/")
|
||||
if not os.path.isdir(user_folder):
|
||||
user_folder = None
|
||||
exts_folder = None
|
||||
else:
|
||||
exts_folder = os.path.expanduser("~/.local/share/code-server/extensions/")
|
||||
else:
|
||||
subprocess.Popen(
|
||||
[
|
||||
vscode_path,
|
||||
@ -328,6 +349,8 @@ def start_vscode_server(hostname, hostnames, param, task, env):
|
||||
stdout=fd,
|
||||
stderr=fd,
|
||||
)
|
||||
|
||||
if user_folder:
|
||||
settings = Path(os.path.expanduser(os.path.join(user_folder, 'User/settings.json')))
|
||||
settings.parent.mkdir(parents=True, exist_ok=True)
|
||||
# noinspection PyBroadException
|
||||
@ -348,15 +371,19 @@ def start_vscode_server(hostname, hostnames, param, task, env):
|
||||
json.dump(base_json, f)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
proc = subprocess.Popen(
|
||||
['bash', '-c',
|
||||
'{} --auth none --bind-addr 127.0.0.1:{} --disable-update-check '
|
||||
'--user-data-dir {} --extensions-dir {}'.format(vscode_path, port, user_folder, exts_folder)],
|
||||
'{} --auth none --bind-addr 127.0.0.1:{} --disable-update-check {} {}'.format(
|
||||
vscode_path, port,
|
||||
'--user-data-dir \"{}\"'.format(user_folder) if user_folder else '',
|
||||
'--extensions-dir \"{}\"'.format(exts_folder) if exts_folder else '')],
|
||||
env=env,
|
||||
stdout=fd,
|
||||
stderr=fd,
|
||||
cwd=cwd,
|
||||
)
|
||||
|
||||
try:
|
||||
error_code = proc.wait(timeout=1)
|
||||
raise ValueError("code-server failed starting, return code {}".format(error_code))
|
||||
|
Loading…
Reference in New Issue
Block a user