-
Notifications
You must be signed in to change notification settings - Fork 0
/
container-build.py
executable file
·45 lines (38 loc) · 1.52 KB
/
container-build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python
import os
import docker
import argparse
import re
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument("--username", type=str, required=False,
default=None, help="User credentials")
parser.add_argument("--password", type=str, required=False,
default=None, help="Access token")
parser.add_argument("--upload", action="store_true",
required=False, help="Upload to conan remote")
return parser.parse_args()
def run_build(docker_image, container_command):
current_path = os.getcwd()
client = docker.from_env()
container = client.containers.run(image=docker_image, command=container_command, remove=True,
working_dir="/app", volumes={current_path: {'bind': '/app', 'mode': 'rw'}},
detach=True)
has_error = False
for line in container.logs(stream=True):
text = str(line.strip())
print(text)
if re.search('ERROR:', text, re.IGNORECASE):
has_error = True
if has_error:
print(f'Failed to run container')
exit(1)
else:
print("SUCCESS")
if __name__ == "__main__":
args = get_args()
bash_command = "./build.sh"
if args.upload:
bash_command += f"; mumoco remotes --username {args.username} --password {args.password}; mumoco upload disroop-conan"
command = f"/bin/bash -c '{bash_command}'"
run_build("disroop/embedded-hipster:0.6.14", command)