forked from precice/systemtests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker.py
More file actions
31 lines (25 loc) · 1.38 KB
/
docker.py
File metadata and controls
31 lines (25 loc) · 1.38 KB
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
import datetime, subprocess
def get_namespace():
return "st_"
def get_dockername():
""" Returns the docker namespace resp. username. """
return "precice"
def get_images():
cmd = r'docker image list --filter=reference="%s*" --format="{{.Repository}}"' % get_namespace()
print("EXECUTING:", cmd)
cp = subprocess.run(cmd, stdout = subprocess.PIPE, shell = True, check = True)
images = cp.stdout.decode().split("\n")
return [i for i in images if len(i) > 0] # Remove empty lines
def get_containers():
cmd = r'docker ps -a --filter=name="%s*" --format="{{.Names}}"' % get_namespace()
print("EXECUTING:", cmd)
cp = subprocess.run(cmd, stdout = subprocess.PIPE, shell = True, check = True)
images = cp.stdout.decode().split("\n")
return [i for i in images if len(i) > 0] # Remove empty lines
def build_image(tag, dockerfile = "Dockerfile", build_args = {}, force_rebuild = False):
if force_rebuild:
build_args["CACHEBUST"] = datetime.datetime.now().isoformat() # A unique string for every invocation
args = " ".join(["--build-arg " + a + "=" + b for a, b in build_args.items()])
cmd = "docker build --network=host --file {dockerfile} --tag {namespace}{tag} {build_args} .".format(dockerfile=dockerfile, namespace=get_namespace(), tag=tag.lower(), build_args=args)
print("EXECUTING:", cmd)
subprocess.run(cmd, shell = True, check = True)