Skip to content

Commit

Permalink
allow to specify env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
leoschwarz committed Oct 24, 2024
1 parent 8856831 commit a19a2c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app_runner/docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions app_runner/src/app_runner/app_runner/_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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",
Expand All @@ -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),
]
Expand Down

0 comments on commit a19a2c7

Please sign in to comment.