Skip to main content

Help generating docker images from PDM projects

Project description

pdm-dockerize

CI pre-commit.ci status PyPI PyPI - License

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 install 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"]

Contributing

Read the dedicated contributing guidelines.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdm_dockerize-0.3.0.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

pdm_dockerize-0.3.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file pdm_dockerize-0.3.0.tar.gz.

File metadata

  • Download URL: pdm_dockerize-0.3.0.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.11.1 CPython/3.10.12

File hashes

Hashes for pdm_dockerize-0.3.0.tar.gz
Algorithm Hash digest
SHA256 13f5d1e7dc1bdb12ee178bd86f7f50952d9630c6d3d46c053d7c3b2a676aa0ba
MD5 ef2f4a590bbe0604184148cec36bc13f
BLAKE2b-256 0901f0a5ef8551e5cbf27673c58256f5f61b39b96886d183045de81b29020ef0

See more details on using hashes here.

Provenance

File details

Details for the file pdm_dockerize-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pdm_dockerize-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a3b719a05b3918b1c55189c50ca82f46b21f55c833c6a3a24d8dd2affa11af31
MD5 b14612190dd09529995eb1bb9b595aa7
BLAKE2b-256 b3e3cbb49a373391527ae530ac14fc0b6bdf1aa908a4ebfad96c4dd41b00a3dd

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page