diff --git a/scripts/deployservice b/scripts/deployservice index 0b038b3..2ab7280 100755 --- a/scripts/deployservice +++ b/scripts/deployservice @@ -11,7 +11,7 @@ from python_on_whales import DockerClient PROJECT_ROOT_DIRECTORY = Path(__file__).parent.parent.resolve() SERVICES_DIRECTORY = PROJECT_ROOT_DIRECTORY / "services" -AVAILIBLE_SERVICES = list( +AVAILABLE_SERVICES = list( service.name for service in SERVICES_DIRECTORY.iterdir() ) @@ -49,8 +49,14 @@ class ServicesConfig: for server in self.servers: if service_name in server.services: servers_matched.append(server) - if len(servers_matched) != 1: - raise ValueError("Two services with the same name found.") + + if not servers_matched: + raise ValueError(f"Service `{service_name}` not found.") + + if len(servers_matched) > 1: + raise ValueError( + f"Two services with the same name (`{service_name}`) found.", + ) return servers_matched.pop() @@ -79,10 +85,26 @@ def _get_service_context(service_name: str, config: ServicesConfig) -> str: return server_config.context -def deploy_service(service_name: str, config: ServicesConfig) -> str: +def deploy_service(service_name: str, config: ServicesConfig): context = _get_service_context(service_name, config) + service_dir = SERVICES_DIRECTORY / service_name + docker = DockerClient(context=context) - return str(docker.docker_cmd) + + compose_file = service_dir / "docker-compose.yml" + env_file = service_dir / ".env" + + if not compose_file.exists(): + raise ValueError( + f"Service {service_name} is missing docker-compose.yml", + ) + + print(f"INFO: deploying service {service_name}") + docker.stack.deploy( + name=service_name, + compose_files=[compose_file], + env_files=[env_file] if env_file else [], + ) def load_config(config_file: Path | str) -> ServicesConfig: @@ -93,7 +115,7 @@ def load_config(config_file: Path | str) -> ServicesConfig: def _add_args(parser: argparse.ArgumentParser): parser.add_argument("services_file") - parser.add_argument("service_name", choices=AVAILIBLE_SERVICES) + parser.add_argument("service_name", choices=AVAILABLE_SERVICES) def main() -> int: @@ -101,7 +123,7 @@ def main() -> int: _add_args(parser) parsed_args = parser.parse_args() config = load_config(parsed_args.services_file) - print(deploy_service(parsed_args.service_name, config)) + deploy_service(parsed_args.service_name, config) return 0 diff --git a/services.json b/services.json index e0e5630..4ba7b89 100644 --- a/services.json +++ b/services.json @@ -7,7 +7,7 @@ "joplin", "kanboard", "ntfy", - "uptime-kuma", + "uptime_kuma", "usememos", "authentik-ldap", "heimdall" diff --git a/services/uptime-kuma/.env.template b/services/uptime_kuma/.env.template similarity index 100% rename from services/uptime-kuma/.env.template rename to services/uptime_kuma/.env.template diff --git a/services/uptime-kuma/docker-compose.yml b/services/uptime_kuma/docker-compose.yml similarity index 100% rename from services/uptime-kuma/docker-compose.yml rename to services/uptime_kuma/docker-compose.yml