Use more verbose error output
This commit is contained in:
parent
2cb7792258
commit
186f057b2b
1 changed files with 32 additions and 33 deletions
|
@ -1,4 +1,4 @@
|
|||
from subprocess import Popen, PIPE, run
|
||||
from subprocess import Popen, PIPE, run, CalledProcessError
|
||||
from pathlib import Path
|
||||
from sys import stdout
|
||||
from os import chmod, environ
|
||||
|
@ -49,55 +49,42 @@ class FileApi:
|
|||
|
||||
|
||||
class ImageApi:
|
||||
def __init__(self):
|
||||
self.execution_api = ExecutionApi()
|
||||
|
||||
def image(self, name: str, path: Path):
|
||||
run(
|
||||
f"docker build -t {name} --file {path}/image/Dockerfile {path}/image",
|
||||
shell=True,
|
||||
check=True,
|
||||
self.execution_api.run_handled(
|
||||
f"docker build -t {name} --file {path}/image/Dockerfile {path}/image"
|
||||
)
|
||||
|
||||
def drun(self, name: str):
|
||||
run(
|
||||
f'docker run -it --entrypoint="" {name} /bin/bash',
|
||||
shell=True,
|
||||
check=True,
|
||||
self.execution_api.run_handled(
|
||||
f'docker run -it --entrypoint="" {name} /bin/bash'
|
||||
)
|
||||
|
||||
def dockerhub_login(self, username: str, password: str):
|
||||
run(
|
||||
f"docker login --username {username} --password {password}",
|
||||
shell=True,
|
||||
check=True,
|
||||
self.execution_api.run_handled(
|
||||
f"docker login --username {username} --password {password}"
|
||||
)
|
||||
|
||||
def dockerhub_publish(self, name: str, username: str, tag=None):
|
||||
if tag is not None:
|
||||
run(
|
||||
f"docker tag {name} {username}/{name}:{tag}",
|
||||
shell=True,
|
||||
check=True,
|
||||
self.execution_api.run_handled(
|
||||
f"docker tag {name} {username}/{name}:{tag}"
|
||||
)
|
||||
run(
|
||||
f"docker push {username}/{name}:{tag}",
|
||||
shell=True,
|
||||
check=True,
|
||||
self.execution_api.run_handled(
|
||||
f"docker push {username}/{name}:{tag}"
|
||||
)
|
||||
run(
|
||||
f"docker tag {name} {username}/{name}:latest",
|
||||
shell=True,
|
||||
check=True,
|
||||
self.execution_api.run_handled(
|
||||
f"docker tag {name} {username}/{name}:latest"
|
||||
)
|
||||
run(
|
||||
f"docker push {username}/{name}:latest",
|
||||
shell=True,
|
||||
check=True,
|
||||
self.execution_api.run_handled(
|
||||
f"docker push {username}/{name}:latest"
|
||||
)
|
||||
|
||||
def test(self, name: str, path: Path):
|
||||
run(
|
||||
f"docker build -t {name} -test --file {path}/test/Dockerfile {path}/test",
|
||||
shell=True,
|
||||
check=True,
|
||||
self.execution_api.run_handled(
|
||||
f"docker build -t {name} -test --file {path}/test/Dockerfile {path}/test"
|
||||
)
|
||||
|
||||
|
||||
|
@ -124,6 +111,18 @@ 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)
|
||||
|
||||
|
||||
|
||||
class EnvironmentApi:
|
||||
def get(self, key):
|
||||
|
|
Loading…
Reference in a new issue