Skip to content

Commit 702d94f

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 e856198 commit 702d94f

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

Dockerfile.e2e-test

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 -c pdm install --dev --frozen-lockfile --no-editable
13+
14+
# Copy the rest of the source code.
15+
COPY . .
16+
17+
# Ensure PYTHONPATH contains our current WORKDIR so that the main module can be
18+
# found.
19+
ENV PYTHONPATH="$PYTHONPATH:/workspace"
20+
21+
# Default command is to run the E2E tests, but you may override this with any
22+
# pdm or bash command (e.g., docker run -it <TAG> -- bash).
23+
ENTRYPOINT ["nix", "develop", "-c"]
24+
CMD ["pdm", "run", "test:e2e"]

flake.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@
6464
];
6565

6666
venvDir = "venv";
67+
68+
shellHook = ''
69+
# This isn't needed anywhere except for inside the Dockerfile environment, since we
70+
# try to do `pdm install` without actually having any actual code present for better
71+
# image layering.
72+
export PYTHONPATH="$PYTHONPATH:$PWD"
73+
'';
6774
};
6875

6976
packages = rec {

pyproject.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,14 @@ distribution = true
6565
[tool.pdm.scripts]
6666
format = "ruff format"
6767
lint = "ruff check"
68-
test = "pytest tests"
68+
69+
"test" = "pytest tests"
6970
"test:e2e" = "pytest e2e"
71+
"test:e2e:docker".composite = ["docker:e2e-test:build", "docker:e2e-test:run"]
72+
73+
"docker:e2e-test:build" = "docker build -f Dockerfile.e2e-test -t inference-perf-e2e-test ."
74+
"docker:e2e-test:run" = "docker run --rm -it inference-perf-e2e-test"
75+
7076
type-check = "mypy --strict ./inference_perf ./tests"
7177
validate = {composite = ["format", "lint", "type-check"]}
7278

0 commit comments

Comments
 (0)