Beispiel #1
0
 def __init__(
     self,
     type_: constants.ImageType,
     names: typing.List[str],
     versions: typing.List[str],
     targets: typing.List[str],
 ):
     self.index = index.Index()
     self.type = type_
     self.names = names
     for name in self.names:
         if name not in self.index.groups[self.type]:
             raise TypeError(f"Group {name} is not valid!")
     self.images = []
     for images in [self.index.groups[self.type][n] for n in self.names]:
         self.images.extend(images)
     if not versions or (len(versions) == 1
                         and versions[0] == constants.ALL):
         version_set = set()
         for image in self.images:
             for v in self.index.iter_versions(self.type, image):
                 version_set.add(utils.get_major_version(v))
         versions = sorted(version_set)
     self.versions = [utils.get_major_version(v) for v in sorted(versions)]
     self.targets = targets
     logger.debug(
         "GroupInfo: type=%s names=%s versions=%s images=%s targets=%s",
         self.type,
         self.names,
         self.versions,
         self.images,
         self.targets,
     )
Beispiel #2
0
 def __init__(
     self,
     type_: constants.ImageType,
     names: typing.List[str],
     versions: typing.List[str],
     targets: typing.List[str],
 ):
     self.index = index.Index()
     self.type = type_
     self.names = names
     self.versions = [utils.get_major_version(v) for v in versions]
     for name in self.names:
         if name not in constants.GROUPS[self.type]:
             raise TypeError(f"Group {name} is not valid!")
     self.images = []
     for images in [constants.GROUPS[self.type][n] for n in self.names]:
         self.images.extend(images)
     self.targets = targets
     logger.debug(
         "GroupInfo: type=%s names=%s versions=%s images=%s targets=%s",
         self.type,
         self.names,
         self.versions,
         self.images,
         self.targets,
     )
Beispiel #3
0
    def migrate(self, dry_run: bool):
        for minfo in self.migration_list:
            if dry_run:
                logger.info("Migrating %s -> %s", minfo.source, minfo.destination)
            else:
                logger.info("Would migrate %s -> %s", minfo.source, minfo.destination)

            self.cmds.append(f"docker pull {minfo.source}")
            self.cmds.append(f"docker tag {minfo.source} {minfo.destination}")
            self.cmds.append(f"docker push {minfo.destination}")

            major_version = utils.get_major_version(minfo.version)
            version_info = constants.VERSION_INFO[major_version]
            tags = version_info.get_tags(minfo.version, self.to_org, minfo.image)
            if len(tags) > 1:
                for tag in tags:
                    if tag != minfo.destination:
                        self.cmds.append(f"docker tag {minfo.destination} {tag}")
                        self.cmds.append(f"docker push {tag}")

        if logger.isEnabledFor(logging.DEBUG):
            list(map(logger.debug, self.cmds))

        if not dry_run:
            for cmd in self.cmds:
                subprocess.run(cmd, shell=True, check=True)
Beispiel #4
0
    def make_bake_dict(self) -> dict:
        targets = {}
        for img in self.group_info.images:
            if self.group_info.target and img != self.group_info.target:
                logger.debug("Skipping target %s", img)
                continue

            image_name = utils.get_image_name(self.group_info.type, img)
            if self.group_info.type == constants.ImageType.PACKAGE:
                docker_file = "packages/Dockerfile"
                target = f"ci-{img}-package"
                target_name = f"package-{img}"
            else:
                docker_file = f"{image_name}/Dockerfile"
                target = ""
                target_name = f"image-{img}"

            all_versions = constants.VERSIONS[self.group_info.type][img]
            major_versions = [utils.get_major_version(v) for v in all_versions]
            for version in [
                    version for version in self.group_info.versions
                    if version in major_versions
            ]:
                version_info = constants.VERSION_INFO[version]
                aswf_version = all_versions[major_versions.index(version)]
                tags = version_info.get_tags(aswf_version,
                                             self.build_info.docker_org,
                                             image_name)
                target_dict = {
                    "context":
                    ".",
                    "dockerfile":
                    docker_file,
                    "args": {
                        "ASWF_ORG": self.build_info.docker_org,
                        "ASWF_PKG_ORG": self.build_info.package_org,
                        "ASWF_VERSION": aswf_version,
                        "CI_COMMON_VERSION": version_info.ci_common_version,
                        "PYTHON_VERSION": version_info.python_version,
                        "BUILD_DATE": self.build_info.build_date,
                        "VCS_REF": self.build_info.vcs_ref,
                        "VFXPLATFORM_VERSION": version,
                    },
                    "tags":
                    tags,
                    "output": [
                        "type=registry,push=true"
                        if self.push else "type=docker"
                    ],
                }
                if target:
                    target_dict["target"] = target
                targets[target_name] = target_dict

        root = {}
        root["target"] = targets
        root["group"] = {"default": {"targets": list(targets.keys())}}
        return root
