-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_image.py
executable file
·55 lines (47 loc) · 2.14 KB
/
build_image.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
52
53
54
55
#!python
# pylint: disable=missing-docstring,line-too-long
import argparse
import subprocess
BUILD_COMMAND_TMPL = "docker build --network=host -t {REGION}-docker.pkg.dev/{PROJECT}/{REPO}/zetta_utils:{TAG} -f docker/Dockerfile.{MODE}.{PYTHON_VERSION} ."
PUSH_COMMAND_TMPL = "docker push {REGION}-docker.pkg.dev/{PROJECT}/{REPO}/zetta_utils:{TAG}"
def main():
parser = argparse.ArgumentParser(description="Build and push docker image.")
parser.add_argument("--project", type=str, required=True, help="GCR project.")
parser.add_argument("--tag", "-t", type=str, required=True, help="Image tag name/version.")
parser.add_argument(
"--mode",
"-m",
type=str,
default="all",
choices=["all"],
help="Which dependencies to install.",
)
parser.add_argument(
"--python",
"-p",
type=str,
default="3.10",
choices=["3.11", "3.10"],
help="Which python version to use for the image.",
)
parser.add_argument("--region", type=str, default="us-east1", help="Artifact Registry region.")
parser.add_argument("--repo", type=str, default="zutils", help="Artifact Registry repo name.")
args = parser.parse_args()
build_command = BUILD_COMMAND_TMPL
build_command = build_command.replace("{TAG}", args.tag)
build_command = build_command.replace("{MODE}", args.mode)
build_command = build_command.replace("{PYTHON_VERSION}", f"p{args.python.replace('.', '')}")
build_command = build_command.replace("{PROJECT}", args.project)
build_command = build_command.replace("{REGION}", args.region)
build_command = build_command.replace("{REPO}", args.repo)
print(f"Running: \n{build_command}")
subprocess.call(build_command, shell=True)
push_command = PUSH_COMMAND_TMPL
push_command = push_command.replace("{TAG}", args.tag)
push_command = push_command.replace("{PROJECT}", args.project)
push_command = push_command.replace("{REGION}", args.region)
push_command = push_command.replace("{REPO}", args.repo)
print(f"Running: \n{push_command}")
subprocess.call(push_command, shell=True)
if __name__ == "__main__":
main()