Skip to main content

Overview

The PackageOptions class defines configuration for how your application is built and packaged into a container image.

Constructor

PackageOptions(
    repository,
    name=None,
    builder='docker',
    publish=False,
    verbose=True,
    quiet=False,
    py_version=3
)

Parameters

repository
str
required
The container registry repository where the image will be stored.Example: 'myusername', 'gcr.io/myproject'
name
str
default:"current directory name"
The name of the container image. If not provided, defaults to the basename of the current working directory.Example: 'myapp', 'web-service'
builder
str
default:"'docker'"
The builder to use for creating the container image.Options: 'docker'
publish
bool
default:"False"
Whether to push the built image to the container registry.Set to True to automatically publish after building.
verbose
bool
default:"True"
Enable verbose output during the build process.Set to False to reduce output verbosity.
quiet
bool
default:"False"
Suppress output during the build process.Set to True for minimal output.
py_version
int
default:"3"
The Python version to use in the generated Dockerfile.Example: 3 (for Python 3.x Alpine base image)
Note on custom Dockerfiles: The PackageOptions namedtuple does not include a dockerfile field. The auto-generated Dockerfile cannot currently be overridden via this parameter. Buildr will always generate a default Dockerfile. See the Custom Dockerfiles guide for workarounds.

Usage

Basic Configuration

from metaparticle_pkg.containerize import Containerize

@Containerize(
    package={
        'repository': 'myrepo'
    }
)
def main():
    pass

Full Configuration

@Containerize(
    package={
        'repository': 'myrepo',
        'name': 'myapp',
        'builder': 'docker',
        'publish': True,
        'verbose': True,
        'quiet': False,
        'py_version': 3
    }
)
def main():
    pass

With Custom Dockerfile

@Containerize(
    package={
        'repository': 'gcr.io/myproject',
        'name': 'production-app',
        'dockerfile': './Dockerfile.prod',
        'publish': True
    }
)
def main():
    pass

Default Dockerfile

When no custom Dockerfile is provided, Buildr generates a default Dockerfile:
FROM python:{py_version}-alpine

COPY ./ /app/
RUN pip install --no-cache -r /app/requirements.txt

CMD python /app/{exec_file}

Required vs Optional

Required Parameters:
  • repository - Must be provided
Optional Parameters:
  • All other parameters have sensible defaults

Image Naming

The final image name is constructed as:
{repository}/{name}:latest
Examples:
  • repository='myrepo', name='myapp'myrepo/myapp:latest
  • repository='gcr.io/project', name='service'gcr.io/project/service:latest

Build docs developers (and LLMs) love