Пример #1
0
def test_pathset():
    ps = PathSet()

    x = "/ham"
    assert x not in ps
    ps.add(x)
    assert x in ps

    x = Path("/spam")
    assert x not in ps
    ps.add(x)
    assert x in ps
Пример #2
0
def test_pathset():
    ps = PathSet()

    x = '/ham'
    assert x not in ps
    ps.add(x)
    assert x in ps

    x = Path('/spam')
    assert x not in ps
    ps.add(x)
    assert x in ps
Пример #3
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
Пример #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'
                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