def run(self): """Run the validator the read the index and update the dependency graph""" if not self._success: return False for entry in self._index_data: # Form the container name from index yaml primary_container_name = str(entry["app-id"]) + "/" + str(entry["job-id"]) + ":" + str(entry["desired-tag"]) # Add the container to dependency graph (if it does not already exist) self._context.dependency_validator.dependency_graph.add_container(primary_container_name, from_index=True) # Check if entry has any dependencies to account for if entry["depends-on"]: if not isinstance(entry["depends-on"], list): value = [entry["depends-on"]] else: value = entry["depends-on"] for item in value: if ":" not in item: item += ":latest" # Add the dependent container to dependency graph, if it does not already exist self._context.dependency_validator.dependency_graph.add_container(str(item), from_index=True) # Ensure that the dependency from current depends-on container and the current container is # established self._context.dependency_validator.dependency_graph.add_dependency(str(item), primary_container_name) # Work out the path to targetfile git_branch = entry["git-branch"] target_file_dir = entry["git-url"] git_path = str(entry["git-path"]) if ":" in target_file_dir: # If the git-url containers :, then we dont need the protocol part, so just get the uri target_file_dir = target_file_dir.split(":")[1] # The final git-path would be path where all repos are dumped + the git-url part + git-path # Example : repo_dump = /mydir, git-url = https://github.com/user/repo, git-path= /mydir # then final path = /mydir/github.com/user/repo/mydir target_file_dir = self._context.environment.repo_dump + "/" + target_file_dir target_file = target_file_dir + "/" + git_path + "/" + entry["target-file"] get_back = getcwd() chdir(target_file_dir) # Checkout required branch cmd = ["git", "checkout", "origin/" + git_branch] execute_command(cmd) chdir(get_back) base_image = None try: with open(target_file, "r") as f: for line in f: l = line.strip() if l.startswith("FROM"): base_image = l.split()[1] break except Exception as e: print e if base_image: self._context.dependency_validator.dependency_graph.add_container(container_name=base_image, from_target_file=True) self._context.dependency_validator.dependency_graph.add_dependency(base_image, primary_container_name) return True
def run(self): """Run the validator the read the index and update the dependency graph""" if not self._success: return False for entry in self._index_data: # Form the container name from index yaml primary_container_name = str(entry["app-id"]) + "/" + str(entry["job-id"]) + ":" + str(entry["desired-tag"]) # Add the container to dependency graph (if it does not already exist) self._context.dependency_validator.dependency_graph.add_container(primary_container_name, from_index=True) # Check if entry has any dependencies to account for if entry["depends-on"]: if not isinstance(entry["depends-on"], list): value = [entry["depends-on"]] else: value = entry["depends-on"] for item in value: if ":" not in item: item += ":latest" # Add the dependent container to dependency graph, if it does not already exist self._context.dependency_validator.dependency_graph.add_container(str(item), from_index=True) # Ensure that the dependency from current depends-on container and the current container is # established self._context.dependency_validator.dependency_graph.add_dependency(str(item), primary_container_name) # Work out the path to targetfile git_branch = entry["git-branch"] target_file_dir = entry["git-url"] git_path = entry["git-path"] if ":" in target_file_dir: # If the git-url containers :, then we dont need the protocol part, so just get the uri target_file_dir = target_file_dir.split(":")[1] # The final git-path would be path where all repos are dumped + the git-url part + git-path # Example : repo_dump = /mydir, git-url = https://github.com/user/repo, git-path= /mydir # then final path = /mydir/github.com/user/repo/mydir target_file_dir = self._context.environment.repo_dump + "/" + target_file_dir target_file = target_file_dir + "/" + git_path + "/" + entry["target-file"] get_back = getcwd() chdir(target_file_dir) # Checkout required branch cmd = ["git", "checkout", "origin/" + git_branch] execute_command(cmd) chdir(get_back) base_image = None try: with open(target_file, "r") as f: for line in f: l = line.strip() if l.startswith("FROM"): base_image = l.split()[1] break except Exception as e: print e if base_image: self._context.dependency_validator.dependency_graph.add_container(container_name=base_image, from_target_file=True) self._context.dependency_validator.dependency_graph.add_dependency(base_image, primary_container_name) return True
def update_git_url(repo_dump, git_url, git_branch): clone_path = None # Work out the path to clone repo to clone_to = git_url if ":" in clone_to: clone_to = clone_to.split(":")[1] clone_to = repo_dump + "/" + clone_to # If the path doesnt already exist, attempt to clone repo if not path.exists(clone_to): cmd = ["git", "clone", git_url, clone_to] if not execute_command(cmd): return None # Update repo get_back = getcwd() chdir(clone_to) cmd = "git branch -r | grep -v '\->' | while read remote; do git branch --track \"${remote#origin/}\"" \ " \"$remote\" &> /dev/null; done" # Get all the branches system(cmd) # fetch the branches cmd = ["git", "fetch", "--all"] execute_command(cmd) # Pull for update cmd = ["git", "pull", "--all"] execute_command(cmd) # Checkout required branch cmd = ["git", "checkout", "origin/" + git_branch] if execute_command(cmd): clone_path = clone_to chdir(get_back) return clone_path