Beispiel #1
0
 def mount_templates(self, snapshot, path):
     utils.clear_path(path)
     for node in snapshot.nodes:
         try:
             node_obj = self.environment.system.nodes.get(name=node.name)
         except Node.DoesNotExist:
             pass
         else:
             dest_path = os.path.join(path, str(node_obj.pk))
             utils.clear_path(dest_path)
             templates_path = os.path.join(node.container.path, 'templates')
             if os.path.exists(templates_path):
                 dir_util.copy_tree(templates_path, dest_path)
Beispiel #2
0
 def mount_templates(self, snapshot, path):
     utils.clear_path(path)
     for node in snapshot.nodes:
         try:
             node_obj = self.environment.system.nodes.get(name=node.name)
         except Node.DoesNotExist:
             pass
         else:
             dest_path = os.path.join(path, str(node_obj.pk))
             utils.clear_path(dest_path)
             templates_path = os.path.join(node.container.path, 'templates')
             if os.path.exists(templates_path):
                 dir_util.copy_tree(templates_path, dest_path)
Beispiel #3
0
    def compile_templates(self, node):
        templates_path = self.get_templates_path()

        # Remove all contents before adding new templates
        utils.clear_path(templates_path)

        # Walk through node templates, render, and save to instance templates.
        node_templates_path = node.get_templates_path()
        if os.path.exists(node_templates_path):
            for dirpath, dirnames, filenames in os.walk(node_templates_path):
                rel_dir = os.path.relpath(dirpath, node_templates_path)
                for file_name in filenames:
                    self.compile_template(os.path.normpath(os.path.join(
                        rel_dir, file_name)), node_templates_path,
                        templates_path, node)
Beispiel #4
0
    def start(self, snapshot):
        self.snapshot = snapshot
        self.snapshot.run_build_plugins(self)
        self.snapshot.run_pre_deploy_plugins(self)
        template_path = os.path.join(settings.STRETCH_CACHE_DIR, 'templates',
                                     str(self.environment.pk))

        with self.snapshot.mount_templates(template_path):
            yield

        utils.clear_path(template_path)
        self.snapshot.run_post_deploy_plugins(self)
        utils.delete_path(self.snapshot.path)
        if self.existing_snapshot:
            utils.delete_path(self.existing_snapshot.path)
Beispiel #5
0
    def start(self, snapshot):
        self.snapshot = snapshot
        self.snapshot.run_build_plugins(self)
        self.snapshot.run_pre_deploy_plugins(self)
        template_path = os.path.join(settings.STRETCH_CACHE_DIR, 'templates',
                                     str(self.environment.pk))

        with self.snapshot.mount_templates(template_path):
            yield

        utils.clear_path(template_path)
        self.snapshot.run_post_deploy_plugins(self)
        utils.delete_path(self.snapshot.path)
        if self.existing_snapshot:
            utils.delete_path(self.existing_snapshot.path)
Beispiel #6
0
    def compile_templates(self, node):
        templates_path = self.get_templates_path()

        # Remove all contents before adding new templates
        utils.clear_path(templates_path)

        # Walk through node templates, render, and save to instance templates.
        node_templates_path = node.get_templates_path()
        if os.path.exists(node_templates_path):
            for dirpath, dirnames, filenames in os.walk(node_templates_path):
                rel_dir = os.path.relpath(dirpath, node_templates_path)
                for file_name in filenames:
                    self.compile_template(
                        os.path.normpath(os.path.join(rel_dir, file_name)),
                        node_templates_path, templates_path, node)
Beispiel #7
0
    def pull(self, args):
        # Pull image
        if not args['app_path']:
            utils.run_cmd(['docker', 'pull', args['image']])

        # Prepare to pull templates
        templates_path = self.get_templates_path()
        src = 'salt://templates/%s/%s' % (args['env_id'], self.data['_id'])

        # Remove all contents before adding new templates
        utils.clear_path(templates_path)

        # Pull templates
        caller_client().function('cp.get_dir', src, templates_path)

        node.update(args)
Beispiel #8
0
    def pull(self, args):
        # Pull image
        if not args['app_path']:
            utils.run_cmd(['docker', 'pull', args['image']])

        # Prepare to pull templates
        templates_path = self.get_templates_path()
        src = 'salt://templates/%s/%s' % (args['env_id'], self.data['_id'])

        # Remove all contents before adding new templates
        utils.clear_path(templates_path)

        # Pull templates
        caller_client().function('cp.get_dir', src, templates_path)

        node.update(args)
Beispiel #9
0
    def create(cls, path, system):
        """
        Creates, and processes, and archives a release. Emits a
        `release_created` signal upon completion.

        :Parameters:
          - `path`: the path to create the release from.
          - `system`: the system to associate the release with.
        """
        release = cls(
            name=utils.generate_memorable_name(),
            sha=utils.generate_random_hex(28),
            system=system
        )

        # Copy to temporary directory
        tmp_path = utils.temp_dir(path)

        # Create snapshot
        snapshot = parser.Snapshot(tmp_path)

        # Build release from snapshot
        # Archive the release
        utils.clear_path(release.data_dir)

        # Tar release buffer
        tar_path = os.path.join(release.data_dir, cls.archive_name)
        tar_file = tarfile.open(tar_path, 'w:gz')
        tar_file.add(tmp_path, '/')
        tar_file.close()

        # Build docker images
        snapshot.build_and_push(release, system)

        # Delete snapshot buffer
        utils.delete_path(tmp_path)

        # Build finished
        release.save()
        signals.release_created.send(sender=release)
        return release
Beispiel #10
0
    def create(cls, path, system):
        """
        Creates, and processes, and archives a release. Emits a
        `release_created` signal upon completion.

        :Parameters:
          - `path`: the path to create the release from.
          - `system`: the system to associate the release with.
        """
        release = cls(name=utils.generate_memorable_name(),
                      sha=utils.generate_random_hex(28),
                      system=system)

        # Copy to temporary directory
        tmp_path = utils.temp_dir(path)

        # Create snapshot
        snapshot = parser.Snapshot(tmp_path)

        # Build release from snapshot
        # Archive the release
        utils.clear_path(release.data_dir)

        # Tar release buffer
        tar_path = os.path.join(release.data_dir, cls.archive_name)
        tar_file = tarfile.open(tar_path, 'w:gz')
        tar_file.add(tmp_path, '/')
        tar_file.close()

        # Build docker images
        snapshot.build_and_push(release, system)

        # Delete snapshot buffer
        utils.delete_path(tmp_path)

        # Build finished
        release.save()
        signals.release_created.send(sender=release)
        return release