def bind_library(library_source_dir, library_destination_dir): source_path_directory = Path(library_source_dir).resolve() destination_path_directory = Path( library_destination_dir).resolve() / source_path_directory.name _unmount_and_rm_directory(destination_path_directory) os.makedirs(destination_path_directory) call_command('bindfs --delete-deny {} {}'.format( source_path_directory, destination_path_directory), quiet=True)
def _unmount_and_rm_directory(directory): if platform.system() == 'Darwin': call_command( 'mount -t osxfuse | grep "{}" | awk -F " " \'{{print "umount " $3}}\'| bash' .format(directory), quiet=True) elif platform.system() == 'Linux': call_command( 'mount -l -t fuse | grep "{}" | awk -F " " \'{{print "fusermount -u " $3}}\'| bash' .format(directory), quiet=True) shutil.rmtree(directory, ignore_errors=True)
def docker_clean(hard=False): call_command(['docker', 'image', 'prune', '-f']) call_command(['docker', 'container', 'prune', '-f']) if hard: call_command(['docker', 'system', 'prune', '-af']) if get_command_output('docker volume ls -q'): call_command('docker volume rm $(docker volume ls -q)')
def copy_containers_dirs(project_name, containers_dir_to_copy=None, containers=None): for container_name, _, host_dir in containers_dir_to_copy: if not containers or container_name in containers: shutil.rmtree(Path.cwd() / host_dir, ignore_errors=True) os.makedirs(Path.cwd() / host_dir) for container_name, container_dir, host_dir in containers_dir_to_copy: if not containers or container_name in containers: call_command([ 'docker', 'run', '-v', '{}:/copy_tmp'.format(Path.cwd() / host_dir), '-u', str(os.getuid()), '{}_{}'.format(project_name, container_name), "cp -rT {}/ /copy_tmp/".format(container_dir) ])
def compose_build(project_name, compose_files, containers=None, containers_dir_to_copy=None): for container_name, _, host_dir in containers_dir_to_copy: if not containers or container_name in containers: shutil.rmtree(Path.cwd() / host_dir, ignore_errors=True) os.makedirs(Path.cwd() / host_dir) _call_compose_command(project_name, compose_files, 'build', containers) for container_name, container_dir, host_dir in containers_dir_to_copy: if not containers or container_name in containers: call_command([ 'docker', 'run', '-v', '{}:/copy_tmp'.format(Path.cwd() / host_dir), '{}_{}'.format(project_name, container_name), "cp -r {}/* /copy_tmp/".format(container_dir) ])
def tag(source_image, target_image): call_command(['docker', 'tag', source_image, target_image])
def login_client(username, password, registry): call_command(['docker', 'login', '--username', username, '--password', password, registry])
def push_image(repository, tag): call_command(['docker', 'push', '{}:{}'.format(repository, tag)])
def sh(command): """ Runs SH command. """ call_command(command)
def compose_kill_all(): if get_command_output('docker ps -q'): call_command('docker kill $(docker ps -q)')