Пример #1
0
    def __init__(self, parent=None, sub_components=[]):
        self.config = Config()
        self.parent = parent

        self.sub_components = []

        for component in sub_components:
            component.parent = self.name
            self.sub_components.append(component)
Пример #2
0
    def reload(self):
        """
        Reloads the configuration file
        """
        self.config = Config()

        for component in self.sub_components:
            component.parent = self
Пример #3
0
def main(args):
    config = Config()
    with repository_root():
        with use_dir(Projects.BACKEND):
            log.info(f"Updating {args.environment} backend")
            run(["zappa", "update", args.environment])

            log.info(f"Running migrations for {args.environment}")
            run(["zappa", "manage", args.environment, "migrate"])

        with use_dir(Projects.FRONTEND):
            log.info(f"Updating {args.environment} frontend")
            run(["eb", "deploy", f"{config.name}-{args.environment}"])
Пример #4
0
def main(args):
    config = Config()
    ecs = boto3.client("ecs")

    with repository_root():
        with use_dir(Projects.BACKEND):
            log.info(f"Updating {args.environment} backend")
            run(["zappa", "update", args.environment])

            log.info(f"Running migrations for {args.environment}")
            run(["zappa", "manage", args.environment, "migrate"])

        with use_dir(Projects.FRONTEND):
            log.info("Building frontend")
            image_name = f"{config.name}-frontend"
            latest = f"{image_name}:latest"
            git_commit_hash = get_git_commit_hash()
            tags = ["latest", f"{args.environment}", f"{git_commit_hash}"]

            run([
                "docker",
                "build",
                "-t",
                f"{latest}",
                "-t",
                f"{image_name}:{args.environment}",
                "-t",
                f"{image_name}:{git_commit_hash}",
                ".",
            ])

            for tag in tags:
                run([
                    "docker",
                    "tag",
                    f"{image_name}:{tag}",
                    f"{ECR_REPO_PREFIX}/{image_name}:{tag}",
                ])
                run([
                    "docker", "push", f"{ECR_REPO_PREFIX}/{image_name}:{tag}"
                ])

            log.info(
                f"Updating service frontend-{args.environment} on {config.name} ECS cluster"
            )
            ecs.update_service(
                cluster=f"{config.name}",
                service=f"frontend-{args.environment}",
                taskDefinition=f"{config.name}-frontend-{args.environment}",
                forceNewDeployment=True,
            )
Пример #5
0
def main(args):
    config = Config()
    with repository_root():
        with use_dir(Projects.BACKEND):
            log.info(f"Updating {args.environment} backend")
            run(["zappa", "update", args.environment])

            log.info(f"Running migrations for {args.environment}")
            run(["zappa", "manage", args.environment, "migrate"])

        with use_dir(Projects.FRONTEND):
            log.info("Building frontend")
            image_name = f"{config.name}-frontend"
            latest = f"{image_name}:latest"
            run(["docker", "build", "-t", f"{image_name}", "."])
            run([
                "docker",
                "tag",
                f"{config.name}-frontend:latest",
                f"{ECR_REPO_PREFIX}/{latest}",
            ])
            run(["docker", "push", f"{ECR_REPO_PREFIX}/{latest}"])
Пример #6
0
class Component:
    def __init__(self, parent=None, sub_components=[]):
        self.config = Config()
        self.parent = parent

        self.sub_components = []

        for component in sub_components:
            component.parent = self.name
            self.sub_components.append(component)

    @property
    def name(self):
        """
        Convenience function for retrieving the class name
        """
        return self.__class__.__name__

    @property
    def identifier(self):
        """
        The component's path in the tree, using django notation

        (i.e. Backend__Linting, Backend__Dockerfile, Frontend__Tests, etc.)
        """
        if self.parent is None:
            return self.name

        return '{self.parent}__{self.name}'

    @property
    def exclude(self):
        """
        Whether or not this sub-component should be used in the project
        """
        if self.config.get('exclude', None) is None:
            return False

        return self.identifier in self.config.exclude

    @property
    def include(self):
        """
        Convenience wrapper for easier reading
        """
        return not self.exclude

    def call_phase(self, phase):
        """
        Calls a phase (e.g. create, update, delete) on self + all sub components
        """
        if self.exclude:
            log.debug(
                f'Skipping {self.identifier} as it was found in the exclude list'
            )
            return

        log_string = 'Calling phase {} for {}'

        phase_func = getattr(self, phase, None)

        if phase_func is not None:
            with repository_root():
                log.info(log_string.format(phase, self.__class__.__name__))
                phase_func()

        for component in self.sub_components:
            log.info(log_string.format(phase, component.__class__.__name__))
            component.call_phase(phase)