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

apps: use the new docker_socket func that handles group adding as well #1037

Merged
merged 1 commit into from
Nov 27, 2024
Merged
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
6 changes: 3 additions & 3 deletions ix-dev/community/dockge/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ icon: https://media.sys.truenas.net/apps/dockge/icons/icon.svg
keywords:
- docker
- compose
lib_version: 2.0.22
lib_version_hash: a5314152df87f4b7a76f4fa3a2923e4508d82b530ac48f033466114befe2db3b
lib_version: 2.0.23
lib_version_hash: 8909de0f230ddb07f219f65eb8e67f9b8a112e9c310bee801834248854aa91af
maintainers:
- email: [email protected]
name: truenas
Expand All @@ -48,4 +48,4 @@ sources:
- https://github.com/louislam/dockge
title: Dockge
train: community
version: 1.1.0
version: 1.1.1
2 changes: 1 addition & 1 deletion ix-dev/community/dockge/templates/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{% do c1.environment.add_user_envs(values.dockge.additional_env) %}
{% do c1.ports.add_port(values.network.web_port, values.network.web_port) %}

{% do c1.storage.add_docker_socket(read_only=False) %}
{% do c1.add_docker_socket(read_only=False) %}
{% do c1.add_storage(values.consts.data_path, values.storage.data) %}

