Skip to content

Pass environment to docker container for local-test#409

Closed
dphuang2 wants to merge 1 commit intomainfrom
pass-dot-env-to-docker-container
Closed

Pass environment to docker container for local-test#409
dphuang2 wants to merge 1 commit intomainfrom
pass-dot-env-to-docker-container

Conversation

@dphuang2
Copy link
Collaborator

@dphuang2 dphuang2 commented Jan 14, 2026

Note

Introduces .env support and forwards env vars to Docker for local-test.

  • Forward key-value pairs from .env.dev/.env into the docker run environment in local_test.py
  • Add find_dotenv_path and get_dotenv_values in auth.py; auto-load .env.dev then .env on import (without overriding existing env)
  • Small typing/import updates

Written by Cursor Bugbot for commit 838c7a5. This will update automatically on new commits. Configure here.

…iable loading into local test command. Introduced functions to find and retrieve values from .env files, enhancing configuration management for Docker tests.
dotenv_vars = get_dotenv_values(project_root)
for key, value in dotenv_vars.items():
if value is not None:
cmd += ["-e", f"{key}={value}"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dotenv variables may override critical container settings

Medium Severity

Environment variables from the .env file are added after the hardcoded HOME and EVAL_PROTOCOL_DIR settings. In Docker, when the same -e flag is specified multiple times, the last value wins. If a user's .env file contains HOME or EVAL_PROTOCOL_DIR, these values would override the container's critical configuration (HOME=/container_home, EVAL_PROTOCOL_DIR=/container_home/.eval_protocol), potentially breaking the container's ability to write logs and artifacts to the mounted volume.

Fix in Cursor Fix in Web

env_path = find_dotenv(filename=".env", raise_error_if_not_found=False, usecwd=True)
if env_path:
return env_path
return None
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent dotenv search behavior between host and Docker

Medium Severity

The find_dotenv_path function behaves differently depending on whether search_path is provided. Without an argument, it searches up the directory tree using find_dotenv(). With a path, it only looks in that exact directory. The module-level load uses the former (finding parent .env files), while get_dotenv_values(project_root) uses the latter. This means environment variables from a parent directory's .env file are loaded into the host but not forwarded to Docker, causing tests to pass locally but fail in the container.

Additional Locations (1)

Fix in Cursor Fix in Web

@dphuang2 dphuang2 closed this Jan 14, 2026
@dphuang2 dphuang2 deleted the pass-dot-env-to-docker-container branch January 14, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant