Development
This commit is contained in:
parent
abf05a60fb
commit
831bc88a92
4 changed files with 24 additions and 10 deletions
|
|
@ -42,6 +42,19 @@ def die(msg):
|
|||
sys.exit(1)
|
||||
|
||||
|
||||
def _compose_env():
|
||||
"""Return an env dict with HOME set to the invoking user's home, not root's."""
|
||||
import pwd
|
||||
sudo_user = os.environ.get('SUDO_USER')
|
||||
if sudo_user:
|
||||
try:
|
||||
home = pwd.getpwnam(sudo_user).pw_dir
|
||||
return {**os.environ, 'HOME': home}
|
||||
except KeyError:
|
||||
pass
|
||||
return os.environ.copy()
|
||||
|
||||
|
||||
def check_root():
|
||||
if os.geteuid() != 0:
|
||||
die("This script must be run as root (sudo python3 install.py).")
|
||||
|
|
@ -250,19 +263,20 @@ def setup_docker_compose(reuse_config=False):
|
|||
if reuse_config:
|
||||
import time
|
||||
cache_bust = str(int(time.time()))
|
||||
env = _compose_env()
|
||||
print("\n Stopping existing container...")
|
||||
subprocess.run(["docker", "compose", "down"], cwd=COMPOSE_FILE.parent, check=False)
|
||||
subprocess.run(["docker", "compose", "down"], cwd=COMPOSE_FILE.parent, env=env, check=False)
|
||||
print("\n Building dashboard image...")
|
||||
result = subprocess.run(
|
||||
["docker", "compose", "build", "--build-arg", f"CACHE_BUST={cache_bust}"],
|
||||
cwd=COMPOSE_FILE.parent, check=False
|
||||
cwd=COMPOSE_FILE.parent, env=env, check=False
|
||||
)
|
||||
if result.returncode != 0:
|
||||
die("docker compose build failed. Check the output above.")
|
||||
print("\n Starting dashboard container...")
|
||||
result = subprocess.run(
|
||||
["docker", "compose", "up", "-d"],
|
||||
cwd=COMPOSE_FILE.parent, check=False
|
||||
cwd=COMPOSE_FILE.parent, env=env, check=False
|
||||
)
|
||||
if result.returncode != 0:
|
||||
die("docker compose up failed. Check the output above.")
|
||||
|
|
@ -301,14 +315,14 @@ def setup_docker_compose(reuse_config=False):
|
|||
COMPOSE_FILE.write_text(content)
|
||||
print(f"\n Written: {COMPOSE_FILE}")
|
||||
|
||||
env = _compose_env()
|
||||
print("\n Stopping existing container...")
|
||||
subprocess.run(["docker", "compose", "down"], cwd=COMPOSE_FILE.parent, check=False)
|
||||
subprocess.run(["docker", "compose", "down"], cwd=COMPOSE_FILE.parent, env=env, check=False)
|
||||
|
||||
print("\n Starting dashboard container...")
|
||||
compose_dir = COMPOSE_FILE.parent
|
||||
result = subprocess.run(
|
||||
["docker", "compose", "up", "-d", "--build"],
|
||||
cwd=compose_dir, check=False
|
||||
cwd=COMPOSE_FILE.parent, env=env, check=False
|
||||
)
|
||||
if result.returncode != 0:
|
||||
die("docker compose up failed. Check the output above.")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue