diff --git a/library/2.0.5/__init__.py b/library/2.0.6/__init__.py similarity index 100% rename from library/2.0.5/__init__.py rename to library/2.0.6/__init__.py diff --git a/library/2.0.5/configs.py b/library/2.0.6/configs.py similarity index 100% rename from library/2.0.5/configs.py rename to library/2.0.6/configs.py diff --git a/library/2.0.5/container.py b/library/2.0.6/container.py similarity index 100% rename from library/2.0.5/container.py rename to library/2.0.6/container.py diff --git a/library/2.0.5/depends.py b/library/2.0.6/depends.py similarity index 100% rename from library/2.0.5/depends.py rename to library/2.0.6/depends.py diff --git a/library/2.0.5/deploy.py b/library/2.0.6/deploy.py similarity index 100% rename from library/2.0.5/deploy.py rename to library/2.0.6/deploy.py diff --git a/library/2.0.5/deps.py b/library/2.0.6/deps.py similarity index 81% rename from library/2.0.5/deps.py rename to library/2.0.6/deps.py index c8207aec3d..400f71cd7b 100644 --- a/library/2.0.5/deps.py +++ b/library/2.0.6/deps.py @@ -1,5 +1,6 @@ import os import json +import urllib.parse from typing import TYPE_CHECKING, TypedDict, NotRequired if TYPE_CHECKING: @@ -261,11 +262,28 @@ def perms(self, name: str): return PermsContainer(self._render_instance, name) def postgres(self, name: str, image: str, config: PostgresConfig, perms_instance: PermsContainer): + return PostgresContainer(self._render_instance, name, image, config, perms_instance) + + def redis(self, name: str, image: str, config: RedisConfig, perms_instance: PermsContainer): + return RedisContainer(self._render_instance, name, image, config, perms_instance) + + def mariadb(self, name: str, image: str, config: MariadbConfig, perms_instance: PermsContainer): + return MariadbContainer(self._render_instance, name, image, config, perms_instance) + + +class PostgresContainer: + def __init__( + self, render_instance: "Render", name: str, image: str, config: PostgresConfig, perms_instance: PermsContainer + ): + self._render_instance = render_instance + self._name = name + self._config = config + for key in ("user", "password", "database", "volume"): if key not in config: raise RenderError(f"Expected [{key}] to be set for postgres") - port = valid_port_or_raise(config.get("port") or 5432) + port = valid_port_or_raise(self._get_port()) c = self._render_instance.add_container(name, image) c.set_user(999, 999) @@ -273,18 +291,51 @@ def postgres(self, name: str, image: str, config: PostgresConfig, perms_instance c.deploy.resources.remove_devices() c.add_storage("/var/lib/postgresql/data", config["volume"]) - perms_instance.add_or_skip_action("postgres_data", config["volume"], {"uid": 999, "gid": 999, "mode": "check"}) + perms_instance.add_or_skip_action( + f"${name}_postgres_data", config["volume"], {"uid": 999, "gid": 999, "mode": "check"} + ) c.environment.add_env("POSTGRES_USER", config["user"]) c.environment.add_env("POSTGRES_PASSWORD", config["password"]) c.environment.add_env("POSTGRES_DB", config["database"]) c.environment.add_env("POSTGRES_PORT", port) - # Return container for further configuration + # Store container for further configuration # For example: c.depends.add_dependency("other_container", "service_started") - return c + self._container = c + + @property + def container(self): + return self._container + + def _get_port(self): + return self._config.get("port") or 5432 + + def get_url(self, variant: str): + user = urllib.parse.quote_plus(self._config["user"]) + password = urllib.parse.quote_plus(self._config["password"]) + creds = f"{user}:{password}" + addr = f"{self._name}:{self._get_port()}" + db = self._config["database"] + + match variant: + case "postgres": + return f"postgres://{creds}@{addr}/{db}?sslmode=disable" + case "postgresql": + return f"postgresql://{creds}@{addr}/{db}?sslmode=disable" + case "host_port": + return addr + case _: + raise RenderError(f"Expected [variant] to be one of [postgres, postgresql], got [{variant}]") + + +class RedisContainer: + def __init__( + self, render_instance: "Render", name: str, image: str, config: RedisConfig, perms_instance: PermsContainer + ): + self._render_instance = render_instance + self._name = name - def redis(self, name: str, image: str, config: RedisConfig, perms_instance: PermsContainer): for key in ("password", "volume"): if key not in config: raise RenderError(f"Expected [{key}] to be set for redis") @@ -297,17 +348,30 @@ def redis(self, name: str, image: str, config: RedisConfig, perms_instance: Perm c.deploy.resources.remove_devices() c.add_storage("/bitnami/redis/data", config["volume"]) - perms_instance.add_or_skip_action("redis_data", config["volume"], {"uid": 1001, "gid": 0, "mode": "check"}) + perms_instance.add_or_skip_action( + f"{self._name}_redis_data", config["volume"], {"uid": 1001, "gid": 0, "mode": "check"} + ) c.environment.add_env("ALLOW_EMPTY_PASSWORD", "no") c.environment.add_env("REDIS_PASSWORD", config["password"]) c.environment.add_env("REDIS_PORT_NUMBER", port) - # Return container for further configuration + # Store container for further configuration # For example: c.depends.add_dependency("other_container", "service_started") - return c + self._container = c + + @property + def container(self): + return self._container + + +class MariadbContainer: + def __init__( + self, render_instance: "Render", name: str, image: str, config: MariadbConfig, perms_instance: PermsContainer + ): + self._render_instance = render_instance + self._name = name - def mariadb(self, name: str, image: str, config: MariadbConfig, perms_instance: PermsContainer): for key in ("user", "password", "database", "volume"): if key not in config: raise RenderError(f"Expected [{key}] to be set for mariadb") @@ -322,7 +386,9 @@ def mariadb(self, name: str, image: str, config: MariadbConfig, perms_instance: c.deploy.resources.remove_devices() c.add_storage("/var/lib/mysql", config["volume"]) - perms_instance.add_or_skip_action("mariadb_data", config["volume"], {"uid": 999, "gid": 999, "mode": "check"}) + perms_instance.add_or_skip_action( + f"{self._name}_mariadb_data", config["volume"], {"uid": 999, "gid": 999, "mode": "check"} + ) c.environment.add_env("MARIADB_USER", config["user"]) c.environment.add_env("MARIADB_PASSWORD", config["password"]) @@ -331,6 +397,10 @@ def mariadb(self, name: str, image: str, config: MariadbConfig, perms_instance: c.environment.add_env("MARIADB_AUTO_UPGRADE", str(auto_upgrade).lower()) c.set_command(["--port", str(port)]) - # Return container for further configuration + # Store container for further configuration # For example: c.depends.add_dependency("other_container", "service_started") - return c + self._container = c + + @property + def container(self): + return self._container diff --git a/library/2.0.5/device.py b/library/2.0.6/device.py similarity index 100% rename from library/2.0.5/device.py rename to library/2.0.6/device.py diff --git a/library/2.0.5/devices.py b/library/2.0.6/devices.py similarity index 100% rename from library/2.0.5/devices.py rename to library/2.0.6/devices.py diff --git a/library/2.0.5/dns.py b/library/2.0.6/dns.py similarity index 100% rename from library/2.0.5/dns.py rename to library/2.0.6/dns.py diff --git a/library/2.0.5/environment.py b/library/2.0.6/environment.py similarity index 100% rename from library/2.0.5/environment.py rename to library/2.0.6/environment.py diff --git a/library/2.0.5/error.py b/library/2.0.6/error.py similarity index 100% rename from library/2.0.5/error.py rename to library/2.0.6/error.py diff --git a/library/2.0.5/formatter.py b/library/2.0.6/formatter.py similarity index 100% rename from library/2.0.5/formatter.py rename to library/2.0.6/formatter.py diff --git a/library/2.0.5/functions.py b/library/2.0.6/functions.py similarity index 100% rename from library/2.0.5/functions.py rename to library/2.0.6/functions.py diff --git a/library/2.0.5/healthcheck.py b/library/2.0.6/healthcheck.py similarity index 100% rename from library/2.0.5/healthcheck.py rename to library/2.0.6/healthcheck.py diff --git a/library/2.0.5/labels.py b/library/2.0.6/labels.py similarity index 100% rename from library/2.0.5/labels.py rename to library/2.0.6/labels.py diff --git a/library/2.0.5/notes.py b/library/2.0.6/notes.py similarity index 100% rename from library/2.0.5/notes.py rename to library/2.0.6/notes.py diff --git a/library/2.0.5/portal.py b/library/2.0.6/portal.py similarity index 100% rename from library/2.0.5/portal.py rename to library/2.0.6/portal.py diff --git a/library/2.0.5/portals.py b/library/2.0.6/portals.py similarity index 100% rename from library/2.0.5/portals.py rename to library/2.0.6/portals.py diff --git a/library/2.0.5/ports.py b/library/2.0.6/ports.py similarity index 100% rename from library/2.0.5/ports.py rename to library/2.0.6/ports.py diff --git a/library/2.0.5/render.py b/library/2.0.6/render.py similarity index 100% rename from library/2.0.5/render.py rename to library/2.0.6/render.py diff --git a/library/2.0.5/resources.py b/library/2.0.6/resources.py similarity index 100% rename from library/2.0.5/resources.py rename to library/2.0.6/resources.py diff --git a/library/2.0.5/restart.py b/library/2.0.6/restart.py similarity index 100% rename from library/2.0.5/restart.py rename to library/2.0.6/restart.py diff --git a/library/2.0.5/storage.py b/library/2.0.6/storage.py similarity index 100% rename from library/2.0.5/storage.py rename to library/2.0.6/storage.py diff --git a/library/2.0.5/tests/__init__.py b/library/2.0.6/tests/__init__.py similarity index 100% rename from library/2.0.5/tests/__init__.py rename to library/2.0.6/tests/__init__.py diff --git a/library/2.0.5/tests/test_build_image.py b/library/2.0.6/tests/test_build_image.py similarity index 100% rename from library/2.0.5/tests/test_build_image.py rename to library/2.0.6/tests/test_build_image.py diff --git a/library/2.0.5/tests/test_configs.py b/library/2.0.6/tests/test_configs.py similarity index 100% rename from library/2.0.5/tests/test_configs.py rename to library/2.0.6/tests/test_configs.py diff --git a/library/2.0.5/tests/test_container.py b/library/2.0.6/tests/test_container.py similarity index 100% rename from library/2.0.5/tests/test_container.py rename to library/2.0.6/tests/test_container.py diff --git a/library/2.0.5/tests/test_depends.py b/library/2.0.6/tests/test_depends.py similarity index 100% rename from library/2.0.5/tests/test_depends.py rename to library/2.0.6/tests/test_depends.py diff --git a/library/2.0.5/tests/test_deps.py b/library/2.0.6/tests/test_deps.py similarity index 96% rename from library/2.0.5/tests/test_deps.py rename to library/2.0.6/tests/test_deps.py index 68eef635f8..5c0d60757d 100644 --- a/library/2.0.5/tests/test_deps.py +++ b/library/2.0.6/tests/test_deps.py @@ -39,7 +39,7 @@ def test_add_postgres(mock_values): "pg_image", { "user": "test_user", - "password": "test_password", + "password": "test_@password", "database": "test_database", "volume": {"type": "volume", "volume_config": {"volume_name": "test_volume"}, "auto_permissions": True}, }, @@ -47,8 +47,11 @@ def test_add_postgres(mock_values): ) if perms_container.has_actions(): perms_container.activate() - p.depends.add_dependency("perms_container", "service_completed_successfully") + p.container.depends.add_dependency("perms_container", "service_completed_successfully") output = render.render() + assert ( + p.get_url("postgres") == "postgres://test_user:test_%40password@pg_container:5432/test_database?sslmode=disable" + ) assert "devices" not in output["services"]["pg_container"] assert "reservations" not in output["services"]["pg_container"]["deploy"]["resources"] assert output["services"]["pg_container"]["image"] == "postgres:latest" @@ -75,7 +78,7 @@ def test_add_postgres(mock_values): "TZ": "Etc/UTC", "NVIDIA_VISIBLE_DEVICES": "void", "POSTGRES_USER": "test_user", - "POSTGRES_PASSWORD": "test_password", + "POSTGRES_PASSWORD": "test_@password", "POSTGRES_DB": "test_database", "POSTGRES_PORT": "5432", } @@ -114,7 +117,7 @@ def test_add_redis(mock_values): ) if perms_container.has_actions(): perms_container.activate() - r.depends.add_dependency("perms_container", "service_completed_successfully") + r.container.depends.add_dependency("perms_container", "service_completed_successfully") output = render.render() assert "devices" not in output["services"]["redis_container"] assert "reservations" not in output["services"]["redis_container"]["deploy"]["resources"] @@ -181,7 +184,7 @@ def test_add_mariadb(mock_values): ) if perms_container.has_actions(): perms_container.activate() - m.depends.add_dependency("perms_container", "service_completed_successfully") + m.container.depends.add_dependency("perms_container", "service_completed_successfully") output = render.render() assert "devices" not in output["services"]["mariadb_container"] assert "reservations" not in output["services"]["mariadb_container"]["deploy"]["resources"] diff --git a/library/2.0.5/tests/test_device.py b/library/2.0.6/tests/test_device.py similarity index 100% rename from library/2.0.5/tests/test_device.py rename to library/2.0.6/tests/test_device.py diff --git a/library/2.0.5/tests/test_dns.py b/library/2.0.6/tests/test_dns.py similarity index 100% rename from library/2.0.5/tests/test_dns.py rename to library/2.0.6/tests/test_dns.py diff --git a/library/2.0.5/tests/test_environment.py b/library/2.0.6/tests/test_environment.py similarity index 100% rename from library/2.0.5/tests/test_environment.py rename to library/2.0.6/tests/test_environment.py diff --git a/library/2.0.5/tests/test_formatter.py b/library/2.0.6/tests/test_formatter.py similarity index 100% rename from library/2.0.5/tests/test_formatter.py rename to library/2.0.6/tests/test_formatter.py diff --git a/library/2.0.5/tests/test_functions.py b/library/2.0.6/tests/test_functions.py similarity index 100% rename from library/2.0.5/tests/test_functions.py rename to library/2.0.6/tests/test_functions.py diff --git a/library/2.0.5/tests/test_healthcheck.py b/library/2.0.6/tests/test_healthcheck.py similarity index 100% rename from library/2.0.5/tests/test_healthcheck.py rename to library/2.0.6/tests/test_healthcheck.py diff --git a/library/2.0.5/tests/test_labels.py b/library/2.0.6/tests/test_labels.py similarity index 100% rename from library/2.0.5/tests/test_labels.py rename to library/2.0.6/tests/test_labels.py diff --git a/library/2.0.5/tests/test_notes.py b/library/2.0.6/tests/test_notes.py similarity index 100% rename from library/2.0.5/tests/test_notes.py rename to library/2.0.6/tests/test_notes.py diff --git a/library/2.0.5/tests/test_portal.py b/library/2.0.6/tests/test_portal.py similarity index 100% rename from library/2.0.5/tests/test_portal.py rename to library/2.0.6/tests/test_portal.py diff --git a/library/2.0.5/tests/test_ports.py b/library/2.0.6/tests/test_ports.py similarity index 100% rename from library/2.0.5/tests/test_ports.py rename to library/2.0.6/tests/test_ports.py diff --git a/library/2.0.5/tests/test_render.py b/library/2.0.6/tests/test_render.py similarity index 100% rename from library/2.0.5/tests/test_render.py rename to library/2.0.6/tests/test_render.py diff --git a/library/2.0.5/tests/test_resources.py b/library/2.0.6/tests/test_resources.py similarity index 100% rename from library/2.0.5/tests/test_resources.py rename to library/2.0.6/tests/test_resources.py diff --git a/library/2.0.5/tests/test_restart.py b/library/2.0.6/tests/test_restart.py similarity index 100% rename from library/2.0.5/tests/test_restart.py rename to library/2.0.6/tests/test_restart.py diff --git a/library/2.0.5/tests/test_volumes.py b/library/2.0.6/tests/test_volumes.py similarity index 100% rename from library/2.0.5/tests/test_volumes.py rename to library/2.0.6/tests/test_volumes.py diff --git a/library/2.0.5/validations.py b/library/2.0.6/validations.py similarity index 100% rename from library/2.0.5/validations.py rename to library/2.0.6/validations.py diff --git a/library/2.0.5/volume_mount.py b/library/2.0.6/volume_mount.py similarity index 100% rename from library/2.0.5/volume_mount.py rename to library/2.0.6/volume_mount.py diff --git a/library/2.0.5/volume_mount_types.py b/library/2.0.6/volume_mount_types.py similarity index 100% rename from library/2.0.5/volume_mount_types.py rename to library/2.0.6/volume_mount_types.py diff --git a/library/2.0.5/volume_sources.py b/library/2.0.6/volume_sources.py similarity index 100% rename from library/2.0.5/volume_sources.py rename to library/2.0.6/volume_sources.py diff --git a/library/2.0.5/volume_types.py b/library/2.0.6/volume_types.py similarity index 100% rename from library/2.0.5/volume_types.py rename to library/2.0.6/volume_types.py diff --git a/library/2.0.5/volumes.py b/library/2.0.6/volumes.py similarity index 100% rename from library/2.0.5/volumes.py rename to library/2.0.6/volumes.py diff --git a/library/hashes.yaml b/library/hashes.yaml index 1ea6b75bb8..0157ee74df 100644 --- a/library/hashes.yaml +++ b/library/hashes.yaml @@ -1,3 +1,3 @@ 0.0.1: f074617a82a86d2a6cc78a4c8a4296fc9d168e456f12713e50c696557b302133 1.1.5: 51332f2b032a0c473693458cd93daa96d56604241878e538c07cb85b8be66727 -2.0.5: 0a65beb80aa50e867204d9c6720f8c841047d9e2a0e03d2c949534688c2832e1 +2.0.6: 39d6ab5b62befe6d2e1d80fe590291662ccd2b678f162ea13d305008fb695b66