Dockerpyze (dpy)
Previously named poetry-dockerize-plugin
Key features:
- Automatically generate a docker image from your
uv/poetryapplication. - PEP-621 compliant.
- 100% configurable. You can configure the image by adding a section in the
pyproject.tomlconfiguration file.
Quickstart
uv
- Install it as a dev dependency:
uv add dockerpyze --dev
- Configure entrypoint in
pyproject.toml:
[tool.dpy]
entrypoint = "uv run <your-script>"
- Now straight to the point:
uv run dockerpyze
>No .dockerignore found, using a good default one 😉
>Building image: dockerpyze:latest 🔨
Successfully built images: ✅ (0.3s)
- dockerpyze:latest
- Tell your friends about this library 😉
poetry
- Move your project to
uv... well if you can't do it, you can still usepoetry. - Install the freaking plugin:
poetry self add dockerpyze@latest
- Configure entrypoint in
pyproject.toml:
[tool.dpy]
entrypoint = "poetry run <your-script>"
- Now straight to the point:
poetry dockerpyze
>No .dockerignore found, using a good default one 😉
>Building image: dockerpyze:latest 🔨
Successfully built images: ✅ (0.3s)
- dockerpyze:latest
- Tell your friends about this library 😉 (and then switch to
uv)
Configure entrypoint
It's recommended to configure the entrypoint for the docker image:
[tool.dpy]
packages = ["myapp"]
entrypoint = ["python", "myapp/main.py"]
Configuration via pyproject.toml
To customize some options, you can add a [tool.dpy] section in your pyproject.toml file. For example to change the image name:
[tool.dpy]
name = "myself/myproject-app"
Configuration via environment variables
You can also pass any option via environment variable by prefixing the key with DPY_. For example, to set the entrypoint you can use the DPY_ENTRYPOINT environment variable:
export DPY_ENTRYPOINT="python -m myapp"
uv run dockerpyze
or use a .env file which will be loaded by the plugin:
echo "DPY_ENTRYPOINT=python -m myapp" > .env
poetry dockerpyze
For dicts such as env and labels, you can set multiple values by adding multiple variables:
export DPY_ENV_MY_VAR="my_value"
export DPY_ENV_MY_OTHER_VAR="my_other_value"
export DPY_LABELS_MY_LABEL="label1"
poetry dockerpyze
Usage in GitHub Actions
You just need to run the quickstart command in your GitHub Actions workflow:
name: Build and publish latest
on:
push:
branches: main
jobs:
login:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: "Setup: Python 3.11"
uses: actions/setup-python@v4
- name: Install uv
run: python -m pip install uv
- name: Build and package
run: |
uv sync
uv run ruff
uv run pytest
uv run dockerpyze
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push to Docker Hub
run: docker push my-app:latest
Configuration API Reference
This examples shows a complete configuration of the docker image:
[tool.dpy]
name = "alternative-image-name"
packages = ["myapp"]
python = "3.12"
base-image = "python:3.12-slim"
tags = ["latest-dev"]
entrypoint = ["python", "-m", "whatever"]
ports = [5000]
env = {"MY_APP_ENV" = "dev"}
labels = {"MY_APP_LABEL" = "dev"}
apt-packages = ["curl"]
extra-run-instructions = ["RUN curl https://huggingface.co/transformers/"]
platform = "linux/amd64"
# Only for build docker layer
build-apt-packages = ["gcc"]
extra-build-instructions = ["RUN poetry config http-basic.foo <username> <password>"]
build-poetry-install-args = ["-E", "all", "--no-root"]
namecustomizes the docker image name.packagesdeclares the packages to be included in the docker image. If you they are declared in[project.scripts]or in[tool.poetry.scripts], they will be automatically added to the list.pythonpython version to use. If not specified, will try to be extracted fromtool.poetry.dependencies.python. Default is3.11base-imagecustomizes the base image. If not defined, the default base image ispython:<python-version>-slim-bookworm.tagsdeclares a list of tags for the image.entrypointcustomizes the entrypoint of the image. If not provided, the default entrypoint is retrieved from thepackagesconfiguration.portsexposes portsenvdeclares environment variables inside the docker image.labelsappend labels to the docker image. Default labels are added following the opencontainers specification.apt-packagesinstalls apt packages inside the docker image.extra-run-instructionsadds extra instructions to the docker run (after poetry install). Any modification to the filesystem will be kept after the poetry install.- 'platform' forces docker platform to be used.
For the build step:
build-apt-packagesinstalls apt packages inside the build docker container.extra-build-instructionsadds extra instructions to the docker build (before poetry install). Any modification to the filesystem will be lost after the poetry install. If you need to add files to the image, use theextra-run-instructions.build-poetry-install-argsadds additional arguments to thepoetry installcommand in the build step.
Command line options
All command line options provided by the dockerpyze may be accessed by typing:
uv run dockerpyze --help
poetry dockerpyze --help
Troubleshooting
To troubleshoot the plugin, you can use the --debug flag to get more information about the execution.
poetry dockerpyze --debug
The build is broken and --debug is completely useless? I get it.
You can generate the Dockerfile and manually build it to have more control over the problem.
uv run dockerpyze --generate
docker build Dockerfile .
It's totally fine to use the
--generateflag to generate the initialDockerfileand then customize it. I don't mind.
License
This project is licensed under the terms of the MIT license.
Issues or want to contribute?
- Open an issue
- (optional) Open a pull request and I'll merge it, maybe.
Metadata
Release files for dockerpyze 2.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| dockerpyze-2.2.0.tar.gz | 15.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dockerpyze-2.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.9 kB
Release files / dockerpyze-2.2.0.tar.gz
| Download URL | dockerpyze-2.2.0.tar.gz |
|---|---|
| Size | 15.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b33abb8c0835891740cbadf432e9643d22b17e469b0f66b3a876740580bfc8ce
|
|
BLAKE2b-256 checksum How to use checksums |
277714949515cfdab8529647dd513fea537109cdf84e926f9cd40d84e6e2bf51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / dockerpyze-2.2.0-py3-none-any.whl
| Download URL | dockerpyze-2.2.0-py3-none-any.whl |
|---|---|
| Size | 11.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1e705ff38da8e9e1794d6d82720e8a50e8465ab5b824f6dd1ffb433e90f6c9d2
|
|
BLAKE2b-256 checksum How to use checksums |
4849c00f5d76d542c4d60e362185a3310926b5aeb6f183ae321d015b6be1d014
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Security for dockerpyze 2.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.