def copy_resource(container, resource, local_filename, contents_only=True): """ Copies a resource from a container to a compressed tarball and downloads it. :param container: Container name or id. :type container: unicode :param resource: Name of resource to copy. :type resource: unicode :param local_filename: Path to store the tarball locally. :type local_filename: unicode :param contents_only: In case ``resource`` is a directory, put all contents at the root of the tar file. If this is set to ``False``, the directory itself will be at the root instead. :type contents_only: bool """ with temp_dir() as remote_tmp: base_name = os.path.basename(resource) copy_path = posixpath.join(remote_tmp, 'copy_tmp') run(mkdir(copy_path, check_if_exists=True)) remote_name = posixpath.join(copy_path, base_name) archive_name = 'container_{0}.tar.gz'.format(container) archive_path = posixpath.join(remote_tmp, archive_name) run('docker cp {0}:{1} {2}'.format(container, resource, copy_path), shell=False) if contents_only and is_directory(remote_name): src_dir = remote_name src_files = '*' else: src_dir = copy_path src_files = base_name with cd(src_dir): run(targz(archive_path, src_files)) get(archive_path, local_filename)
def _copy_resource(resource): default_dest_path = generic_path if generic_path is not None else resource dest_path = directories.get(resource, default_dest_path).strip(posixpath.sep) head, tail = posixpath.split(dest_path) rel_path = posixpath.join(storage_dir, head) run(mkdir(rel_path, check_if_exists=True)) run('docker cp {0}:{1} {2}'.format(src_container, resource, rel_path), shell=False)
arch='amd64', os='debian-9', org='ursalab', title='Ursabot Python 3.7', steps=[ ADD(docker_assets / 'requirements-ursabot.txt'), RUN(pip(files=['requirements-ursabot.txt'])) ]) images.append(ursabot) # none of the above images are usable as buildbot workers until We install, # configure and set it as the command of the docker image worker_command = 'twistd --pidfile= -ny buildbot.tac' worker_steps = [ RUN(pip('buildbot-worker')), RUN(mkdir('/buildbot')), ADD(docker_assets / 'buildbot.tac', '/buildbot/buildbot.tac'), WORKDIR('/buildbot') ] # create worker images and add them to the list of arrow images worker_images = [] for image in images: # exec form is required for conda images becase of the bash entrypoint cmd = [worker_command] if image.variant == 'conda' else worker_command steps = worker_steps + [CMD(cmd)] worker = DockerImage(image.name, base=image, tag='worker', steps=steps) worker_images.append(worker) images.extend(worker_images)