Docker Utilities
This module contains utility functions for interacting with docker objects (images/containers) in the context of executing or securing a train.
- train_lib.docker_util.docker_ops.add_archive(img: str, archive: _io.BytesIO, path: str)[source]
Adds a given tar archive to a given docker image at the specified path :param img: identifier of the image <repository>:<tag> :param archive: tar archive to be added to the image :param path: path at which the tar archive will be added inside the image
- Returns
- train_lib.docker_util.docker_ops.extract_archive(img: str, extract_path: str) tarfile.TarFile[source]
Extracts a file or folder at the given path from the given docker image
- Parameters
img – identifier of the img to extract the file from
extract_path – path of the file or directory to extract from the container
- Returns
tar archive containing the the extracted path
- train_lib.docker_util.docker_ops.extract_query_json(img: str, query_file_path: str = '/opt/pht_train/query.json') dict[source]
Extract query.json file from the specified image and return it as a dictionary :param img: docker image identifier :param query_file_path: path of the query file inside the image :return: dictionary containing the security values stored inside the train:config.json
- train_lib.docker_util.docker_ops.extract_train_config(img: str, config_path: str = '/opt/train_config.json') dict[source]
Extract the train configuration json from the specified image and return it as a dictionary :param img: docker image identifier :param config_path: path of the config file inside the image :return: dictionary containing the security values stored inside the train:config.json
- train_lib.docker_util.docker_ops.files_from_archive(tar_archive: tarfile.TarFile)[source]
Extracts only the actual files from the given tarfile
- Parameters
tar_archive – the tar archive from which to extract the files
- Returns
List of file object extracted from the tar archive
- train_lib.docker_util.docker_ops.result_files_from_archive(tar_archive: tarfile.TarFile)[source]
Extracts the result files from the given archive returning the files as well as the director structure contained in the tar archive for later reconstruction
- Parameters
tar_archive – the tar archive from which to extract the files
- Returns
List of file object extracted from the tar archive