{# Note that the DOCKGE_STACKS_DIR (container path) must be the SAME path as the host path #}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ def set_command(self, command: list[str]):
def add_storage(self, mount_path: str, config: "IxStorage"):
self._storage.add(mount_path, config)

def add_docker_socket(self, read_only: bool = True, mount_path: str = "/var/run/docker.sock"):
self.add_group(999)
self._storage._add_docker_socket(read_only, mount_path)

def set_shm_size_mb(self, size: int):
self._shm_size = size

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def add(self, mount_path: str, config: "IxStorage"):
volume_mount = VolumeMount(self._render_instance, mount_path, config)
self._volume_mounts.add(volume_mount)

def add_docker_socket(self, read_only: bool = True, mount_path: str = "/var/run/docker.sock"):
def _add_docker_socket(self, read_only: bool = True, mount_path: str = "/var/run/docker.sock"):
cfg: "IxStorage" = {
"type": "host_path",
"read_only": read_only,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,27 @@ def test_add_group_as_string(mock_values):
c1.add_group("1000")


def test_add_docker_socket(mock_values):
render = Render(mock_values)
c1 = render.add_container("test_container", "test_image")
c1.healthcheck.disable()
c1.add_docker_socket()
output = render.render()
assert output["services"]["test_container"]["group_add"] == [568, 999]
assert output["services"]["test_container"]["volumes"] == [
{
"type": "bind",
"source": "/var/run/docker.sock",
"target": "/var/run/docker.sock",
"read_only": True,
"bind": {
"propagation": "rprivate",
"create_host_path": False,
},
}
]


def test_shm_size(mock_values):
render = Render(mock_values)
c1 = render.add_container("test_container", "test_image")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ def test_add_docker_socket(mock_values):
render = Render(mock_values)
c1 = render.add_container("test_container", "test_image")
c1.healthcheck.disable()
c1.storage.add_docker_socket()
c1.storage._add_docker_socket()
output = render.render()
assert output["services"]["test_container"]["volumes"] == [
{
Expand All @@ -636,7 +636,7 @@ def test_add_docker_socket_not_read_only(mock_values):
render = Render(mock_values)
c1 = render.add_container("test_container", "test_image")
c1.healthcheck.disable()
c1.storage.add_docker_socket(read_only=False)
c1.storage._add_docker_socket(read_only=False)
output = render.render()
assert output["services"]["test_container"]["volumes"] == [
{
Expand All @@ -653,7 +653,7 @@ def test_add_docker_socket_mount_path(mock_values):
render = Render(mock_values)
c1 = render.add_container("test_container", "test_image")
c1.healthcheck.disable()
c1.storage.add_docker_socket(mount_path="/some/path")
c1.storage._add_docker_socket(mount_path="/some/path")
output = render.render()
assert output["services"]["test_container"]["volumes"] == [
{
Expand Down
6 changes: 3 additions & 3 deletions ix-dev/community/uptime-kuma/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ icon: https://media.sys.truenas.net/apps/uptime-kuma/icons/icon.svg
keywords:
- uptime
- monitor
lib_version: 2.0.21
lib_version_hash: e2faccd282b768e411919a7386a03e8491d1a7fda2da586dcf9af0d412733b8a
lib_version: 2.0.23
lib_version_hash: 8909de0f230ddb07f219f65eb8e67f9b8a112e9c310bee801834248854aa91af
maintainers:
- email: [email protected]
name: truenas
Expand All @@ -31,4 +31,4 @@ sources:
- https://github.com/louislam/uptime-kuma
title: Uptime Kuma
train: community
version: 1.0.6
version: 1.0.7
2 changes: 1 addition & 1 deletion ix-dev/community/uptime-kuma/templates/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

{% do c1.add_storage("/app/data", values.storage.data) %}
{% if values.uptime_kuma.mount_docker_socket %}
{% do c1.storage.add_docker_socket() %}
{% do c1.add_docker_socket() %}
{% endif %}

{% for store in values.storage.additional_storage %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ def set_command(self, command: list[str]):
def add_storage(self, mount_path: str, config: "IxStorage"):
self._storage.add(mount_path, config)

def add_docker_socket(self, read_only: bool = True, mount_path: str = "/var/run/docker.sock"):
self.add_group(999)
self._storage._add_docker_socket(read_only, mount_path)

def set_shm_size_mb(self, size: int):
self._shm_size = size

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

try:
from .error import RenderError
from .volume_sources import HostPathSource, IxVolumeSource
except ImportError:
from error import RenderError
from volume_sources import HostPathSource, IxVolumeSource


class Functions:
Expand Down Expand Up @@ -85,10 +87,32 @@ def _merge_dicts(self, *dicts):
merged_dict.update(dictionary)
return merged_dict

def _disallow_chars(self, string, chars, key):
def _disallow_chars(self, string: str, chars: list[str], key: str):
for char in chars:
if char in string:
raise RenderError(f"Disallowed character [{char}] in [{key}]")
return string

def _get_host_path(self, storage):
source_type = storage.get("type", "")
if not source_type:
raise RenderError("Expected [type] to be set for volume mounts.")

match source_type:
case "host_path":
mount_config = storage.get("host_path_config")
if mount_config is None:
raise RenderError("Expected [host_path_config] to be set for [host_path] type.")
host_source = HostPathSource(self._render_instance, mount_config).get()
return host_source
case "ix_volume":
mount_config = storage.get("ix_volume_config")
if mount_config is None:
raise RenderError("Expected [ix_volume_config] to be set for [ix_volume] type.")
ix_source = IxVolumeSource(self._render_instance, mount_config).get()
return ix_source
case _:
raise RenderError(f"Storage type [{source_type}] does not support host path.")

def func_map(self):
# TODO: Check what is no longer used and remove
Expand All @@ -108,4 +132,5 @@ def func_map(self):
"must_match_regex": self._must_match_regex,
"secure_string": self._secure_string,
"disallow_chars": self._disallow_chars,
"get_host_path": self._get_host_path,
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def add(self, mount_path: str, config: "IxStorage"):
volume_mount = VolumeMount(self._render_instance, mount_path, config)
self._volume_mounts.add(volume_mount)

def add_docker_socket(self, read_only: bool = True, mount_path: str = "/var/run/docker.sock"):
def _add_docker_socket(self, read_only: bool = True, mount_path: str = "/var/run/docker.sock"):
cfg: "IxStorage" = {
"type": "host_path",
"read_only": read_only,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,27 @@ def test_add_group_as_string(mock_values):
c1.add_group("1000")


def test_add_docker_socket(mock_values):
render = Render(mock_values)
c1 = render.add_container("test_container", "test_image")
c1.healthcheck.disable()
c1.add_docker_socket()
output = render.render()
assert output["services"]["test_container"]["group_add"] == [568, 999]
assert output["services"]["test_container"]["volumes"] == [
{
"type": "bind",
"source": "/var/run/docker.sock",
"target": "/var/run/docker.sock",
"read_only": True,
"bind": {
"propagation": "rprivate",
"create_host_path": False,
},
}
]


def test_shm_size(mock_values):
render = Render(mock_values)
c1 = render.add_container("test_container", "test_image")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def mock_values():


def test_funcs(mock_values):
mock_values["ix_volumes"] = {"test": "/mnt/test123"}
render = Render(mock_values)
c1 = render.add_container("test_container", "test_image")
c1.healthcheck.disable()
Expand Down Expand Up @@ -49,6 +50,18 @@ def test_funcs(mock_values):
{"func": "must_match_regex", "values": ["my_user", "^[0-9]$"], "expect_raise": True},
{"func": "must_match_regex", "values": ["1", "^[0-9]$"], "expected": "1"},
{"func": "secure_string", "values": [10], "expect_regex": r"^[a-zA-Z0-9-_]+$"},
{"func": "disallow_chars", "values": ["my_user", ["$", "@"], "my_key"], "expected": "my_user"},
{"func": "disallow_chars", "values": ["my_user$", ["$", "@"], "my_key"], "expect_raise": True},
{
"func": "get_host_path",
"values": [{"type": "host_path", "host_path_config": {"path": "/mnt/test"}}],
"expected": "/mnt/test",
},
{
"func": "get_host_path",
"values": [{"type": "ix_volume", "ix_volume_config": {"dataset_name": "test"}}],
"expected": "/mnt/test123",
},
]

for test in tests:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ def test_add_docker_socket(mock_values):
render = Render(mock_values)
c1 = render.add_container("test_container", "test_image")
c1.healthcheck.disable()
c1.storage.add_docker_socket()
c1.storage._add_docker_socket()
output = render.render()
assert output["services"]["test_container"]["volumes"] == [
{
Expand All @@ -636,7 +636,7 @@ def test_add_docker_socket_not_read_only(mock_values):
render = Render(mock_values)
c1 = render.add_container("test_container", "test_image")
c1.healthcheck.disable()
c1.storage.add_docker_socket(read_only=False)
c1.storage._add_docker_socket(read_only=False)
output = render.render()
assert output["services"]["test_container"]["volumes"] == [
{
Expand All @@ -653,7 +653,7 @@ def test_add_docker_socket_mount_path(mock_values):
render = Render(mock_values)
c1 = render.add_container("test_container", "test_image")
c1.healthcheck.disable()
c1.storage.add_docker_socket(mount_path="/some/path")
c1.storage._add_docker_socket(mount_path="/some/path")
output = render.render()
assert output["services"]["test_container"]["volumes"] == [
{
Expand Down