mirror of
https://github.com/clearml/clearml-agent
synced 2025-01-31 09:06:52 +00:00
Fix run as user support in Windows and add fall-back for created user folders
This commit is contained in:
parent
b3418e4496
commit
61232d05dd
@ -17,7 +17,7 @@ from datetime import datetime
|
|||||||
from distutils.spawn import find_executable
|
from distutils.spawn import find_executable
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp, gettempdir
|
||||||
from time import sleep, time
|
from time import sleep, time
|
||||||
from typing import Text, Optional, Any, Tuple
|
from typing import Text, Optional, Any, Tuple
|
||||||
|
|
||||||
@ -2066,14 +2066,20 @@ class Worker(ServiceCommandSection):
|
|||||||
os.setuid(self.uid)
|
os.setuid(self.uid)
|
||||||
|
|
||||||
# create a home folder for our user
|
# create a home folder for our user
|
||||||
|
trains_agent_home = 'trains_agent_home{}'.format('.'+str(Singleton.get_slot()) if Singleton.get_slot() else '')
|
||||||
try:
|
try:
|
||||||
home_folder = '/trains_agent_home'
|
home_folder = (Path('/') / trains_agent_home).absolute().as_posix()
|
||||||
rm_tree(home_folder)
|
rm_tree(home_folder)
|
||||||
Path(home_folder).mkdir(parents=True, exist_ok=True)
|
Path(home_folder).mkdir(parents=True, exist_ok=True)
|
||||||
except:
|
except:
|
||||||
home_folder = '/home/trains_agent_home'
|
try:
|
||||||
rm_tree(home_folder)
|
home_folder = (Path.home().parent / trains_agent_home).absolute().as_posix()
|
||||||
Path(home_folder).mkdir(parents=True, exist_ok=True)
|
rm_tree(home_folder)
|
||||||
|
Path(home_folder).mkdir(parents=True, exist_ok=True)
|
||||||
|
except:
|
||||||
|
home_folder = (Path(gettempdir()) / trains_agent_home).absolute().as_posix()
|
||||||
|
rm_tree(home_folder)
|
||||||
|
Path(home_folder).mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
# move our entire venv into the new home
|
# move our entire venv into the new home
|
||||||
venv_folder = venv_folder.as_posix()
|
venv_folder = venv_folder.as_posix()
|
||||||
|
@ -137,3 +137,7 @@ class Singleton(object):
|
|||||||
if os.environ.get(ENV_K8S_HOST_MOUNT):
|
if os.environ.get(ENV_K8S_HOST_MOUNT):
|
||||||
return os.environ.get(ENV_K8S_HOST_MOUNT).split(':')[-1]
|
return os.environ.get(ENV_K8S_HOST_MOUNT).split(':')[-1]
|
||||||
return gettempdir()
|
return gettempdir()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_slot(cls):
|
||||||
|
return cls.instance_slot or 0
|
||||||
|
Loading…
Reference in New Issue
Block a user