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,27 +263,40 @@ 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:
|
||||||
# installing VSCODE:
|
# check if preinstalled
|
||||||
|
# noinspection PyBroadException
|
||||||
try:
|
try:
|
||||||
python_ext = StorageManager.get_local_copy(
|
vscode_path = subprocess.check_output('which code-server', shell=True).decode().strip()
|
||||||
'https://github.com/microsoft/vscode-python/releases/download/{}/ms-python-release.vsix'.format(
|
pre_installed = bool(vscode_path)
|
||||||
python_ext_version),
|
except Exception:
|
||||||
extract_archive=False)
|
vscode_path = None
|
||||||
code_server_deb = StorageManager.get_local_copy(
|
|
||||||
'https://github.com/cdr/code-server/releases/download/'
|
if not vscode_path:
|
||||||
'v{version}/code-server_{version}_amd64.deb'.format(version=vscode_version),
|
# installing VSCODE:
|
||||||
extract_archive=False)
|
try:
|
||||||
os.system("dpkg -i {}".format(code_server_deb))
|
python_ext = StorageManager.get_local_copy(
|
||||||
except Exception as ex:
|
'https://github.com/microsoft/vscode-python/releases/download/{}/ms-python-release.vsix'.format(
|
||||||
print("Failed installing vscode server: {}".format(ex))
|
python_ext_version),
|
||||||
return
|
extract_archive=False)
|
||||||
vscode_path = 'code-server'
|
code_server_deb = StorageManager.get_local_copy(
|
||||||
|
'https://github.com/cdr/code-server/releases/download/'
|
||||||
|
'v{version}/code-server_{version}_amd64.deb'.format(version=vscode_version),
|
||||||
|
extract_archive=False)
|
||||||
|
os.system("dpkg -i {}".format(code_server_deb))
|
||||||
|
except Exception as ex:
|
||||||
|
print("Failed installing vscode server: {}".format(ex))
|
||||||
|
return
|
||||||
|
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,51 +325,65 @@ def start_vscode_server(hostname, hostnames, param, task, env):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
fd, local_filename = mkstemp()
|
fd, local_filename = mkstemp()
|
||||||
subprocess.Popen(
|
if pre_installed:
|
||||||
[
|
user_folder = os.path.expanduser("~/.local/share/code-server/")
|
||||||
vscode_path,
|
if not os.path.isdir(user_folder):
|
||||||
"--auth",
|
user_folder = None
|
||||||
"none",
|
exts_folder = None
|
||||||
"--bind-addr",
|
else:
|
||||||
"127.0.0.1:{}".format(port),
|
exts_folder = os.path.expanduser("~/.local/share/code-server/extensions/")
|
||||||
"--user-data-dir", user_folder,
|
else:
|
||||||
"--extensions-dir", exts_folder,
|
subprocess.Popen(
|
||||||
"--install-extension", "ms-toolsai.jupyter",
|
[
|
||||||
# "--install-extension", "donjayamanne.python-extension-pack"
|
vscode_path,
|
||||||
] + ["--install-extension", "ms-python.python@{}".format(python_ext_version)] if python_ext else [],
|
"--auth",
|
||||||
env=env,
|
"none",
|
||||||
stdout=fd,
|
"--bind-addr",
|
||||||
stderr=fd,
|
"127.0.0.1:{}".format(port),
|
||||||
)
|
"--user-data-dir", user_folder,
|
||||||
settings = Path(os.path.expanduser(os.path.join(user_folder, 'User/settings.json')))
|
"--extensions-dir", exts_folder,
|
||||||
settings.parent.mkdir(parents=True, exist_ok=True)
|
"--install-extension", "ms-toolsai.jupyter",
|
||||||
# noinspection PyBroadException
|
# "--install-extension", "donjayamanne.python-extension-pack"
|
||||||
try:
|
] + ["--install-extension", "ms-python.python@{}".format(python_ext_version)] if python_ext else [],
|
||||||
with open(settings.as_posix(), 'rt') as f:
|
env=env,
|
||||||
base_json = json.load(f)
|
stdout=fd,
|
||||||
except Exception:
|
stderr=fd,
|
||||||
base_json = {}
|
)
|
||||||
# noinspection PyBroadException
|
|
||||||
try:
|
if user_folder:
|
||||||
base_json.update({
|
settings = Path(os.path.expanduser(os.path.join(user_folder, 'User/settings.json')))
|
||||||
"extensions.autoCheckUpdates": False,
|
settings.parent.mkdir(parents=True, exist_ok=True)
|
||||||
"extensions.autoUpdate": False,
|
# noinspection PyBroadException
|
||||||
"python.pythonPath": sys.executable,
|
try:
|
||||||
"terminal.integrated.shell.linux": "/bin/bash" if Path("/bin/bash").is_file() else None,
|
with open(settings.as_posix(), 'rt') as f:
|
||||||
})
|
base_json = json.load(f)
|
||||||
with open(settings.as_posix(), 'wt') as f:
|
except Exception:
|
||||||
json.dump(base_json, f)
|
base_json = {}
|
||||||
except Exception:
|
# noinspection PyBroadException
|
||||||
pass
|
try:
|
||||||
|
base_json.update({
|
||||||
|
"extensions.autoCheckUpdates": False,
|
||||||
|
"extensions.autoUpdate": False,
|
||||||
|
"python.pythonPath": sys.executable,
|
||||||
|
"terminal.integrated.shell.linux": "/bin/bash" if Path("/bin/bash").is_file() else None,
|
||||||
|
})
|
||||||
|
with open(settings.as_posix(), 'wt') as f:
|
||||||
|
json.dump(base_json, f)
|
||||||
|
except Exception:
|
||||||
|
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