-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpublish_container.py
More file actions
executable file
·87 lines (75 loc) · 2.8 KB
/
publish_container.py
File metadata and controls
executable file
·87 lines (75 loc) · 2.8 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
"""
Build the Dashboard (GUI) container or
build the ML training container (with CUDA support) for
Perlmutter (NERSC) and publish it to registry.nersc.gov
"""
import argparse
import subprocess
def run(command: str, proceed: str, auto_yes: bool):
if auto_yes or proceed in ["y"]:
try:
subprocess.run(
command,
check=True,
encoding="utf-8",
shell=True,
text=True,
)
except Exception as error:
print(error)
else:
print("Skipping...")
def build_container(container: str, auto_yes: bool):
# where to find the Dockerfile
folders = {
"gui": "dashboard",
"ml": "ml",
}
# how to name the container image
imagename = {
"gui": "synapse-gui",
"ml": "synapse-ml",
}
# build the new image
proceed = "y" if auto_yes else input(f"\nBuild new {container} image? [y/N] ")
command = f"docker build --platform linux/amd64 --output type=image,oci-mediatypes=true -t {imagename[container]} -f {folders[container]}.Dockerfile ."
run(command, proceed, auto_yes)
# upload to the NERSC registry
proceed = "y" if auto_yes else input(f"\nPublish new {container} image? [y/N] ")
command_list = [
"docker login registry.nersc.gov",
f"docker tag {imagename[container]}:latest registry.nersc.gov/m558/superfacility/{imagename[container]}:latest",
f"docker tag {imagename[container]}:latest registry.nersc.gov/m558/superfacility/{imagename[container]}:$(date '+%y.%m')",
f"docker push -a registry.nersc.gov/m558/superfacility/{imagename[container]}",
]
command = " && ".join(command_list)
run(command, proceed, auto_yes)
if __name__ == "__main__":
# CLI options: --gui --ml
parser = argparse.ArgumentParser(
description="Build a container image and push it to the NERSC registry."
)
parser.add_argument(
"--gui", action="store_true", help="Build Dashboard GUI container"
)
parser.add_argument("--ml", action="store_true", help="Build ML training container")
parser.add_argument(
"-y",
"--yes",
action="store_true",
help="Automatically answer yes to all prompts",
)
args = parser.parse_args()
containers = []
containers += ["gui"] if args.gui else []
containers += ["ml"] if args.ml else []
if len(containers) == 0:
parser.error("At least one of the options --gui or --ml must be set.")
# prune all existing images
proceed = "y" if args.yes else input("\nPrune all existing images? [y/N] ")
command = "docker system prune -a -f"
run(command, proceed, args.yes)
# build new container images
for container in containers:
build_container(container, args.yes)