Пример #1
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
Пример #2
0
def store_config(ctx):
    considered_files = PathSet()
    for compose_file in ctx.config_details.config_files:
        store_config_file(ctx, compose_file, considered_files)

    store_build_contexts(ctx)

    env_file = ctx.options['project_dir'] / '.env'
    if env_file.exists():
        put_config_file(ctx, env_file, considered_files)
Пример #3
0
def store_volumes(ctx):
    volume_index = ctx.manifest['volumes'] = OrderedDict()
    volume_index['project'] = {}
    volume_index['mounted'] = []
    volume_index['services'] = {}
    mounted_paths = PathSet()

    if 'volumes' in ctx.options['scopes']:
        store_project_volumes(ctx)
    store_services_volumes(ctx, mounted_paths)
    if 'mounted' in ctx.options['scopes']:
        store_mounted_volumes(ctx, mounted_paths)
Пример #4
0
def store_volumes(ctx):
    volume_index = ctx.manifest["volumes"] = OrderedDict()
    volume_index["project"] = {}
    volume_index["mounted"] = []
    volume_index["services"] = {}
    mounted_paths = PathSet()

    if "volumes" in ctx.options["scopes"]:
        store_project_volumes(ctx)
    store_services_volumes(ctx, mounted_paths)
    if "mounted" in ctx.options["scopes"]:
        store_mounted_volumes(ctx, mounted_paths)
Пример #5
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
Пример #6
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
Пример #7
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