Help generating docker images from PDM projects
Project description
pdm-dockerize
Help generating docker image from PDM projects.
Installation
Install pdm-dockerize
:
With pipx
If you installed pdm
with pipx
and want to have the command for all projects:
pipx inject pdm pdm-dockerize
With pip
If you manually installed pdm
with pip
, just install the extra dependency in the same environment:
pip install pdm-dockerize
With pdm
You can also install it as a standard pdm
plugin.
Either globally:
pdm self add pdm-dockerize
Either as a local plugin in your project:
[tool.pdm]
plugins = [
"pdm-dockerize",
]
Then:
pdm install --plugins
Usage
Just use pdm dockerize
in your multistage build:
# syntax=docker/dockerfile:1
ARG PY_VERSION=3.11
##
# Build stage: build and install dependencies
##
FROM python:${PY_VERSION} AS builder
ARG VERSION=0.dev
ENV PDM_BUILD_SCM_VERSION=${VERSION}
WORKDIR /project
# install PDM
RUN pip install -U pip setuptools wheel
RUN pip install pdm pdm-dockerize
RUN --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
--mount=type=bind,source=pdm.lock,target=pdm.lock \
--mount=type=cache,target=$HOME/.cache,uid=$UUID \
pdm dockerize --prod -v
##
# Run stage: create the final runtime container
##
FROM python:${PY_VERSION} AS runtime
WORKDIR /app
# Fetch built dependencies
COPY --from=builder /project/dist/docker /app
# Copy needed files from your project (filter using `.dockerignore`)
COPY . /app
ENTRYPOINT ["/app/entrypoint"]
CMD ["your-default-command"]
Selecting scripts
By default, the dockerize
command will render a script without any command as it does not select any script by default.
You can select scripts with the include
and exclude
properties of the tool.pdm.dockerize
section.
Those properties are optional, can be either a string or list of string.
Each string is a fnmatch
filter pattern
Dockerize first select script based on the include patterns and then filter-out those matching with any exclude pattern.
Include all scripts
[tool.pdm.dockerize]
include = "*"
Include some specific scripts
[tool.pdm.dockerize]
include = ["my-script", "my-other-script"]
Include all scripts excluding those matching prefix-*
[tool.pdm.dockerize]
include = "*"
exclude = "prefix-*"
Include all scripts matching a prefix but two
[tool.pdm.dockerize]
include = "prefix-*"
exclude = ["prefix-not-you", "prefix-you-neither"]
Selecting binaries
By default, the dockerize
command will not copy any python executable provided by your dependencies.
You can select binaries with the include_bins
and exclude_bins
properties of the tool.pdm.dockerize
section.
Syntax and behavior are exactly the exact sames than include
/exclude
for script selection.
Include all python executables
[tool.pdm.dockerize]
include_bins = "*"
Include some specific executables
Most of the time, you will look like this
[tool.pdm.dockerize]
include = ["uvicorn"]
Controlling environment
pdm-dockerize
respects defined environment variables:
- scripts
env
variables are properly set - shared
_.env
variables are properly set - scripts
env_file
are properly loaded - shared
_.env_file
are properly loaded
In addition, you can define some docker-only environment variables using the tool.pdm.dockerize.env
table
or some docker-only .env
files using tool.pdm.dockerize.env_file
Defining docker-only environment variables
Those environment variables will only be effective in the docker entrypoint.
[tool.pdm.dockerize.env]
VAR = "value"
Loading docker-only environment files
This file will only be loaded in the docker entrypoint.
[tool.pdm.dockerize]
env_file = "docker.env"
Internals
This plugin works by providing by subclassing some pdm.installers
classes to reuse the installation process:
DockerizeInstallManager
, apdm
InstallManager
filtering binariesDockerizeSynchronizer
, apdm
Synchronizer
using aDockerizeInstallManager
asInstallManager
FilteringDestination
, apdm
InstallDestination
filtering binaries
This way, the dockerization is using the same installation process just tuned for docker and augmented with pdm-dockerize
specifics.
Contributing
Read the dedicated contributing guidelines.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pdm_dockerize-0.6.0.tar.gz
.
File metadata
- Download URL: pdm_dockerize-0.6.0.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.19.0 CPython/3.10.12 Linux/6.8.0-1014-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e97cd9e9684ab74702b5c24f9d17f990b8a02a6fe15075bcc0dcd47436bd8e37 |
|
MD5 | 71dcf3d88c5ee20e6d6111074a9ec0ba |
|
BLAKE2b-256 | eb907c87ab6de4974272496f1b0ea9d60647bb9bd4725f4e64df88dc820e352a |
File details
Details for the file pdm_dockerize-0.6.0-py3-none-any.whl
.
File metadata
- Download URL: pdm_dockerize-0.6.0-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.19.0 CPython/3.10.12 Linux/6.8.0-1014-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70b6a53d29eb74df2bd9bd37433727b32f954232e5bff224f7a7bfb19bebc16b |
|
MD5 | d45b1606ac0897cead180fc2fdc81dca |
|
BLAKE2b-256 | cc6e9cfd4c4250159b1b1253b23e465842cde53e975ff5761f3f737159fc1a8c |