feat!: Multiple services support (beta?)

This commit is contained in:
Piotr Dec 2026-05-08 04:10:31 +02:00
parent ce77c0cf7d
commit 667d7f476d
Signed by: stawros
GPG key ID: 74B18A3F0F1E99C0
2 changed files with 21 additions and 18 deletions

View file

@ -43,17 +43,21 @@ class WoodpeckerRunner(Thread):
result = RunnerResult() result = RunnerResult()
try: try:
service = self.get_service(self._event.files) services = self.get_service(self._event.files)
if service is None: if len(services) == 0:
logger.info("No service found.") logger.info("No service found.")
result.success = True result.success = True
else: else:
service_path = f"{self._root}/compose/{service}/docker-compose.yml"
self._git.checkout(self._event.commit) self._git.checkout(self._event.commit)
for file in self._event.files: paths = []
if file.__contains__('.mo.'): for service in services:
self._mo.process(Path(f"{self._root}{file}").absolute()) service_path = f"{self._root}/compose/{service}/docker-compose.yml"
self._docker.reload(Path(service_path).absolute()) for file in self._event.files:
if file.__contains__('.mo.'):
self._mo.process(Path(f"{self._root}{file}").absolute())
paths.append(service_path)
for service_path in paths:
self._docker.reload(Path(service_path).absolute())
result.success = True result.success = True
except Exception as e: except Exception as e:
result.throwable = e result.throwable = e
@ -61,20 +65,14 @@ class WoodpeckerRunner(Thread):
asyncio.run(dispatch(result)) asyncio.run(dispatch(result))
@staticmethod @staticmethod
def get_service(files: list[str]) -> str | None: def get_service(files: list[str]) -> list[str]:
supported_files = [] supported_files = []
for f in files: for f in files:
f_parts = f.split("/") f_parts = f.split("/")
if f_parts[0] in ["compose", "files"]: if f_parts[0] in ["compose", "files"]:
supported_files.append(f_parts[1]) supported_files.append(f_parts[1])
match len(set(supported_files)): # TODO: check service priorities (NGINX last)
case 0: return list(dict.fromkeys(supported_files))
return None
case 1:
return supported_files[0]
case _:
logger.error(f"Multiple services were provided: {', '.join(supported_files)}")
raise Exception("Multiple services are not supported.")
@injectable(singleton=True) @injectable(singleton=True)

View file

@ -4,8 +4,13 @@ files = [".gitignore", "compose/nginx/docker-compose.yaml", "config/heimdall.kdb
"files/nginx/cert/key.mo.pem", "files/nginx/conf.d/default.conf", "files/nginx/conf.d/forge.conf", "files/nginx/cert/key.mo.pem", "files/nginx/conf.d/default.conf", "files/nginx/conf.d/forge.conf",
"files/nginx/conf.d/mqtt.conf", "files/nginx/conf.d/nextcloud.conf", "files/nginx/conf.d/zitadel.conf", "files/nginx/conf.d/mqtt.conf", "files/nginx/conf.d/nextcloud.conf", "files/nginx/conf.d/zitadel.conf",
"files/nginx/nginx.conf"] "files/nginx/nginx.conf"]
files2 = [".gitignore", "compose/nginx/docker-compose.yaml", "compose/nginx2/docker-compose.yaml"]
def test_get_service(): def test_get_service_single():
service = woodpecker.WoodpeckerRunner.get_service(files) service = woodpecker.WoodpeckerRunner.get_service(files)
assert service == 'nginx' assert service == ['nginx']
def test_get_service_multi():
services = woodpecker.WoodpeckerRunner.get_service(files2)
assert services == ['nginx', 'nginx2']