Loads the composition specified by the command-line arguments.
(
args: argparse.Namespace,
munge_services: bool = True,
resolve_image_specs: bool = True,
)
| 180 | |
| 181 | |
| 182 | def load_composition( |
| 183 | args: argparse.Namespace, |
| 184 | munge_services: bool = True, |
| 185 | resolve_image_specs: bool = True, |
| 186 | ) -> Composition: |
| 187 | """Loads the composition specified by the command-line arguments.""" |
| 188 | if not args.ignore_docker_version: |
| 189 | docker_local_version = Version.parse( |
| 190 | spawn.capture(["docker", "--version"]) |
| 191 | .removeprefix("Docker version ") |
| 192 | .split(", ")[0] |
| 193 | ) |
| 194 | docker_ci_version = Version.parse("24.0.5") |
| 195 | if docker_local_version < docker_ci_version: |
| 196 | raise UIError( |
| 197 | f"Your Docker version is {docker_local_version} while the version used in CI is {docker_ci_version}, please upgrade your local Docker version to prevent unexpected breakages.", |
| 198 | hint="If you believe this is a mistake, contact the QA team. While not recommended, --ignore-docker-version can be used to ignore this version check.", |
| 199 | ) |
| 200 | |
| 201 | compose_local_version_s = spawn.capture( |
| 202 | ["docker", "compose", "version", "--short"] |
| 203 | ) |
| 204 | try: |
| 205 | compose_local_version = Version.parse(compose_local_version_s) |
| 206 | compose_ci_version = Version.parse("2.15.1") |
| 207 | if compose_local_version < compose_ci_version: |
| 208 | raise UIError( |
| 209 | f"Your Docker Compose version is {compose_local_version} while the version used in CI is {compose_ci_version}, please upgrade your local Docker Compose version to prevent unexpected breakages.", |
| 210 | hint="If you believe this is a mistake, contact the QA team. While not recommended, --ignore-docker-version can be used to ignore this version check.", |
| 211 | ) |
| 212 | except ValueError: |
| 213 | pass |
| 214 | |
| 215 | repo = mzbuild.Repository.from_arguments(MZ_ROOT, args) |
| 216 | try: |
| 217 | return Composition( |
| 218 | repo, |
| 219 | name=args.find or Path.cwd().name, |
| 220 | preserve_ports=args.preserve_ports, |
| 221 | project_name=args.project_name, |
| 222 | sanity_restart_mz=args.sanity_restart_mz, |
| 223 | host_network=args.host_network, |
| 224 | munge_services=munge_services, |
| 225 | resolve_image_specs=resolve_image_specs, |
| 226 | ) |
| 227 | except UnknownCompositionError as e: |
| 228 | if args.find: |
| 229 | hint = "available compositions:\n" |
| 230 | for name in sorted(repo.compositions): |
| 231 | hint += f" {name}\n" |
| 232 | e.set_hint(hint) |
| 233 | raise e |
| 234 | else: |
| 235 | hint = "enter one of the following directories and run ./mzcompose:\n" |
| 236 | for path in repo.compositions.values(): |
| 237 | hint += f" {path.relative_to(Path.cwd())}\n" |
| 238 | raise UIError( |
| 239 | "directory does not contain mzcompose.py", |
no test coverage detected