-
Notifications
You must be signed in to change notification settings - Fork 6
/
build_components.py
73 lines (56 loc) · 2.03 KB
/
build_components.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import docker
from pathlib import Path
from datetime import datetime
import subprocess
from privatekube.experiments.utils import load_yaml
import typer
from typing import Optional
from loguru import logger
def build_dir(client, repo, directory):
for subdir in filter(lambda x: x.is_dir(), directory.iterdir()):
build(client, repo, subdir)
def build(client, repo, subdir):
name = subdir.name
tag = datetime.now().strftime("%m-%d-%H-%M-%S")
image = f"{repo}/{name}:{tag}"
logger.info(f"Building: {image}")
im = client.images.build(
path=str(subdir.absolute()),
tag=f"{repo}/{name}:{tag}",
)
for l in im[1]:
logger.info(l)
res = client.api.push(f"{repo}/{name}", tag=tag)
logger.info(res)
subprocess.call(
f"sed 's=DOCKER_IMAGE_PLACEHOLDER='\"{image}\"'=g' {subdir.joinpath('src/component.yaml').absolute()} > {subdir.joinpath('component.yaml').absolute()}",
shell=True,
)
logger.info("Done.")
def main(
dir: Optional[str] = typer.Argument("", help="Base directory for the components"),
single: Optional[bool] = typer.Option(
False,
help="Build a single component instead of all the components in the directory.",
)
# vector_cache: Optional[bool] = typer.Argument(False, help="Copy the vector cache"),
):
secrets = load_yaml(Path(__file__).parent.joinpath("client_secrets.yaml"))
repo = secrets["repo"]
client = docker.from_env()
if not single:
if dir == "":
directory = Path(__file__).parent.absolute()
else:
directory = Path(dir).absolute()
logger.info(f"Building whole directory: {directory}")
build_dir(client, repo, directory)
else:
if dir == "":
raise Exception("Please provide a component directory")
else:
directory = Path(dir).absolute()
logger.info(f"Building single component directory: {directory}")
build(client, repo, directory)
if __name__ == "__main__":
typer.run(main)