Skip to content

fix(docker): docker compose build app works without a .git directory in the image - #1737

Open
dimitri-yatsenko wants to merge 3 commits into
masterfrom
fix/docker-build-version
Open

dimitri-yatsenko wants to merge 3 commits into
masterfrom
fix/docker-build-version

Conversation

@dimitri-yatsenko

@dimitri-yatsenko dimitri-yatsenko commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Summary

docker compose build app failed on master, and so did docker compose --profile test up djtest --build. The package version comes from the git tag through hatch-vcs. The Docker build context has no .git directory, so hatch-vcs found no version and pip install /main stopped with a LookupError.

The Dockerfile now gives the version explicitly. It comes from a new build argument, DJ_BUILD_VERSION, which defaults to 0.0.0+docker. To build an image that reports a release version, set it: DJ_BUILD_VERSION=2.3.7 docker compose build app.

Fixes #1723.

Changes

  • Dockerfile: a DJ_BUILD_VERSION build argument. The datajoint wheel is built alone (pip wheel --no-deps) with SETUPTOOLS_SCM_PRETEND_VERSION set to it, then installed. Dependencies are installed without the variable. Otherwise a dependency built from source with setuptools-scm would get the same version. The per-package form of the variable does not work here, because hatch-vcs does not pass the package name to setuptools-scm.
  • docker-compose.yaml: pass DJ_BUILD_VERSION to the app build (and so to djtest, which extends it).

The djtest command still runs pip install -e ".[test]" from the mounted source, which has .git, so the tests run with the real version.

Tests

  • docker compose build app fails on master with the LookupError and succeeds with this change. The image reports 0.0.0+docker by default and 2.3.7 with DJ_BUILD_VERSION=2.3.7.
  • docker compose --profile test build djtest succeeds.
  • tests/unit/test_docker_build.py checks the build files: the Dockerfile builds the wheel with the version set and without dependencies, and the compose file passes the argument. It fails before the change. Building the image in the unit tests would be too slow.
  • The unit suite passes. No library code changed, so no database integration tests apply.

Note for merging

#1726 changes the same pip install line, to add 'pymysql[rsa]'. Whichever PR merges second resolves the conflict by keeping both changes: pip install -q --no-cache-dir /tmp/dist/datajoint-*.whl 'pymysql[rsa]'.

The Docker build context has no .git directory, so hatch-vcs found no
version and 'docker compose build app' failed. The Dockerfile now builds
the datajoint wheel with SETUPTOOLS_SCM_PRETEND_VERSION set from the
DJ_BUILD_VERSION build argument (default 0.0.0+docker), then installs it.
Dependencies are installed without the variable, so none built from
source picks up that version.

Fixes #1723.
MilagrosMarin
MilagrosMarin previously approved these changes Nov 28, 2026

@MilagrosMarin MilagrosMarin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dimitri-yatsenko, I built the image to check this end to end:

  • On master, docker build fails with the setuptools-scm LookupError; with this branch it succeeds.
  • Default build reports 0.0.0+docker (both importlib.metadata and dj.__version__); --build-arg DJ_BUILD_VERSION=2.3.7 reports 2.3.7.
  • In the 2.3.7 image, only datajoint got that version, so the pretend version stays scoped to the wheel as intended.
  • An editable install from a clone with .git inside the built image reports the real git version (2.3.5.devN+g...), so the djtest path is unaffected; the env var is set inline in the RUN step and does not persist in the image.
  • Both new unit tests pass and both fail with master's Dockerfile and compose file restored.

Scoping the version to the datajoint wheel alone is the right call for keeping source-built dependencies honest.

@dimitri-yatsenko

Copy link
Copy Markdown
Member Author

Merged master in (e97c974) after #1726. The Dockerfile conflict is resolved as the description says, keeping both changes: pip install -q --no-cache-dir /tmp/dist/datajoint-*.whl 'pymysql[rsa]'. Built the image locally with --build-arg DJ_BUILD_VERSION=2.3.7.dev0: datajoint.__version__ is 2.3.7.dev0 and cryptography imports. The push dismissed the approval; it needs a re-approval.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docker compose build app fails: hatch-vcs finds no version in the image

2 participants