Skip to content

Commit e378e20

Browse files
committed
add pdm run e2e:test:docker
this commit adds a new `Dockerfile.e2e-test` just for running the end-to-end tests inside a Docker container. This is useful if you don't have Nix in your local environment.
1 parent 4bbb6c9 commit e378e20

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ share/python-wheels/
2525
.installed.cfg
2626
*.egg
2727
MANIFEST
28+
/result
2829

2930
# PyInstaller
3031
# Usually these files are written by a python script from a template
@@ -174,4 +175,4 @@ cython_debug/
174175
.pypirc
175176

176177
# Test Reports (directories)
177-
reports-*/
178+
reports-*/

Dockerfile.e2e-test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM docker.nix-community.org/nixpkgs/nix-flakes AS builder
2+
3+
# Don't stay in the root directory for this.
4+
# https://github.com/NixOS/nix/issues/11217
5+
WORKDIR /workspace
6+
7+
# Copy just enough for Nix pdm install without bringing in the entire project.
8+
# This ensures we don't run the nix develop too often.
9+
COPY flake.nix flake.lock pyproject.toml pdm.lock .
10+
11+
# Build Nix shell and install all dev PDM dependencies.
12+
RUN nix develop path:///workspace -c pdm sync -d
13+
14+
# Copy the actual module and E2E tests.
15+
# This is what will be edited during development, so we run it last.
16+
COPY inference_perf e2e .
17+
18+
# Default command is to run the E2E tests, but you may override this with any
19+
# pdm or bash command (e.g., docker run -it <TAG> -- bash).
20+
ENTRYPOINT ["nix", "develop", "path:///workspace", "-c"]
21+
CMD ["pdm", "run", "test:e2e"]

flake.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@
6060
];
6161

6262
venvDir = "venv";
63+
64+
shellHook = ''
65+
# This isn't needed anywhere except for inside the Dockerfile environment, since we
66+
# try to do `pdm install` without actually having any actual code present for better
67+
# image layering.
68+
export PYTHONPATH="$PYTHONPATH:$PWD"
69+
'';
6370
};
6471

6572
packages = rec {

pyproject.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,15 @@ distribution = true
6565
[tool.pdm.scripts]
6666
format = "ruff format"
6767
lint = "ruff check"
68-
test = "pytest tests"
69-
"test:e2e" = "pytest e2e"
7068
type-check = "mypy --strict ./inference_perf ./tests"
7169
validate = {composite = ["format", "lint", "type-check"]}
7270

71+
"test" = "pytest tests"
72+
"test:e2e" = "pytest e2e"
73+
"test:e2e:docker" = "docker:e2e-test:run"
74+
"docker:e2e-test:build".cmd = "docker buildx b -f Dockerfile.e2e-test {args:-t inference-perf-e2e-test} ."
75+
"docker:e2e-test:run".shell = "pdm run docker:e2e-test:build --iidfile result && docker run --rm -it -v $PWD:/workspace $(< result)"
76+
7377
[tool.ruff]
7478
# The GitHub editor is 127 chars wide
7579
line-length = 127

0 commit comments

Comments
 (0)