Beispiel #5
0
 def iter_images_versions(self):
     for image in self.images:
         if self.targets and image not in self.targets:
             logger.debug("Skipping target %s", image)
             continue
         logger.debug("iter image=%s", image)
         ci_image = utils.get_image_name(self.type, image)
         all_versions = list(self.index.iter_versions(self.type, image))
         major_versions = [utils.get_major_version(v) for v in all_versions]
         for version in [v for v in self.versions if v in major_versions]:
             logger.debug("iter version=%s", version)
             version = all_versions[major_versions.index(version)]
             yield ci_image, version
Beispiel #6
0
    def make_bake_dict(self) -> typing.Dict[str, dict]:
        root: typing.Dict[str, dict] = {}
        root["target"] = {}
        for image, version in self.group_info.iter_images_versions():
            major_version = utils.get_major_version(version)
            version_info = self.index.version_info(major_version)
            if self.group_info.type == constants.ImageType.PACKAGE:
                tags = version_info.get_tags(
                    version,
                    self.build_info.docker_org,
                    image,
                    extra_suffix=version_info.package_versions.get(
                        "ASWF_" + image.replace("ci-package-", "").upper() +
                        "_VERSION"),
                )
                docker_file = f"packages/{self.index.get_group_from_image(self.group_info.type, image.replace('ci-package-', ''))}/Dockerfile"
            else:
                tags = version_info.get_tags(version,
                                             self.build_info.docker_org, image)
                docker_file = f"{image}/Dockerfile"
            target_dict = {
                "context":
                ".",
                "dockerfile":
                docker_file,
                "args": {
                    "ASWF_ORG": self.build_info.docker_org,
                    "ASWF_PKG_ORG": self.build_info.package_org,
                    "ASWF_VERSION": version,
                    "CI_COMMON_VERSION": version_info.ci_common_version,
                    "ASWF_VFXPLATFORM_VERSION": version_info.major_version,
                },
                "labels": {
                    "org.opencontainers.image.created":
                    self.build_info.build_date,
                    "org.opencontainers.image.revision":
                    self.build_info.vcs_ref,
                },
                "tags":
                tags,
                "output":
                ["type=registry,push=true" if self.push else "type=docker"],
            }
            target_dict["args"].update(version_info.all_package_versions)
            if self.group_info.type == constants.ImageType.PACKAGE:
                target_dict["target"] = image
            root["target"][f"{image}-{major_version}"] = target_dict

        root["group"] = {"default": {"targets": list(root["target"].keys())}}
        return root
Beispiel #7
0
    def make_bake_dict(self) -> typing.Dict[str, dict]:
        root: typing.Dict[str, dict] = {}
        root["target"] = {}
        for image, version in self.group_info.iter_images_versions():
            if self.group_info.type == constants.ImageType.PACKAGE:
                docker_file = "packages/Dockerfile"
            else:
                docker_file = f"{image}/Dockerfile"

            major_version = utils.get_major_version(version)
            version_info = constants.VERSION_INFO[major_version]
            tags = version_info.get_tags(version, self.build_info.docker_org,
                                         image)
            target_dict = {
                "context":
                ".",
                "dockerfile":
                docker_file,
                "args": {
                    "ASWF_ORG": self.build_info.docker_org,
                    "ASWF_PKG_ORG": self.build_info.package_org,
                    "ASWF_VERSION": version,
                    "CI_COMMON_VERSION": version_info.ci_common_version,
                    "PYTHON_VERSION": version_info.python_version,
                    "VFXPLATFORM_VERSION": major_version,
                    "DTS_VERSION": version_info.dts_version,
                },
                "labels": {
                    "org.opencontainers.image.created":
                    self.build_info.build_date,
                    "org.opencontainers.image.revision":
                    self.build_info.vcs_ref,
                },
                "tags":
                tags,
                "output":
                ["type=registry,push=true" if self.push else "type=docker"],
            }
            if self.group_info.type == constants.ImageType.PACKAGE:
                target_dict["target"] = image
            root["target"][f"{image}-{major_version}"] = target_dict

        root["group"] = {"default": {"targets": list(root["target"].keys())}}
        return root