Compare commits
No commits in common. "667d7f476df75f1f8bbfcf952fedf856e85c8a32" and "976d739b1849bbbd234dc68728566f4574d1f054" have entirely different histories.
667d7f476d
...
976d739b18
4 changed files with 24 additions and 33 deletions
|
|
@ -43,21 +43,17 @@ class WoodpeckerRunner(Thread):
|
|||
|
||||
result = RunnerResult()
|
||||
try:
|
||||
services = self.get_service(self._event.files)
|
||||
if len(services) == 0:
|
||||
service = self.get_service(self._event.files)
|
||||
if service is None:
|
||||
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())
|
||||
for file in self._event.files:
|
||||
if file.__contains__('.mo.'):
|
||||
self._mo.process(Path(f"{self._root}{file}").absolute())
|
||||
self._docker.reload(Path(service_path).absolute())
|
||||
result.success = True
|
||||
except Exception as e:
|
||||
result.throwable = e
|
||||
|
|
@ -65,14 +61,20 @@ class WoodpeckerRunner(Thread):
|
|||
asyncio.run(dispatch(result))
|
||||
|
||||
@staticmethod
|
||||
def get_service(files: list[str]) -> list[str]:
|
||||
def get_service(files: list[str]) -> str | None:
|
||||
supported_files = []
|
||||
for f in files:
|
||||
f_parts = f.split("/")
|
||||
if f_parts[0] in ["compose", "files"]:
|
||||
supported_files.append(f_parts[1])
|
||||
# TODO: check service priorities (NGINX last)
|
||||
return list(dict.fromkeys(supported_files))
|
||||
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.")
|
||||
|
||||
|
||||
@injectable(singleton=True)
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@ class DockerService:
|
|||
|
||||
def reload(self, compose_path: Path):
|
||||
os.chdir(compose_path.parent)
|
||||
# TODO: Check if container needs to be reloaded from scratch
|
||||
# if len(self._client.compose.ps()) > 0:
|
||||
# self._client.compose.restart()
|
||||
# return
|
||||
self._client.compose.ps()
|
||||
self._client.compose.down(remove_orphans=True)
|
||||
self._client.compose.up(detach=True)
|
||||
|
|
|
|||
|
|
@ -32,23 +32,19 @@ class NamingCache:
|
|||
|
||||
|
||||
class ApplicationFormatter(Formatter):
|
||||
def __init__(self, handler_prefix: str = '', include_timestamp: bool = True):
|
||||
def __init__(self, handler_prefix: str = ''):
|
||||
super().__init__()
|
||||
self._logger_names = NamingCache()
|
||||
self._handler_prefix = handler_prefix
|
||||
self._include_timestamp = include_timestamp
|
||||
|
||||
def format(self, record):
|
||||
from datetime import datetime
|
||||
if self._include_timestamp:
|
||||
timestamp = datetime.fromtimestamp(record.created).isoformat(sep=' ', timespec='milliseconds') + ' '
|
||||
else:
|
||||
timestamp = ''
|
||||
timestamp = datetime.fromtimestamp(record.created).isoformat(sep=' ', timespec='milliseconds')
|
||||
level = record.levelname.replace('WARNING', 'WARN').rjust(5)
|
||||
thread_name = record.threadName.replace(' (', '#').replace(')', '').rjust(16)[-16:] # TODO: NamingCache?
|
||||
logger_name = self._logger_names[f"{self._handler_prefix}{record.name}"]
|
||||
message = record.getMessage()
|
||||
formatted = f"{timestamp}{level} [{thread_name}] {logger_name} : {message}"
|
||||
formatted = f"{timestamp} {level} [{thread_name}] {logger_name} : {message}"
|
||||
|
||||
if record.exc_info:
|
||||
formatted += "\n" + self.formatException(record.exc_info)
|
||||
|
|
@ -66,7 +62,7 @@ class HandlerFactory:
|
|||
def create(target: Target, handler_prefix: str = '', file_path: Path = None) -> List[Handler]:
|
||||
def console_handler(prefix: str = ''):
|
||||
handler = StreamHandler()
|
||||
handler.setFormatter(ApplicationFormatter(prefix, include_timestamp=False))
|
||||
handler.setFormatter(ApplicationFormatter(prefix))
|
||||
handler.setLevel('INFO')
|
||||
return handler
|
||||
|
||||
|
|
|
|||
|
|
@ -4,13 +4,8 @@ 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_single():
|
||||
def test_get_service():
|
||||
service = woodpecker.WoodpeckerRunner.get_service(files)
|
||||
assert service == ['nginx']
|
||||
|
||||
def test_get_service_multi():
|
||||
services = woodpecker.WoodpeckerRunner.get_service(files2)
|
||||
assert services == ['nginx', 'nginx2']
|
||||
assert service == 'nginx'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue