mirror of
https://github.com/clearml/clearml-session
synced 2025-03-13 15:18:09 +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 = dict(**env)
|
||||||
env.pop('PYTHONPATH', None)
|
env.pop('PYTHONPATH', None)
|
||||||
|
|
||||||
|
pre_installed = False
|
||||||
|
python_ext = None
|
||||||
|
|
||||||
# find a free tcp port
|
# find a free tcp port
|
||||||
port = get_free_port(9000, 9100)
|
port = get_free_port(9000, 9100)
|
||||||
|
|
||||||
if os.geteuid() == 0:
|
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:
|
# installing VSCODE:
|
||||||
try:
|
try:
|
||||||
python_ext = StorageManager.get_local_copy(
|
python_ext = StorageManager.get_local_copy(
|
||||||
@ -284,6 +296,7 @@ def start_vscode_server(hostname, hostnames, param, task, env):
|
|||||||
vscode_path = 'code-server'
|
vscode_path = 'code-server'
|
||||||
else:
|
else:
|
||||||
python_ext = None
|
python_ext = None
|
||||||
|
pre_installed = True
|
||||||
# check if code-server exists
|
# check if code-server exists
|
||||||
# noinspection PyBroadException
|
# noinspection PyBroadException
|
||||||
try:
|
try:
|
||||||
@ -312,6 +325,14 @@ def start_vscode_server(hostname, hostnames, param, task, env):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
fd, local_filename = mkstemp()
|
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(
|
subprocess.Popen(
|
||||||
[
|
[
|
||||||
vscode_path,
|
vscode_path,
|
||||||
@ -328,6 +349,8 @@ def start_vscode_server(hostname, hostnames, param, task, env):
|
|||||||
stdout=fd,
|
stdout=fd,
|
||||||
stderr=fd,
|
stderr=fd,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if user_folder:
|
||||||
settings = Path(os.path.expanduser(os.path.join(user_folder, 'User/settings.json')))
|
settings = Path(os.path.expanduser(os.path.join(user_folder, 'User/settings.json')))
|
||||||
settings.parent.mkdir(parents=True, exist_ok=True)
|
settings.parent.mkdir(parents=True, exist_ok=True)
|
||||||
# noinspection PyBroadException
|
# noinspection PyBroadException
|
||||||
@ -348,15 +371,19 @@ def start_vscode_server(hostname, hostnames, param, task, env):
|
|||||||
json.dump(base_json, f)
|
json.dump(base_json, f)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
proc = subprocess.Popen(
|
proc = subprocess.Popen(
|
||||||
['bash', '-c',
|
['bash', '-c',
|
||||||
'{} --auth none --bind-addr 127.0.0.1:{} --disable-update-check '
|
'{} --auth none --bind-addr 127.0.0.1:{} --disable-update-check {} {}'.format(
|
||||||
'--user-data-dir {} --extensions-dir {}'.format(vscode_path, port, user_folder, exts_folder)],
|
vscode_path, port,
|
||||||
|
'--user-data-dir \"{}\"'.format(user_folder) if user_folder else '',
|
||||||
|
'--extensions-dir \"{}\"'.format(exts_folder) if exts_folder else '')],
|
||||||
env=env,
|
env=env,
|
||||||
stdout=fd,
|
stdout=fd,
|
||||||
stderr=fd,
|
stderr=fd,
|
||||||
cwd=cwd,
|
cwd=cwd,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
error_code = proc.wait(timeout=1)
|
error_code = proc.wait(timeout=1)
|
||||||
raise ValueError("code-server failed starting, return code {}".format(error_code))
|
raise ValueError("code-server failed starting, return code {}".format(error_code))
|
||||||
|
Loading…
Reference in New Issue
Block a user