def put_config_file(ctx, filepath, considered_files): if filepath in considered_files: return project_dir = ctx.options['project_dir'] dst = filepath.parent.relative_to(project_dir) if filepath.is_symlink() and not ctx.options['resolve_symlinks']: if locates_in(filepath, project_dir): ctx.storage.put_file(filepath, dst, namespace='config', follow_symlinks=False) considered_files.add(filepath) filepath = filepath.resolve() if filepath in considered_files: return if locates_in(filepath, project_dir): ctx.storage.put_file(filepath, dst, namespace='config') considered_files.add(filepath)
def put_config_file(ctx, filepath, considered_files): if filepath in considered_files: return project_dir = ctx.options["project_dir"] dst = filepath.parent.relative_to(project_dir) if filepath.is_symlink() and not ctx.options["resolve_symlinks"]: if locates_in(filepath, project_dir): ctx.storage.put_file( filepath, dst, namespace="config", follow_symlinks=False ) considered_files.add(filepath) filepath = filepath.resolve() if filepath in considered_files: return if locates_in(filepath, project_dir): ctx.storage.put_file(filepath, dst, namespace="config") considered_files.add(filepath)
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
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