Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for privileged runs #131

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ The ``[docker:container-name]`` section may contain the following directives:
test run until the container reports healthy, and will fail the test
run if it never does so (within the parameters specified).

```privileged```
A boolean string that defaults to False. By default containers are unprivileged and does
not have access to devices. When true, this corresponds to
`docker run --privileged
<https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities>`__.

Command-Line Arguments
----------------------

Expand Down Expand Up @@ -176,6 +182,7 @@ Example
healthcheck_retries = 30
healthcheck_interval = 1
healthcheck_start_period = 1
privileged = true
# Configure a bind-mounted volume on the host to store Postgres' data
# NOTE: this is included for demonstration purposes of tox-docker's
# volume capability; you probably _don't_ want to do this for real
Expand Down
2 changes: 2 additions & 0 deletions tox_docker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def __init__(
ports: Optional[Collection[Port]] = None,
links: Optional[Collection[Link]] = None,
volumes: Optional[Collection[Volume]] = None,
privileged: Optional[bool] = False,
) -> None:
self.name = name
self.runas_name = runas_name(name)
Expand All @@ -127,6 +128,7 @@ def __init__(
self.ports: Collection[Port] = ports or {}
self.links: Collection[Link] = links or {}
self.mounts: Collection[Mount] = [v.docker_mount for v in volumes or ()]
self.privileged = privileged

self.healthcheck_cmd = healthcheck_cmd
self.healthcheck_interval = (
Expand Down
1 change: 1 addition & 0 deletions tox_docker/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def docker_run(
ports=ports,
publish_all_ports=len(ports) == 0,
mounts=container_config.mounts,
privileged=container_config.privileged,
)
container.reload() # TODO: why do we need this?
return container
Expand Down
5 changes: 5 additions & 0 deletions tox_docker/tox3/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ def parse_container_config(
if reader.getstring("volumes"):
volumes = [Volume(line) for line in reader.getlist("volumes")]

privileged = False
if reader.getstring("privileged"):
privileged = bool(reader.getstring("privileged"))

return ContainerConfig(
name=container_name,
image=Image(reader.getstring("image")),
Expand All @@ -146,4 +150,5 @@ def parse_container_config(
ports=ports,
links=links,
volumes=volumes,
privileged=privileged,
)
7 changes: 7 additions & 0 deletions tox_docker/tox4/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def register_config(self) -> None:
default=[],
desc="volumes to attach",
)
self.add_config(
keys=["privileged"],
of_type=bool,
default=False,
desc="run in privileged mode",
)

self.add_config(
keys=["healthcheck_cmd"],
Expand Down Expand Up @@ -102,4 +108,5 @@ def parse_container_config(docker_config: DockerConfigSet) -> ContainerConfig:
ports=docker_config["ports"],
links=docker_config["links"],
volumes=docker_config["volumes"],
privileged=docker_config["privileged"],
)