-
Notifications
You must be signed in to change notification settings - Fork 6
/
docker.py
51 lines (38 loc) · 972 Bytes
/
docker.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
46
47
48
49
50
51
from subprocess import run
ACR_NAME = "faasm.azurecr.io"
def build_container(
tag_name, dockerfile, cwd, nocache=False, push=False, build_args=None
):
build_args = build_args if build_args else dict()
if nocache:
no_cache_str = "--no-cache"
else:
no_cache_str = ""
build_cmd = [
"docker build",
no_cache_str,
"-t {}".format(tag_name),
"-f {}".format(dockerfile),
]
for key, value in build_args.items():
build_cmd.append("--build-arg {}={}".format(key, value))
build_cmd.append(".")
build_cmd = " ".join(build_cmd)
print(build_cmd)
run(
build_cmd,
shell=True,
check=True,
env={"DOCKER_BUILDKIT": "1"},
cwd=cwd,
)
if push:
push_container(tag_name)
def push_container(tag_name):
cmd = "docker push {}".format(tag_name)
print(cmd)
run(
cmd,
shell=True,
check=True,
)