This repo provides an example of a trio of applications across a pair of projects, where each project uses a different virtualenv with extensive Docker integration. The intent is to provide an example of current Bazel x Python x Docker ecosystem patterns.
- Clone the repo
- Install
direnv - Install bazelisk
direnv allowthe repo- Follow the directions to configure the repo tools via Bazel
rehashwhich dazelshould show a program underbazel-bindazel build //...will build a dev container image, cache it, boot it and invoke the requested Bazel task within itdocker pswill show you a runningdazel-${WORKSPACE}-${HASH1}-${HASH2}server containerdazel test //...will run all the tests inside your dev container
Note that bazel and dazel are purposefully kept separate as there are use-cases for each.
dazel could be made the default behavior by linking tools/bazel to tools/dazel/dazel-client.sh, but that can produce some surprising behavior.
rules_uvused to implement requirements lock management (:requirements.update)rules_pythonused to fetch a hermetic Python toolchain and Pip deps; seeMODULE.bazelfor details.aspect_rules_pyused to provide familiar Pytest flows//tools/dockerimplements building a "base" and "dev" image//tools/dazel:dazelimplements builds under Docker with a persistent devcontainer defined usingrules_ocibazel_env+direnvputsdazelon the$PATHfor convenience
- Changes to
Dockerfile-baseorDockerfile-devwill cause image rebuilds automatically - Changes to the
dazeldevcontainer configuration (including invalidation of the image target!) will cause a restart - The
dazeldevcontainer makes its outputs available natively in the host filesystem (dazel-bin, etc)
- The
dazeltool is quick work and could use refinement - The
dazeltool could try to mount the Docker socket through to the dev container for DIND shenanigans - The
:*.digestrules being uncacheable is proof against Docker engine cleans, but a bit slow. Slightly risky operationally but would be faster to allow the loaded digests to cache so that Dazel can hit the cache.
This code is of educational value only and is provided under the terms of the WTFPBL. Use at your own risk.