9 The dev image
Build it yourself. Read the tutorial is the other way to read this part.
This walk goes through rahuldave/cheesecracker on GitHub. This part starts from the code at step-08. The code before this part
If you start at this part, make your clone as Get the project says, and then run this command. It puts in your clone the files that this part starts from. A file that the project deleted before this part stays, so delete it if git check lists it:
git fetch --quiet --tags --force origin; git rm -rq --cached --ignore-unmatch -- :/ && git restore --source step-08 --staged --worktree -- :/The dev image runs the checks in Linux, anywhere Docker runs.
just setupThe checks run on this machine. Another person, or a CI service, runs them on another system, with other versions of the tools. The dev image holds the whole project with every group of dependencies, and uv, just and git. So the checks run in the same Linux, anywhere Docker runs.
9.1 the dev image, to work on the project in Linux
The dev image is a fourth stage of the Dockerfile, dev. It takes uv from the stage uv, and nothing from the
run image.
Apply the patch to Dockerfile, from the top of the project:
curl -fsSL https://github.com/rahuldave/cheesecracker/commit/ccf62d330f28c6eec4c0b993e1a71e2c11a8b5af.diff | git apply --include=DockerfileApply the patch. Read the new lines at the top of the file, then the stage dev at the end. Read its line RUN uv tool install, and its line RUN uv sync --locked, which installs every group.
docker build --target dev --tag cheesecracker-dev .Near the end, the line naming to docker.io/library/cheesecracker-dev names the image.
docker image ls cheesecracker-devThe image is about 353 MB, twice the run image, because it has every tool.
Check your files against this move. The command prints nothing when they match, and otherwise shows what differs:
git check ccf62d330f28If you are stuck, this command puts the files of this move in place of yours. A file that you made yourself stays:
git fetch --quiet --tags --force origin; git restore --source step-08 --staged -- :/ && git restore --source ccf62d330f28 --staged --worktree -- :/What changed
Dockerfile: the stagedev, and its lines in the comment at the top. 26 lines added. The file- look at
FROM python:3.12-slim-bookworm AS dev
- look at
The patch to Dockerfile
@@ -2,6 +2,8 @@
#
# docker build --target run --tag cheesecracker-run .
# the production image: Python, the dependencies of the server and its code. It starts the server
+# docker build --target dev --tag cheesecracker-dev .
+# the development image: every dependency group, uv, just and git. It starts a shell
#
# The environment lives in /opt/venv, never in the project folder.
@@ -32,3 +34,27 @@ USER app
EXPOSE 9000
# Four workers, and no restart on a change: the server as it runs in production
CMD ["uvicorn", "api.service:app", "--host", "0.0.0.0", "--port", "9000", "--workers", "4"]
+
+# The dev image: the whole project with every dependency group, and uv, just and git to work in it
+FROM python:3.12-slim-bookworm AS dev
+# hadolint ignore=DL3008
+RUN apt-get update \
+ && apt-get install --yes --no-install-recommends ca-certificates curl git \
+ && rm -rf /var/lib/apt/lists/*
+COPY --from=uv /uv /uvx /usr/local/bin/
+ENV UV_PROJECT_ENVIRONMENT=/opt/venv \
+ UV_PYTHON_DOWNLOADS=never \
+ UV_LINK_MODE=copy \
+ UV_NO_CACHE=1 \
+ UV_TOOL_BIN_DIR=/usr/local/bin \
+ PATH=/opt/venv/bin:$PATH \
+ PYTHONUNBUFFERED=1
+# just, as a wheel from PyPI. git refuses a folder that another user owns, and a mounted folder
+# belongs to the user of the host, so every folder is safe
+RUN uv tool install "rust-just==1.50.0" \
+ && git config --system --add safe.directory '*'
+WORKDIR /work
+COPY pyproject.toml uv.lock .python-version ./
+RUN uv sync --locked
+COPY . .
+CMD ["bash"]9.2 just docker-shell and just docker-test
Two recipes run the dev image with this folder mounted at /work. An edit here shows in there at once, so the image
needs no rebuild after a change of the code. docker-shell opens a shell in the image. docker-test runs the recipe
that you name in the image, or just check if you name none.
Apply the patch to justfile, from the top of the project:
curl -fsSL https://github.com/rahuldave/cheesecracker/commit/0701e9244ab2384538eda4d623e1d047ff3f8258.diff | git apply --include=justfileRead the recipes docker-shell and docker-test at the end of the justfile.
just docker-testjust check runs in Linux. The last line is 21 passed. The system tests do not run, because just check leaves them
out.
just docker-test test tests/unit -qThe eleven unit tests pass in Linux.
Check your files against this move. The command prints nothing when they match, and otherwise shows what differs:
git check 0701e9244ab2If you are stuck, this command puts the files of this move in place of yours. A file that you made yourself stays:
git fetch --quiet --tags --force origin; git restore --source ccf62d330f28 --staged -- :/ && git restore --source step-09 --staged --worktree -- :/What changed
justfile: the recipesdocker-shellanddocker-test. 8 lines added. The file- look at
docker run --rm -v "$PWD":/work cheesecracker-dev just "${@:-check}"
- look at
The patch to justfile
@@ -86,3 +86,11 @@ docker-stop:
# Run the system tests against the server at http://localhost:9000. They fail when no server answers there
test-system *args:
uv run pytest tests/system "$@"
+
+# A shell in the dev image, with this folder mounted at /work: an edit here shows in there at once
+docker-shell:
+ docker run --rm -it -v "$PWD":/work cheesecracker-dev
+
+# Run a recipe in the dev image, with this folder mounted at /work. Alone, just check: just docker-test test tests/unit
+docker-test *args:
+ docker run --rm -v "$PWD":/work cheesecracker-dev just "${@:-check}"This part ends at the code at step-09. The code after this part