-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpreprocessing.py
131 lines (109 loc) · 4.81 KB
/
preprocessing.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from genericpath import exists
import os
import shutil
from glob import glob
from os.path import join, basename, isabs, relpath
from .helm import KEY_APPS, KEY_TASK_IMAGES
from .utils import app_name_from_path, merge_app_directories, merge_configuration_directories, find_subdirs
from cloudharness_utils.constants import APPS_PATH, BASE_IMAGES_PATH, STATIC_IMAGES_PATH, DEFAULT_MERGE_PATH
def preprocess_build_overrides(root_paths, helm_values, merge_build_path=DEFAULT_MERGE_PATH):
if not isabs(merge_build_path):
merge_build_path = join(os.getcwd(), merge_build_path)
if len(root_paths) < 2:
return root_paths
if not os.path.exists(merge_build_path):
os.makedirs(merge_build_path)
else:
shutil.rmtree(merge_build_path)
merged = False
artifacts = {}
def merge_appdir(root_path, base_path):
app_name = app_name_from_path(basename(base_path))
dest_path = join(
merge_build_path,
relpath(base_path, root_path)
)
merge_configuration_directories(artifacts[app_name], dest_path)
merge_configuration_directories(base_path, dest_path)
for root_path in root_paths:
for base_path in find_subdirs(join(root_path, BASE_IMAGES_PATH)):
app_name = app_name_from_path(basename(base_path))
if app_name not in artifacts:
artifacts[app_name] = base_path
elif app_name in helm_values[KEY_TASK_IMAGES]:
libraries_path = join(root_path, 'libraries')
if exists(libraries_path):
merge_configuration_directories(
libraries_path,
join(merge_build_path, 'libraries')
)
merge_appdir(root_path, base_path)
merged = True
for root_path in root_paths:
for base_path in find_subdirs(join(root_path, STATIC_IMAGES_PATH)):
app_name = app_name_from_path(basename(base_path))
if app_name not in artifacts:
artifacts[app_name] = base_path
elif app_name in helm_values[KEY_TASK_IMAGES]:
merge_appdir(root_path, base_path)
merged = True
for root_path in root_paths:
for base_path in find_subdirs(join(root_path, APPS_PATH)):
app_name = app_name_from_path(basename(base_path))
if app_name not in artifacts:
artifacts[app_name] = base_path
elif app_name.replace("-", "_") in helm_values[KEY_APPS]:
merge_appdir(root_path, base_path)
merged = True
if exists(merge_build_path):
with open(join(merge_build_path, ".dockerignore"), "a") as dst:
for root_path in root_paths:
ignore_file = join(root_path, ".dockerignore")
if os.path.exists(ignore_file):
with open(ignore_file) as src:
dst.write(src.read())
return (root_paths + [merge_build_path]) if merged else root_paths
def get_build_paths(root_paths, helm_values, merge_build_path=DEFAULT_MERGE_PATH):
"""
Gets the same paths from preprocess_build_overrides
"""
if not isabs(merge_build_path):
merge_build_path = join(os.getcwd(), merge_build_path)
artifacts = {}
for root_path in root_paths:
for base_path in find_subdirs(join(root_path, BASE_IMAGES_PATH)):
app_name = app_name_from_path(basename(base_path))
if app_name not in helm_values[KEY_TASK_IMAGES]:
continue
if app_name not in artifacts:
artifacts[app_name] = base_path
else:
artifacts[app_name] = join(
merge_build_path,
relpath(base_path, root_path)
)
for root_path in root_paths:
for base_path in find_subdirs(join(root_path, STATIC_IMAGES_PATH)):
app_name = app_name_from_path(basename(base_path))
if app_name not in helm_values[KEY_TASK_IMAGES]:
continue
if app_name not in artifacts:
artifacts[app_name] = base_path
else:
artifacts[app_name] = join(
merge_build_path,
relpath(base_path, root_path)
)
for root_path in root_paths:
for base_path in find_subdirs(join(root_path, APPS_PATH)):
app_name = app_name_from_path(basename(base_path))
if app_name.replace("-", "_") not in helm_values[KEY_APPS]:
continue
if app_name not in artifacts:
artifacts[app_name] = base_path
else:
artifacts[app_name] = join(
merge_build_path,
relpath(base_path, root_path)
)
return artifacts