fix(docker): HERMES_UID and HERMES_GID usage in container + feature(docker): add new SYNC_CODE_DIR environment variable#12623
fix(docker): HERMES_UID and HERMES_GID usage in container + feature(docker): add new SYNC_CODE_DIR environment variable#12623mmartial wants to merge 2 commits into
Conversation
…cted + Feature: Add rsync for SYNC_CODE_DIR usage
… (using rsync) of the hermes agent source code in an external (mounted) location so that 3rd party tools can have access to it to install the version running in the container in their own venv (or use the requirements.txt for their installation). If the variable is not present, nothing is different from the regular usage
|
Closing since #12696 and nesquena/hermes-webui#1046 |
|
I would reopen the following PR based on mmartial/unraid-templates#2 (comment) |
|
I have recently added Hermes Agent to Unraid. To share content across all 3 Docker images, we must use a named Docker volume. This addition would allow a bind mount to support this feature. |
What does this PR do?
The entrypoint contains runtime ownership/remap logic that only works correctly when the container starts as
root. After the image build switched to running ashermes, that logic no longer had the privileges needed to honorHERMES_UID/HERMES_GID.Separately, some downstream/containerized workflows need access to the exact Hermes source code shipped in the image so they can install it into their own virtualenv or consume files like requirements.txt from a mounted path.
This PR makes two Docker-focused changes:
HERMES_UID/HERMES_GIDbehavior by switching the image back torootbefore the runtime entrypoint executes.SYNC_CODE_DIRenvironment variable thatrsyncs the installed Hermes source tree to a writable external directory at container startup (to allow third party solutions to add hermes agent to their venv; example: Hermes WebUI)Related Issue
I did not see an existing issue, and created one #12696
I discovered the issue while trying to use
HERMES_UIDandHERMES_GIDand found that they were not being respected (the intent was to provide an Unraid template for Hermes Agent, and the Hermes WebUI project; the second one would need the new feature to function)The root cause is the
USER hermesusage in theDockerfilewhile theentrypoint.shchecks againstid = 0(ie therootuser)Type of Change
Changes Made
Dockerfile:
USER rootafter dependency installation so theentrypoint.shcan perform UID/GID and ownership setup correctly at runtimedocker/entrypoint.shSYNC_CODE_DIRsupport. IfSYNC_CODE_DIRpoints to an existing writable directory, the entrypoint copies/opt/hermesinto it withrsync(excludes runtime/build noise such as.venv,.git,__pycache__,*.pyc,*.pyo, and.playwright+ uses--deleteso the synced directory stays aligned with the source tree across restarts). Fails open: if the sync target is missing or not writable, container startup continues normallyBehavior: Default behavior is unchanged when
SYNC_CODE_DIRis unset. The sync is best-effort and does not block container startup. This is mainly useful for bind-mounted development workflows and derived images that want to install Hermes into a separate venv.How to Test
docker build -f Dockerfile --tag ha:test .mkdir -p ../test/{data,src}docker run --rm -it -e HERMES_UID=$(id -u) -e HERMES_GID=$(id -g) -v $(pwd)/../test/data:/test/data -e HERMES_HOME=/test/data -v $(pwd)/../test/src:/test/src -e SYNC_CODE_DIR=/test/src ha:testResult:
Local folders:
../test/datacontains the hermes runtime (includingconfig.yaml, ...) owned by user matchingHERMES_UIDandHERMES_GID../test/srccontains the content of/opt/hermes(without the.venvand other dropped files/folders) to support usage with 3rd party extensions more easilyChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/A