Пример #1
0
    def run(self):

        # Get the docker client.
        docker_client = docker.from_env()

        # Determine the app.
        app = self.options["<app>"]
        if app is not None:

            # Check it.
            if App.check(docker_client, app):
                logger.info("({}) Is valid and ready to go!".format(app))

        else:

            # Check all apps.
            stack_valid = True
            apps = App.get_apps()
            for app in apps:

                # Check the app.
                if App.check(docker_client, app):
                    logger.info("({}) Is valid and ready to go!".format(app))

                else:
                    stack_valid = False

            if stack_valid:
                logger.info("The Stack is valid and ready to go!")
            else:
                logger.critical(
                    "Stack invalid! Ensure all paths and images are "
                    "correct and try again")
Пример #2
0
    def run(self):

        # Get the docker client.
        docker_client = docker.from_env()

        # Get the app.
        app = self.options["<app>"]
        if app is not None:

            # Check run status
            logger.info("({}) Status: {}".format(
                app, App.get_status(docker_client, app)))

        else:

            # Get all app statuses
            for app in App.get_apps():
                logger.info("({}) Status: {}".format(
                    app, App.get_status(docker_client, app)))
Пример #3
0
    def run(self):

        # Get a docker client.
        docker_client = docker.from_env()

        # Check all the build parameters.
        apps = App.get_apps()
        for app in apps:

            # Check images.
            if not App.check_docker_images(docker_client, app):
                logger.error("({}) Container image does not exist, build and"
                             " try again...".format(app))
                return

            # Ensure it is running.
            if not App.check_running(docker_client, app):
                logger.error(
                    "({}) Container is not running, ensure all containers"
                    " are started...".format(app))
                return

        # Capture and redirect output.
        Stack.run(["nosetests", "-s", "-v"])
Пример #4
0
    def run(self):

        # Get a docker client.
        docker_client = docker.from_env()

        # Get options.
        clean = self.options["--clean"]
        app = self.options["<app>"]

        # Check for stack or app
        if app:

            # Check for clean.
            if clean:

                # Clean and fetch.
                App.clean_images(docker_client, app)

                # Build it.
                App.build(app)

            # Capture and redirect output.
            Stack.run(["docker-compose", "kill", app])
            Stack.run(["docker-compose", "rm", "-f", "-v", app])

            # Run the pre-up hook, if any
            Stack.hook("pre-up", app)

            # Build the  up command
            up = ["docker-compose", "up", "--no-start"]

            # Check for purge
            if self.options["--purge"]:

                # Confirm
                if self.yes_no("This will remove all app data, continue?"):
                    logger.warning("({}) Database will be purged!".format(app))

                    # Process it
                    App.purge_data(app)
            else:
                logger.info("({}) Database will not be purged".format(app))

            # Check for flags
            if self.options.get("--flags"):

                # Split them
                flags = self.options.get("--flags").split(",")

                # Don't add no-start twice
                if "no-start" in flags:
                    flags.remove("no-start")

                # Split them, append the '--' and add them to the command
                for flag in flags:
                    up.append("-{}".format(flag) if len(flag) ==
                              1 else "--{}".format(flag))

            # Add the app
            up.append(app)

            Stack.run(up)
            Stack.run(["docker-compose", "start", app])

            # Run the post-up hook, if any
            Stack.hook("post-up", app)

        else:

            # Check for clean.
            if clean and self.yes_no("Clean: Rebuild all app images?"):

                # Clean and fetch.
                for app in App.get_apps():
                    if self.yes_no("({}) Rebuild app image?"):
                        logger.info("({}) Rebuilding image...".format(app))

                        # Rebuild images
                        App.clean_images(docker_client, app)

            # Build and run stack down
            down_command = ["stack", "down"]
            if clean:
                down_command.append("--clean")

            Stack.run(down_command)

            # Run the pre-up hook, if any
            Stack.hook("pre-up")

            # Build and run stack up
            up_command = ["stack", "up"]
            if self.options["-d"]:
                up_command.append("-d")

            Stack.run(up_command)

            # Run the pre-up hook, if any
            Stack.hook("post-up")
Пример #5
0
    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)])