From 26c24867e664ef23833d257d13a246635cfed047 Mon Sep 17 00:00:00 2001 From: Nathan Esquenazi Date: Sun, 12 Apr 2026 13:27:21 -0700 Subject: [PATCH] fix: Docker container restart without recreating (#324) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit uv venv fails with 'A virtual environment already exists' when the container is stopped and started (not removed). The venv persists in the container filesystem between stop/start cycles. Fix: skip venv creation and dependency installation if they already exist from a previous run. Uses two checks: - /app/venv/bin/python3 exists → skip venv creation - /app/venv/.deps_installed marker → skip pip install This also makes restarts much faster since deps don't need to be reinstalled every time the container starts. Fixes #324 Co-Authored-By: Claude Opus 4.6 (1M context) --- docker_init.bash | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/docker_init.bash b/docker_init.bash index acb9899..86dbbdf 100644 --- a/docker_init.bash +++ b/docker_init.bash @@ -204,7 +204,12 @@ sudo mkdir -p ${UV_CACHE_DIR} || error_exit "Failed to create /uv_cache director sudo chown hermeswebui:hermeswebui ${UV_CACHE_DIR} || error_exit "Failed to set owner of ${UV_CACHE_DIR} to hermeswebui user" cd /app -uv venv venv +if [ -f /app/venv/bin/python3 ]; then + echo ""; echo "== Existing virtual environment found — reusing (fast restart)" +else + echo ""; echo "== Creating new virtual environment" + uv venv venv +fi export VIRTUAL_ENV=/app/venv test -d /app/venv test -f /app/venv/bin/activate @@ -213,13 +218,18 @@ echo "";echo "== Activating hermes webui's virtual environment" source /app/venv/bin/activate || error_exit "Failed to activate hermeswebui virtual environment" test -x /app/venv/bin/python3 -echo ""; echo "== Installing hermes-webui dependencies" -uv pip install -r requirements.txt --trusted-host pypi.org --trusted-host files.pythonhosted.org -uv pip install -U pip setuptools --trusted-host pypi.org --trusted-host files.pythonhosted.org -test -x /app/venv/bin/pip +if [ -f /app/venv/.deps_installed ]; then + echo ""; echo "== Dependencies already installed — skipping (fast restart)" +else + echo ""; echo "== Installing hermes-webui dependencies" + uv pip install -r requirements.txt --trusted-host pypi.org --trusted-host files.pythonhosted.org + uv pip install -U pip setuptools --trusted-host pypi.org --trusted-host files.pythonhosted.org + test -x /app/venv/bin/pip -echo ""; echo "== Adding hermes-agent's pyproject.toml base dependencies to the virtual environment" -uv pip install /home/hermeswebui/.hermes/hermes-agent --trusted-host pypi.org --trusted-host files.pythonhosted.org || error_exit "Failed to install hermes-agent's requirements" + echo ""; echo "== Adding hermes-agent's pyproject.toml base dependencies to the virtual environment" + uv pip install /home/hermeswebui/.hermes/hermes-agent --trusted-host pypi.org --trusted-host files.pythonhosted.org || error_exit "Failed to install hermes-agent's requirements" + touch /app/venv/.deps_installed +fi echo ""; echo "== Running hermes-webui" cd /app; python server.py || error_exit "hermes-webui failed or exited with an error"