Development

This commit is contained in:
Matthew Grotke 2026-05-22 02:54:56 -04:00
parent abf05a60fb
commit 831bc88a92
4 changed files with 24 additions and 10 deletions

View file

@ -2,7 +2,7 @@ import json, subprocess, hashlib, os, uuid
from datetime import datetime, timezone
from flask import session
CONFIGS_DIR = '/configs'
CONFIGS_DIR = '/routlin_location'
CORE_FILE = f'{CONFIGS_DIR}/core.json'
DASHBOARD_QUEUE = f'{CONFIGS_DIR}/.dashboard-queue'
DASHBOARD_DONE = f'{CONFIGS_DIR}/.dashboard-done'

View file

@ -9,7 +9,7 @@ from config_utils import core_hash, get_pending_entries, get_dashboard_pending,
bp = Blueprint('view_page', __name__)
DATA_DIR = '/data'
CONFIGS_DIR = '/configs'
CONFIGS_DIR = '/routlin_location'
LEVEL_RANK = {'nothing': 0, 'viewer': 1, 'administrator': 2, 'manager': 3}

View file

@ -8,11 +8,11 @@ services:
- "25327:25327"
volumes:
- ./data:/data
- $HOME/routlin:/configs
- $HOME/routlin/validation.py:/app/validation.py
- $HOME/routlin:/routlin_location
- /sys/class/net:/sys/class/net:ro
- /sys/devices:/sys/devices:ro
environment:
- PYTHONPATH=/routlin_location
- PRODUCT_DISPLAY_NAME=Routlin Dashboard
- INITIAL_MANAGER_EMAIL=mgrotke@gmail.com
- SECRET_KEY=ey8hSQCCYE5kQXV8nOg1CB44LSd3AoUet2ZBc3aZlFrwBbazE7aHcxXWyuT97eAObet5jmOL0CjMg0rB1hE4d2SBVYHPfl8De55EiFv307r1QP3Mf5XgOSSCxD3TuD

View file

@ -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.")