Say what is wrong when the user id is not a number

A compose .env file is read literally, so MCP_UID=$(id -u) written there arrives
as those eight characters. What came back was "groupadd: invalid group ID", from
a line four steps into a build - true, but it names neither the variable nor the
file that holds it. The build now refuses with both, and says that the file wants
the output of the command rather than the command.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lucio Lelii 2026-09-22 12:26:36 +02:00
parent d19fa7ba4e
commit a5769114eb
2 changed files with 6 additions and 0 deletions

View File

@ -29,6 +29,10 @@ RUN apt-get update \
ARG MCP_UID=10001
ARG MCP_GID=10001
RUN set -eux; \
case "${MCP_UID}${MCP_GID}" in *[!0-9]*) \
echo "MCP_UID and MCP_GID must be plain numbers; got '${MCP_UID}' and '${MCP_GID}'." >&2; \
echo "A compose .env file takes literal values: write the output of 'id -u', not the command." >&2; \
exit 2;; esac; \
if ! getent group "${MCP_GID}" >/dev/null; then groupadd -g "${MCP_GID}" mcp; fi; \
if ! getent passwd "${MCP_UID}" >/dev/null; then useradd -r -u "${MCP_UID}" -g "${MCP_GID}" -M -d /nonexistent mcp; fi; \
mkdir -p /tmp/dev-server /instances /npm-cache; \

View File

@ -6,6 +6,8 @@ DEV_SERVER_WORKER_TOKEN=replace-with-a-private-worker-token-32-chars
# Use a dedicated project directory, never a home directory or filesystem root.
MCP_WORKSPACE_HOST_PATH=/absolute/path/to/project
# Whoever owns the workspace directory on the host. This file is read literally - no shell runs
# over it - so write the numbers that 'id -u' and 'id -g' print, not the commands themselves.
MCP_UID=10001
MCP_GID=10001