Example #1
0
 def _make_name(ctx):
     isodate = ctx.manifest['meta']['invocation_time']
     return ctx.options['target_pattern'].format(
         date=isodate[:10],
         isodate=isodate,
         host=ctx.manifest['meta']['host'],
         name=ctx.options['project_name'],
         path_hash=hash_string(ctx.options['project_dir']),
         time=isodate[11:16])
Example #2
0
 def _make_name(ctx):
     isodate = ctx.manifest['meta']['invocation_time']
     return ctx.options['target_pattern'].format(
         date=isodate[:10],
         isodate=isodate,
         host=ctx.manifest['meta']['host'],
         name=ctx.options['project_name'],
         path_hash=hash_string(ctx.options['project_dir']),
         time=isodate[11:16]
     )
Example #3
0
 def _make_name(ctx):
     isodate = ctx.manifest["meta"]["invocation_time"]
     return ctx.options["target_pattern"].format(
         date=isodate[:10],
         isodate=isodate,
         host=ctx.manifest["meta"]["host"],
         name=ctx.options["project_name"],
         path_hash=hash_string(ctx.options["project_dir"]),
         time=isodate[11:16],
     )
Example #4
0
def store_services_volumes(ctx, mounted_paths):
    for service in ctx.project.services:
        if service.name not in ctx.options['services']:
            continue

        internal_volumes = PathSet()
        considered_paths = PathSet()

        # figure out what should be saved
        for volume in service.options.get('volumes', ()):
            if volume.external in ctx.project.volumes.volumes:
                pass
            elif volume.external is None:
                internal_volumes.add(volume.internal)
            elif locates_in(volume.external, ctx.options['project_dir']):
                mounted_paths.add(volume.external)
            considered_paths.add(volume.internal)

        # collect extra volumes from service image
        try:
            image = service.image()
        except NoSuchImageError as e:
            log.critical('%s: %s' % (service.name, e))
        else:
            image_volumes = image.get('Config', {})['Volumes'] or ()
            for volume in image_volumes:
                if volume not in considered_paths:  # not if encountered before
                    internal_volumes.add(volume)

        if 'volumes' in ctx.options['scopes']:
            index = ctx.manifest['volumes']['services'][service.name] = {}
            container = get_container_for_service(service)
            if container is None:
                log.critical('No container for service %s found.' %
                             service.name)
                continue
            for path in internal_volumes:
                archive_name = hash_string(service.name.upper() +
                                           path) + '.tar'
                bits, stat = ctx.project.client.get_archive(container.id, path)
                if hasattr(
                        bits, 'stream'
                ):  # TODO: obsolete with docker-compose>1.19.0 (e.g. docker-py>=3.0.0)
                    bits = bits.stream
                ctx.storage.write_file(bits,
                                       archive_name,
                                       namespace='volumes/services')
                index[path] = archive_name
Example #5
0
def store_services_volumes(ctx, mounted_paths):
    for service in ctx.project.services:
        if service.name not in ctx.options['services']:
            continue

        internal_volumes = PathSet()
        considered_paths = PathSet()

        # figure out what should be saved
        for volume in service.options.get('volumes', ()):
            if volume.external in ctx.project.volumes.volumes:
                pass
            elif volume.external is None:
                internal_volumes.add(volume.internal)
            elif locates_in(volume.external, ctx.options['project_dir']):
                mounted_paths.add(volume.external)
            considered_paths.add(volume.internal)

        # collect extra volumes from service image
        try:
            image = service.image()
        except NoSuchImageError as e:
            log.critical('%s: %s' % (service.name, e))
        else:
            image_volumes = image.get('Config', {})['Volumes'] or ()
            for volume in image_volumes:
                if volume not in considered_paths:  # not if encountered before
                    internal_volumes.add(volume)

        if 'volumes' in ctx.options['scopes']:
            index = ctx.manifest['volumes']['services'][service.name] = {}
            container = get_container_for_service(service)
            if container is None:
                log.critical('No container for service %s found.' % service.name)
                continue
            for path in internal_volumes:
                archive_name = hash_string(service.name.upper() + path) + '.tar'
                response, stat = ctx.project.client.get_archive(container.id, path)
                ctx.storage.write_file(response.stream, archive_name, namespace='volumes/services')
                index[path] = archive_name