feat!: Multiple services support (beta?)
This commit is contained in:
parent
ce77c0cf7d
commit
667d7f476d
2 changed files with 21 additions and 18 deletions
|
|
@ -43,16 +43,20 @@ class WoodpeckerRunner(Thread):
|
|||
|
||||
result = RunnerResult()
|
||||
try:
|
||||
service = self.get_service(self._event.files)
|
||||
if service is None:
|
||||
services = self.get_service(self._event.files)
|
||||
if len(services) == 0:
|
||||
logger.info("No service found.")
|
||||
result.success = True
|
||||
else:
|
||||
service_path = f"{self._root}/compose/{service}/docker-compose.yml"
|
||||
self._git.checkout(self._event.commit)
|
||||
paths = []
|
||||
for service in services:
|
||||
service_path = f"{self._root}/compose/{service}/docker-compose.yml"
|
||||
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
|
||||
except Exception as e:
|
||||
|
|
@ -61,20 +65,14 @@ class WoodpeckerRunner(Thread):
|
|||
asyncio.run(dispatch(result))
|
||||
|
||||
@staticmethod
|
||||
def get_service(files: list[str]) -> str | None:
|
||||
def get_service(files: list[str]) -> list[str]:
|
||||
supported_files = []
|
||||
for f in files:
|
||||
f_parts = f.split("/")
|
||||
if f_parts[0] in ["compose", "files"]:
|
||||
supported_files.append(f_parts[1])
|
||||
match len(set(supported_files)):
|
||||
case 0:
|
||||
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.")
|
||||
# TODO: check service priorities (NGINX last)
|
||||
return list(dict.fromkeys(supported_files))
|
||||
|
||||
|
||||
@injectable(singleton=True)
|
||||
|
|
|
|||
|
|
@ -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/conf.d/mqtt.conf", "files/nginx/conf.d/nextcloud.conf", "files/nginx/conf.d/zitadel.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)
|
||||
assert service == 'nginx'
|
||||
assert service == ['nginx']
|
||||
|
||||
def test_get_service_multi():
|
||||
services = woodpecker.WoodpeckerRunner.get_service(files2)
|
||||
assert services == ['nginx', 'nginx2']
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue