Index
wrknv.container.runtime
¶
TODO: Add module docstring.
Classes¶
ContainerRuntime
¶
Bases: ABC
Abstract base class for container runtimes (Docker, Podman, etc.).
Functions¶
build_image
abstractmethod
¶
build_image(
dockerfile: str,
tag: str,
context: str = ".",
build_args: dict[str, str] | None = None,
**extra_options: Any
) -> CompletedProcess
Build a container image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dockerfile
|
str
|
Path to Dockerfile |
required |
tag
|
str
|
Image tag |
required |
context
|
str
|
Build context directory |
'.'
|
build_args
|
dict[str, str] | None
|
Build arguments |
None
|
**extra_options
|
Any
|
Runtime-specific options |
{}
|
Returns:
| Type | Description |
|---|---|
CompletedProcess
|
CompletedProcess |
Source code in wrknv/container/runtime/base.py
container_exists
abstractmethod
¶
container_running
abstractmethod
¶
exec_in_container
abstractmethod
¶
exec_in_container(
name: str,
command: list[str],
interactive: bool = False,
tty: bool = False,
user: str | None = None,
workdir: str | None = None,
environment: dict[str, str] | None = None,
) -> CompletedProcess
Execute command in a running container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Container name |
required |
command
|
list[str]
|
Command to execute |
required |
interactive
|
bool
|
Keep STDIN open |
False
|
tty
|
bool
|
Allocate pseudo-TTY |
False
|
user
|
str | None
|
User to run as |
None
|
workdir
|
str | None
|
Working directory |
None
|
environment
|
dict[str, str] | None
|
Environment variables |
None
|
Returns:
| Type | Description |
|---|---|
CompletedProcess
|
CompletedProcess with command output |
Source code in wrknv/container/runtime/base.py
get_container_logs
abstractmethod
¶
get_container_logs(
name: str,
follow: bool = False,
tail: int | None = None,
since: str | None = None,
) -> CompletedProcess
Get container logs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Container name |
required |
follow
|
bool
|
Follow log output |
False
|
tail
|
int | None
|
Number of lines to tail |
None
|
since
|
str | None
|
Show logs since timestamp |
None
|
Returns:
| Type | Description |
|---|---|
CompletedProcess
|
CompletedProcess with logs in stdout |
Source code in wrknv/container/runtime/base.py
inspect_container
abstractmethod
¶
is_available
abstractmethod
¶
Check if the container runtime is available.
Returns:
| Type | Description |
|---|---|
bool
|
True if runtime is available and functional |
list_containers
abstractmethod
¶
remove_container
abstractmethod
¶
Remove a container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Container name |
required |
force
|
bool
|
Force removal of running container |
False
|
Returns:
| Type | Description |
|---|---|
CompletedProcess
|
CompletedProcess |
Source code in wrknv/container/runtime/base.py
run_container
abstractmethod
¶
run_container(
image: str,
name: str,
detach: bool = True,
volumes: list[str] | None = None,
environment: dict[str, str] | None = None,
ports: list[str] | None = None,
workdir: str | None = None,
command: list[str] | None = None,
**extra_options: Any
) -> CompletedProcess
Start a new container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
str
|
Container image to run |
required |
name
|
str
|
Container name |
required |
detach
|
bool
|
Run in detached mode |
True
|
volumes
|
list[str] | None
|
Volume mappings (host:container) |
None
|
environment
|
dict[str, str] | None
|
Environment variables |
None
|
ports
|
list[str] | None
|
Port mappings (host:container) |
None
|
workdir
|
str | None
|
Working directory inside container |
None
|
command
|
list[str] | None
|
Command to run in container |
None
|
**extra_options
|
Any
|
Runtime-specific options |
{}
|
Returns:
| Type | Description |
|---|---|
CompletedProcess
|
CompletedProcess with container ID in stdout |
Source code in wrknv/container/runtime/base.py
start_container
abstractmethod
¶
Start an existing container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Container name |
required |
Returns:
| Type | Description |
|---|---|
CompletedProcess
|
CompletedProcess |
stop_container
abstractmethod
¶
Stop a running container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Container name |
required |
timeout
|
int
|
Seconds to wait before force stopping |
10
|
Returns:
| Type | Description |
|---|---|
CompletedProcess
|
CompletedProcess |
Source code in wrknv/container/runtime/base.py
DockerRuntime
¶
Bases: ContainerRuntime
Docker implementation of container runtime.
Functions¶
build_image
¶
build_image(
dockerfile: str,
tag: str,
context: str,
build_args: dict[str, str] | None,
**extra_options: Any
) -> CompletedProcess
Build a Docker image.
Source code in wrknv/container/runtime/docker.py
container_exists
¶
Check if Docker container exists.
Source code in wrknv/container/runtime/docker.py
container_running
¶
Check if Docker container is running.
Source code in wrknv/container/runtime/docker.py
exec_in_container
¶
exec_in_container(
name: str,
command: list[str],
interactive: bool,
tty: bool,
user: str | None,
workdir: str | None,
environment: dict[str, str] | None,
) -> CompletedProcess
Execute command in a running Docker container.
Source code in wrknv/container/runtime/docker.py
get_container_logs
¶
get_container_logs(
name: str,
follow: bool,
tail: int | None,
since: str | None,
) -> CompletedProcess
Get Docker container logs.
Source code in wrknv/container/runtime/docker.py
inspect_container
¶
Get detailed Docker container information.
Source code in wrknv/container/runtime/docker.py
is_available
¶
Check if Docker is available.
Uses circuit breaker to prevent repeated checks when Docker is unavailable. If circuit is open, raises RuntimeError which callers should catch.
Source code in wrknv/container/runtime/docker.py
list_containers
¶
List Docker containers.
Source code in wrknv/container/runtime/docker.py
remove_container
¶
Remove a Docker container.
Source code in wrknv/container/runtime/docker.py
run_container
¶
run_container(
image: str,
name: str,
detach: bool,
volumes: list[str] | None,
environment: dict[str, str] | None,
ports: list[str] | None,
workdir: str | None,
command: list[str] | None,
**extra_options: Any
) -> CompletedProcess
Start a new Docker container.
Source code in wrknv/container/runtime/docker.py
start_container
¶
Start an existing Docker container.
Source code in wrknv/container/runtime/docker.py
stop_container
¶
Stop a running Docker container.