|
33 | 33 | build_init_database, |
34 | 34 | build_init_om_image, |
35 | 35 | build_om_image, |
36 | | - operator_build_configuration, |
37 | 36 | ) |
38 | 37 | from scripts.release.build_configuration import BuildConfiguration |
| 38 | +from scripts.release.build_context import ( |
| 39 | + BuildContext, |
| 40 | + RegistryResolver, |
| 41 | + VersionResolver, |
| 42 | +) |
39 | 43 |
|
40 | 44 |
|
41 | 45 | def get_builder_function_for_image_name() -> Dict[str, Callable]: |
@@ -73,22 +77,13 @@ def build_image(image_name: str, build_configuration: BuildConfiguration): |
73 | 77 |
|
74 | 78 | def build_all_images( |
75 | 79 | images: Iterable[str], |
76 | | - base_registry: str, |
77 | | - debug: bool = False, |
78 | | - parallel: bool = False, |
79 | | - architecture: Optional[List[str]] = None, |
80 | | - sign: bool = False, |
81 | | - all_agents: bool = False, |
82 | | - parallel_factor: int = 0, |
| 80 | + build_configuration: BuildConfiguration, |
83 | 81 | ): |
84 | 82 | """Builds all the images in the `images` list.""" |
85 | | - build_configuration = operator_build_configuration( |
86 | | - base_registry, parallel, debug, architecture, sign, all_agents, parallel_factor |
87 | | - ) |
88 | | - if sign: |
89 | | - mongodb_artifactory_login() |
| 83 | + # if sign: |
| 84 | + # mongodb_artifactory_login() |
90 | 85 | for idx, image in enumerate(images): |
91 | | - logger.info(f"====Building image {image} ({idx}/{len(images)-1})====") |
| 86 | + logger.info(f"====Building image {image} ({idx + 1}/{len(images)})====") |
92 | 87 | time.sleep(1) |
93 | 88 | build_image(image, build_configuration) |
94 | 89 |
|
@@ -126,70 +121,68 @@ def _setup_tracing(): |
126 | 121 |
|
127 | 122 | def main(): |
128 | 123 | _setup_tracing() |
129 | | - |
130 | | - parser = argparse.ArgumentParser() |
131 | | - parser.add_argument("--include", action="append", help="list of images to include") |
132 | | - parser.add_argument("--list-images", action="store_true") |
133 | | - parser.add_argument("--parallel", action="store_true", default=False) |
134 | | - parser.add_argument("--debug", action="store_true", default=False) |
| 124 | + parser = argparse.ArgumentParser(description="Build container images.") |
| 125 | + parser.add_argument("--include", action="append", help="Image to include.") |
| 126 | + parser.add_argument("--skip", action="append", help="Image to skip.") |
135 | 127 | parser.add_argument( |
136 | | - "--arch", |
137 | | - choices=["amd64", "arm64"], |
138 | | - nargs="+", |
139 | | - help="for operator and community images only, specify the list of architectures to build for images", |
| 128 | + "--builder", |
| 129 | + default="docker", |
| 130 | + choices=["docker", "podman"], |
| 131 | + help="Tool to use to build images.", |
140 | 132 | ) |
141 | | - parser.add_argument("--sign", action="store_true", default=False) |
| 133 | + parser.add_argument("--parallel", action="store_true", help="Build images in parallel.") |
| 134 | + parser.add_argument("--debug", action="store_true", help="Enable debug logging.") |
| 135 | + parser.add_argument("--sign", action="store_true", help="Sign images.") |
142 | 136 | parser.add_argument( |
143 | | - "--parallel-factor", |
144 | | - type=int, |
145 | | - default=0, |
146 | | - help="the factor on how many agents are built in parallel. 0 means all CPUs will be used", |
| 137 | + "--architecture", |
| 138 | + action="append", |
| 139 | + help="Target architecture for the build. Can be specified multiple times. Defaults to amd64 and arm64.", |
147 | 140 | ) |
148 | 141 | parser.add_argument( |
149 | 142 | "--all-agents", |
150 | 143 | action="store_true", |
151 | | - default=False, |
152 | | - help="optional parameter to be able to push " |
153 | | - "all non operator suffixed agents, even if we are not in a release", |
| 144 | + help="Build all agent variants instead of only the latest.", |
| 145 | + ) |
| 146 | + parser.add_argument( |
| 147 | + "--parallel-factor", |
| 148 | + default=0, |
| 149 | + type=int, |
| 150 | + help="Number of builds to run in parallel, defaults to number of cores", |
154 | 151 | ) |
155 | | - args = parser.parse_args() |
156 | | - |
157 | | - images_list = get_builder_function_for_image_name().keys() |
158 | 152 |
|
159 | | - if args.list_images: |
160 | | - print(images_list) |
161 | | - sys.exit(0) |
| 153 | + args = parser.parse_args() |
| 154 | + images_to_build = get_builder_function_for_image_name().keys() |
162 | 155 |
|
163 | | - if not args.include: |
164 | | - logger.error(f"--include is required") |
165 | | - sys.exit(1) |
| 156 | + if args.include: |
| 157 | + images_to_build = set(args.include) |
166 | 158 |
|
167 | | - if args.arch == ["arm64"]: |
168 | | - print("Building for arm64 only is not supported yet") |
169 | | - sys.exit(1) |
| 159 | + if args.skip: |
| 160 | + images_to_build = set(images_to_build) - set(args.skip) |
170 | 161 |
|
171 | | - if not args.sign: |
172 | | - logger.warning("--sign flag not provided, images won't be signed") |
| 162 | + # Centralized configuration management |
| 163 | + build_context = BuildContext.from_environment() |
| 164 | + version_resolver = VersionResolver(build_context) |
| 165 | + registry_resolver = RegistryResolver(build_context) |
173 | 166 |
|
174 | | - # TODO check that image names are valid |
175 | | - images_to_build = sorted(list(set(args.include).intersection(images_list))) |
176 | | - if not images_to_build: |
177 | | - logger.error("No images to build, please ensure images names are correct.") |
178 | | - sys.exit(1) |
| 167 | + build_configuration = BuildConfiguration( |
| 168 | + scenario=build_context.scenario, |
| 169 | + version=version_resolver.get_version(), |
| 170 | + base_registry=registry_resolver.get_base_registry(), |
| 171 | + parallel=args.parallel, |
| 172 | + debug=args.debug, |
| 173 | + architecture=args.architecture, |
| 174 | + sign=args.sign or build_context.signing_enabled, |
| 175 | + all_agents=args.all_agents or bool(os.environ.get("all_agents", False)), |
| 176 | + parallel_factor=args.parallel_factor, |
| 177 | + ) |
179 | 178 |
|
180 | | - TEMP_HARDCODED_BASE_REGISTRY = "268558157000.dkr.ecr.us-east-1.amazonaws.com/julienben/staging-temp" |
| 179 | + logger.info(f"Building images: {list(images_to_build)}") |
| 180 | + logger.info(f"Build configuration: {build_configuration}") |
181 | 181 |
|
182 | 182 | build_all_images( |
183 | | - base_registry=TEMP_HARDCODED_BASE_REGISTRY, |
184 | 183 | images=images_to_build, |
185 | | - debug=args.debug, |
186 | | - parallel=args.parallel, |
187 | | - architecture=args.arch, |
188 | | - sign=args.sign, |
189 | | - all_agents=args.all_agents, |
190 | | - parallel_factor=args.parallel_factor, |
| 184 | + build_configuration=build_configuration, |
191 | 185 | ) |
192 | 186 |
|
193 | | - |
194 | 187 | if __name__ == "__main__": |
195 | 188 | main() |
0 commit comments