Exemplo n.º 1
0
 def _build_utils(self, revision) -> str:
     dockerfile = self._ensure_utils_dockerfile()
     tag = f"utils:{revision}"
     self._checkout_revision(revision)
     with workspace("images/utils/"):
         execute(f"docker build . -f {dockerfile} -t {tag}")
         return tag
Exemplo n.º 2
0
 def _get_current_branch_history(self, branch) -> List[str]:
     if branch == "master":
         # The commit 66f5d19 is the first commit that introduces utils image
         # Use this commit to shorten master history length
         output = execute(
             "git log --pretty=format:'%H' --no-patch 66f5d19..")
     else:
         output = execute(
             "git log --pretty=format:'%H' --no-patch origin/master..")
     return output.splitlines()
Exemplo n.º 3
0
    def _diff_template_py(
            self,
            registry_utils_image: DockerImage) -> Dict[str, VersionChange]:
        registry_revision = registry_utils_image.revision

        registry_utils = self._build_utils(registry_revision)
        r1 = self._dump_template(registry_utils)
        self._logger.debug(
            "Registry utils:%s template\n%s", registry_revision,
            "\n".join([f"{key} {value}" for key, value in r1.items()]))

        current_revision = execute("git rev-parse HEAD").strip()
        current_utils = self._build_utils(current_revision)
        r2 = self._dump_template(current_utils)
        self._logger.debug(
            "Current utils:%s template\n%s", current_revision,
            "\n".join([f"{key} {value}" for key, value in r1.items()]))

        result = {}

        for key, new_version in r2.items():
            network, image = key.split("/")
            if key in r1:
                old_version = r1[key]
                if old_version != new_version:
                    result[image] = VersionChange(network, old_version,
                                                  new_version)
            else:
                result[image] = VersionChange(network, None, new_version)

        self._logger.debug(
            "Image utils template diff result: %s",
            "\n".join([f"- {k}: {v}" for k, v in result.items()]))

        return result
Exemplo n.º 4
0
 def _diff_image_with_revision(self, image, revision) -> bool:
     cmd = f"git diff --name-status {revision} -- images/{image}"
     output = execute(cmd)
     lines = output.splitlines()
     if len(lines) > 0:
         self._logger.debug("Image %s is different from %s\n%s", image,
                            revision, "\n".join(lines))
         return True
     else:
         return False
Exemplo n.º 5
0
 def _utils_exists(self, revision) -> bool:
     filter = f"reference=utils:{revision}"
     format = "{{.ID}}"
     output = execute(
         f"docker images --filter='{filter}' --format '{format}'")
     lines = output.splitlines()
     if len(lines) == 1:
         return True
     elif len(lines) == 0:
         return False
     else:
         raise RuntimeError(
             "There shouldn't be multiple utils images with filter: " +
             filter)
Exemplo n.º 6
0
 def _get_origin_url(self):
     try:
         output = execute(f"git remote get-url origin")
         return output.strip()
     except Exception as e:
         raise RuntimeError("Failed to get origin URL") from e
Exemplo n.º 7
0
 def _clone_repo(self, repo_url, repo_dir):
     try:
         execute(f"git clone {repo_url} {repo_dir}")
     except Exception as e:
         raise RuntimeError("Failed to clone repository %s to folder %s" %
                            (repo_url, repo_dir)) from e
Exemplo n.º 8
0
 def _checkout_revision(self, revision) -> None:
     try:
         execute(f"git checkout {revision}")
     except Exception as e:
         raise RuntimeError("Failed to checkout revision %s" %
                            revision) from e
Exemplo n.º 9
0
 def _checkout_origin_ref(self, ref) -> None:
     remote_ref = ref.replace("refs/heads", "refs/remotes/origin")
     execute(f"git checkout --detach {remote_ref}")
Exemplo n.º 10
0
 def _show_head(self) -> None:
     output = execute("git show --no-patch HEAD")
     self._logger.debug("Current HEAD of xud-docker repository\n%s",
                        output.strip())
Exemplo n.º 11
0
 def _get_ref_details(self, ref) -> GitReference:
     revision = execute("git rev-parse HEAD")
     commit_message = execute(
         "git show --format='%s' --no-patch HEAD").strip()
     return GitReference(ref, revision, commit_message)
Exemplo n.º 12
0
 def _fetch_updates(self) -> None:
     output = execute(f"git fetch")
     self._logger.debug("Fetched xud-docker updates\n%s", output.strip())