From d2bc3cd9f319da9904d6aa648471633e4ee09888 Mon Sep 17 00:00:00 2001 From: erik Date: Wed, 12 Jul 2023 15:50:33 +0200 Subject: [PATCH] Use execute --- .../infrastructure/infrastructure.py | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/main/python/ddadevops/infrastructure/infrastructure.py b/src/main/python/ddadevops/infrastructure/infrastructure.py index ca3cdb0..3488753 100644 --- a/src/main/python/ddadevops/infrastructure/infrastructure.py +++ b/src/main/python/ddadevops/infrastructure/infrastructure.py @@ -53,37 +53,37 @@ class ImageApi: self.execution_api = ExecutionApi() def image(self, name: str, path: Path): - self.execution_api.run_handled( + self.execution_api.execute( f"docker build -t {name} --file {path}/image/Dockerfile {path}/image" ) def drun(self, name: str): - self.execution_api.run_handled( + self.execution_api.execute( f'docker run -it --entrypoint="" {name} /bin/bash' ) def dockerhub_login(self, username: str, password: str): - self.execution_api.run_handled( + self.execution_api.execute( f"docker login --username {username} --password {password}" ) def dockerhub_publish(self, name: str, username: str, tag=None): if tag is not None: - self.execution_api.run_handled( + self.execution_api.execute( f"docker tag {name} {username}/{name}:{tag}" ) - self.execution_api.run_handled( + self.execution_api.execute( f"docker push {username}/{name}:{tag}" ) - self.execution_api.run_handled( + self.execution_api.execute( f"docker tag {name} {username}/{name}:latest" ) - self.execution_api.run_handled( + self.execution_api.execute( f"docker push {username}/{name}:latest" ) def test(self, name: str, path: Path): - self.execution_api.run_handled( + self.execution_api.execute( f"docker build -t {name} -test --file {path}/test/Dockerfile {path}/test" ) @@ -111,18 +111,6 @@ class ExecutionApi: process.stdout.close() process.wait() - def run_handled(self, command: str, shell=True, check=True): - try: - run( - command, - shell=shell, - check=check, - capture_output=True, - text=True) - except CalledProcessError as exc: - print("Command failed with code: ", exc.returncode, " and message:", exc.stderr) - raise CalledProcessError - class EnvironmentApi: def get(self, key):