diff --git a/app_runner/docs/changelog.md b/app_runner/docs/changelog.md index f536fa7e..a2e3341f 100644 --- a/app_runner/docs/changelog.md +++ b/app_runner/docs/changelog.md @@ -2,6 +2,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). +## \[0.0.3\] - 2024-10-24 + +### Added + +- Specify environment variables for docker container in spec. + ## \[0.0.2\] - 2024-10-23 ### Added diff --git a/app_runner/src/app_runner/app_runner/_spec.py b/app_runner/src/app_runner/app_runner/_spec.py index 8e02923f..b8f5c35f 100644 --- a/app_runner/src/app_runner/app_runner/_spec.py +++ b/app_runner/src/app_runner/app_runner/_spec.py @@ -44,6 +44,7 @@ class CommandDocker(BaseModel): command: str entrypoint: str | None = None engine: str = "docker" + env: dict[str, str] = {} mounts: MountOptions = MountOptions() def to_shell(self, work_dir: Path | None = None) -> list[str]: @@ -56,6 +57,11 @@ def to_shell(self, work_dir: Path | None = None) -> list[str]: mount_args.append("--mount") mount_args.append(f"type=bind,source={source},target={target}" + (",readonly" if read_only else "")) entrypoint_arg = ["--entrypoint", self.entrypoint] if self.entrypoint else [] + env_args = [] + for key, value in self.env.items(): + env_args.append("--env") + env_args.append(f"{key}={shlex.quote(value)}") + return [ self.engine, "run", @@ -64,6 +70,7 @@ def to_shell(self, work_dir: Path | None = None) -> list[str]: "--rm", *mount_args, *entrypoint_arg, + *env_args, self.image, *shlex.split(self.command), ]