def run(self): # Ensure we have an index specified index = Stack.get_config("index") if not index: logger.error("Stack package index not specified, cannot proceed") exit(1) # Get the package, if specified if self.options["<package>"]: packages = [self.options["<package>"]] else: packages = [package["name"] for package in Stack.get_config("packages")] # Process each package for package in packages: # Update the package if self.update(package): logger.info("Package '{}' was updated successfully".format(package)) # Update services self.update_apps(package) else: logger.error("Error: Could not update package") exit(1)
def run(self): # Get the app. app = self.options["<app>"] branch = self.options["<branch>"] # Get the repo URL repo_url = App.get_repo_url(app) if repo_url is None: logger.error("({}) No repository URL specified...".format(app)) return # Determine the path to the app directory apps_dir = os.path.relpath(Stack.get_config("apps-directory")) subdir = os.path.join(apps_dir, app) # Ensure it exists. if os.path.exists(subdir): logger.error( "({}) A repository already exists, use 'stack checkout' to" " change branches".format(app) ) return # Build the command command = [ "git", "subtree", "add", "--prefix={}".format(subdir), repo_url, branch, "--squash", ] # Check for pre-clone hook Stack.hook("pre-clone", app, [os.path.realpath(subdir)]) # Run the command. return_code = Stack.run(command) # Check for post-clone hook if return_code == 0: Stack.hook("post-clone", app, [os.path.realpath(subdir)])
def run(self): # Get the app. app = self.options["<app>"] branch = self.options["<branch>"] # Get the repo URL repo_url = App.get_repo_url(app) if repo_url is None: logger.error("({}) No repository URL specified...".format(app)) return # Determine the path to the app directory apps_dir = os.path.relpath(Stack.get_config("apps-directory")) subdir = os.path.join(apps_dir, app) # Ensure it exists. if not os.path.exists(subdir): logger.error( '({}) No repository at {}, run "stack clone" command first'. format(app)) return # Build the command command = [ "git", "subtree", "pull", "--prefix={}".format(subdir), repo_url, branch, ] # Check for a squash. if self.options.get("--squash"): command.append("--squash") # Run the command. Stack.run(command)
def run(self): # Create a list of apps to update apps = App.get_apps() # Get the app. app = self.options.get("<app>") if app: apps = [app] # Filter out apps without repository details apps = [app for app in apps if App.get_repo_branch(app)] # Ensure no local changes if Stack.run( ["git", "diff-index", "--name-status", "--exit-code", "HEAD"]): logger.error( "Current working copy has changes, cannot update app repositories" ) exit(1) logger.info("Will update {}".format(", ".join(apps))) # Iterate and update for app in apps: # Get the repo URL repo_url = App.get_repo_url(app) branch = App.get_repo_branch(app) if repo_url is None or branch is None: logger.error( "({}) No repository URL and/or branch specified...".format( app)) continue # Determine the path to the app directory apps_dir = os.path.relpath(Stack.get_config("apps-directory")) subdir = os.path.join(apps_dir, app) # Check for pre-checkout hook Stack.hook("pre-checkout", app, [os.path.realpath(subdir)]) # Build the command command = [ "git", "subtree", "add", "--prefix={}".format(subdir), repo_url, branch, "--squash", ] # Remove the current subtree. Stack.run(["git", "rm", "-rf", subdir]) Stack.run(["rm", "-rf", subdir]) Stack.run([ "git", "commit", "-m", '"Stack op: Removing subtree {} for cloning branch {}"'.format( app, branch), ]) # Run the command. Stack.run(command) # Check for post-checkout hook Stack.hook("post-checkout", app, [os.path.realpath(subdir)])
def update_apps(package): # Find all services listing this package for app, config in Stack.get_config("apps").items(): try: # Check packages if config.get("packages") and package in config.get("packages"): # Get the docker client. docker_client = docker.from_env() # Determine the app. if App.check_running(docker_client, app): logger.info( "App '{}' depends on '{}', reinstalling...".format( app, package ) ) # Build the uninstall command uninstall = [ "docker-compose", "exec", app, "pip", "uninstall", "-y", package, ] # Execute a shell. code = Stack.run(uninstall) if code == 0: logger.info(" ... uninstalled ...") # Build the install command install = [ "docker-compose", "exec", app, "pip", "install", package, ] # Execute a shell. code = Stack.run(install) if code == 0: logger.info(" ... reinstall succeeded!") else: logger.error( " .... failed with exit code: {}".format(code) ) else: logger.error( " .... failed with exit code: {}".format(code) ) else: logger.error( " .... App {} is not running, cannot update".format(app) ) except Exception as e: logger.exception( "Error reinstalling package for {}: {}".format(app, e), exc_info=True, )
def run(self): # Get the app. app = self.options["<app>"] branch = self.options["<branch>"] # Get the repo URL repo_url = App.get_repo_url(app) if repo_url is None: logger.error("({}) No repository URL specified...".format(app)) return # Determine the path to the app directory apps_dir = os.path.relpath(Stack.get_config("apps-directory")) subdir = os.path.join(apps_dir, app) # Ensure no local changes if Stack.run(["git", "diff-index", "--name-status", "--exit-code", "HEAD"]): logger.error( "Current working copy has changes, cannot update app repositories" ) exit(1) # Check if new branch. if self.options["-b"]: # Ensure it exists. if not os.path.exists(subdir): logger.error( "({}) This repository does not exist yet, run" " 'stack clone' command first".format(app, subdir) ) return # Check for pre-checkout hook Stack.hook("pre-checkout", app, [os.path.realpath(subdir)]) # Do a split. command = [ "git", "subtree", "split", "--prefix={}".format(subdir), "--branch", branch, ] Stack.run(command) else: # Check for pre-checkout hook Stack.hook("pre-checkout", app, [os.path.realpath(subdir)]) # Build the command command = [ "git", "subtree", "add", "--prefix={}".format(subdir), repo_url, branch, "--squash", ] # Remove the current subtree. Stack.run(["git", "rm", "-rf", subdir]) Stack.run(["rm", "-rf", subdir]) Stack.run( [ "git", "commit", "-m", '"Stack op: Removing subtree {} for cloning branch {}"'.format( app, branch ), ] ) # Run the command. Stack.run(command) # Check for post-checkout hook Stack.hook("post-checkout", app, [os.path.realpath(subdir)])