Skip to content

Commit

Permalink
allow Dockerfile to have a name (#1232)
Browse files Browse the repository at this point in the history
* allow dockerfile to have a name

since the `config` in a `SandboxEnvironmentSpec` can be an arbitrary path

* add test for is_dockerfile

* mypy doesn't like the reassignment

* minor

---------

Co-authored-by: jjallaire <jj.allaire@gmail.com>
  • Loading branch information
tadamcz and jjallaire authored Feb 7, 2025
1 parent 8ffbe40 commit 8c7ca3e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/inspect_ai/util/_sandbox/docker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def find_compose_file(parent: str = "") -> str | None:


def is_dockerfile(file: str) -> bool:
return os.path.basename(file) == DOCKERFILE
path = Path(file)
return path.name == DOCKERFILE or path.suffix == f".{DOCKERFILE}"


def has_dockerfile(parent: str = "") -> bool:
Expand Down
7 changes: 7 additions & 0 deletions tests/util/sandbox/test_sandbox_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from inspect_ai.scorer import CORRECT, includes
from inspect_ai.solver import Generate, Solver, TaskState, solver
from inspect_ai.util import sandbox
from inspect_ai.util._sandbox.docker.config import is_dockerfile

SANDBOX_SETUP_FILE = (Path(__file__).parent / "sandbox_setup.sh").as_posix()
SANDBOX_SETUP_ERROR_FILE = (Path(__file__).parent / "sandbox_setup_error.sh").as_posix()
Expand Down Expand Up @@ -84,5 +85,11 @@ def test_docker_sandbox_setup_fail_on_error():
assert log.samples[0].error


def test_is_dockerfile():
assert is_dockerfile("/path/to/Dockerfile")
assert is_dockerfile("/path/to/name.Dockerfile")
assert not is_dockerfile("/path/to/not_a_dockerfile.txt")


if __name__ == "__main__":
test_docker_sandbox_setup()

0 comments on commit 8c7ca3e

Please sign in to comment.