This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
forked from mongodb/mongodb-kubernetes-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline.py
205 lines (167 loc) · 5.88 KB
/
pipeline.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import argparse
import json
import sys
from typing import Dict, Optional
from sonar.sonar import process_image
from scripts.dev.dev_config import load_config, DevConfig
VALID_IMAGE_NAMES = frozenset(
[
"agent-ubi",
"agent-ubuntu",
"readiness-probe-init",
"version-post-start-hook-init",
"operator-ubi",
"e2e",
]
)
DEFAULT_IMAGE_TYPE = "ubi"
DEFAULT_NAMESPACE = "default"
def _load_release() -> Dict:
with open("release.json") as f:
release = json.loads(f.read())
return release
def _build_agent_args(config: DevConfig) -> Dict[str, str]:
release = _load_release()
return {
"agent_version": release["mongodb-agent"]["version"],
"release_version": release["mongodb-agent"]["version"],
"tools_version": release["mongodb-agent"]["tools_version"],
"agent_image": config.agent_image,
"agent_image_dev": config.agent_dev_image,
"registry": config.repo_url,
"s3_bucket": config.s3_bucket,
}
def build_agent_image_ubi(config: DevConfig) -> None:
image_name = "agent-ubi"
args = _build_agent_args(config)
args["agent_image"] = config.agent_image_ubi
args["agent_image_dev"] = config.agent_dev_image_ubi
config.ensure_tag_is_run("ubi")
sonar_build_image(
image_name,
config,
args=args,
)
def build_agent_image_ubuntu(config: DevConfig) -> None:
image_name = "agent-ubuntu"
args = _build_agent_args(config)
args["agent_image"] = config.agent_image_ubuntu
args["agent_image_dev"] = config.agent_dev_image_ubuntu
config.ensure_tag_is_run("ubuntu")
sonar_build_image(
image_name,
config,
args=args,
)
def build_readiness_probe_image(config: DevConfig) -> None:
release = _load_release()
config.ensure_tag_is_run("readiness-probe")
config.ensure_tag_is_run("ubi")
sonar_build_image(
"readiness-probe-init",
config,
args={
"builder": "true",
"base_image": "registry.access.redhat.com/ubi8/ubi-minimal:latest",
"registry": config.repo_url,
"release_version": release["readiness-probe"],
"readiness_probe_image": config.readiness_probe_image,
"readiness_probe_image_dev": config.readiness_probe_image_dev,
"builder_image": release["golang-builder-image"],
"s3_bucket": config.s3_bucket,
},
)
def build_version_post_start_hook_image(config: DevConfig) -> None:
release = _load_release()
config.ensure_tag_is_run("post-start-hook")
config.ensure_tag_is_run("ubi")
sonar_build_image(
"version-post-start-hook-init",
config,
args={
"builder": "true",
"base_image": "registry.access.redhat.com/ubi8/ubi-minimal:latest",
"registry": config.repo_url,
"release_version": release["version-upgrade-hook"],
"version_post_start_hook_image": config.version_upgrade_hook_image,
"version_post_start_hook_image_dev": config.version_upgrade_hook_image_dev,
"builder_image": release["golang-builder-image"],
"s3_bucket": config.s3_bucket,
},
)
def build_operator_ubi_image(config: DevConfig) -> None:
release = _load_release()
config.ensure_tag_is_run("ubi")
sonar_build_image(
"operator-ubi",
config,
args={
"registry": config.repo_url,
"builder": "true",
"builder_image": release["golang-builder-image"],
"base_image": "registry.access.redhat.com/ubi8/ubi-minimal:latest",
"operator_image": config.operator_image,
"operator_image_dev": config.operator_image_dev,
"release_version": release["mongodb-kubernetes-operator"],
"s3_bucket": config.s3_bucket,
},
inventory="inventories/operator-inventory.yaml",
)
def build_e2e_image(config: DevConfig) -> None:
release = _load_release()
sonar_build_image(
"e2e",
config,
args={
"registry": config.repo_url,
"base_image": release["golang-builder-image"],
"e2e_image": config.e2e_image,
},
inventory="inventories/e2e-inventory.yaml",
)
def sonar_build_image(
image_name: str,
config: DevConfig,
args: Optional[Dict[str, str]] = None,
inventory: str = "inventory.yaml",
) -> None:
"""Calls sonar to build `image_name` with arguments defined in `args`."""
process_image(
image_name,
build_args=args,
inventory=inventory,
include_tags=config.include_tags,
skip_tags=config.skip_tags,
)
def _parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument("--image-name", type=str)
parser.add_argument("--release", type=lambda x: x.lower() == "true")
return parser.parse_args()
def main() -> int:
args = _parse_args()
image_name = args.image_name
if image_name not in VALID_IMAGE_NAMES:
print(
f"Image name [{image_name}] is not valid. Must be one of [{', '.join(VALID_IMAGE_NAMES)}]"
)
return 1
config = load_config()
# by default we do not want to run any release tasks. We must explicitly
# use the --release flag to run them.
config.ensure_skip_tag("release")
# specify --release to release the image
if args.release:
config.ensure_tag_is_run("release")
image_build_function = {
"agent-ubi": build_agent_image_ubi,
"agent-ubuntu": build_agent_image_ubuntu,
"readiness-probe-init": build_readiness_probe_image,
"version-post-start-hook-init": build_version_post_start_hook_image,
"operator-ubi": build_operator_ubi_image,
"e2e": build_e2e_image,
}[image_name]
image_build_function(config)
return 0
if __name__ == "__main__":
sys.exit(main())