def file(file_context, filepath, copy_path, track): """Create auth context.""" from polyaxon.init.file import create_file_lineage from polyaxon.utils.hashing import hash_value try: file_context = V1FileType.from_dict(ConfigSpec.read_from(file_context)) except (PolyaxonSchemaError, ValidationError) as e: Printer.print_error("received a non valid file context.") Printer.print_error("Error message: {}.".format(e)) sys.exit(1) filepath = os.path.join(filepath, file_context.filename) check_or_create_path(filepath, is_dir=False) # Clean any previous file on that path if os.path.exists(filepath): os.remove(filepath) with open(filepath, "w") as generated_file: generated_file.write(file_context.content) if file_context.chmod: subprocess.check_call(["chmod", file_context.chmod, filepath]) if copy_path: filepath = copy_file(filepath, copy_path) if track: create_file_lineage( filepath=filepath, summary={"hash": hash_value(file_context.content)}, kind=file_context.kind, ) Printer.print_success("File is initialized, path: `{}`".format(filepath))
def generate(polyaxonfile, python_module, build_context, destination, copy_path, params): """Generate a dockerfile given the polyaxonfile.""" if all([polyaxonfile, build_context]): Printer.print_error( "Only a polyaxonfile or a build context option is required.") sys.exit(1) if build_context: try: build_context = [ V1DockerfileType.from_dict(ConfigSpec.read_from(build_context)) ] except (PolyaxonSchemaError, ValidationError) as e: Printer.print_error("received a non valid build context.") Printer.print_error("Error message: {}.".format(e)) sys.exit(1) else: specification = check_polyaxonfile( polyaxonfile=polyaxonfile, python_module=python_module, params=params, log=False, ) try: compiled_operation = specification.compile_operation() compiled_operation.apply_params(params=specification.config.params) compiled_operation = CompiledOperationSpecification.apply_operation_contexts( compiled_operation) except PolyaxonSchemaError: Printer.print_error( "Could not run this polyaxonfile locally, " "a context is required to resolve it dependencies.") sys.exit(1) build_context = compiled_operation.init_dockerfiles for init_dockerfile in build_context: generator = DockerFileGenerator(build_context=init_dockerfile, destination=destination or ".") generator.create() Printer.print_success("Dockerfile was generated, path: `{}`".format( generator.dockerfile_path)) if copy_path: copy_file(generator.dockerfile_path, copy_path)
def generate(polyaxonfile, python_module, build_context, destination, copy_path, params, track): """Generate a dockerfile given the polyaxonfile.""" from polyaxon.init.dockerfile import create_dockerfile_lineage from polyaxon.utils.hashing import hash_value if all([polyaxonfile, build_context]): Printer.print_error( "Only a polyaxonfile or a build context option is required.") sys.exit(1) if build_context: try: build_context = [ V1DockerfileType.from_dict(ConfigSpec.read_from(build_context)) ] except (PolyaxonSchemaError, ValidationError) as e: Printer.print_error("received a non valid build context.") Printer.print_error("Error message: {}.".format(e)) sys.exit(1) else: specification = check_polyaxonfile( polyaxonfile=polyaxonfile, python_module=python_module, params=params, verbose=False, ) try: compiled_operation = OperationSpecification.compile_operation( specification) compiled_operation.apply_params(params=specification.config.params) compiled_operation = (CompiledOperationSpecification. apply_operation_contexts(compiled_operation)) except PolyaxonSchemaError: Printer.print_error( "Could not run this polyaxonfile locally, " "a context is required to resolve it dependencies.") sys.exit(1) build_context = compiled_operation.init_dockerfiles for init_dockerfile in build_context: generator = DockerFileGenerator(build_context=init_dockerfile, destination=destination or ".") generator.create() Printer.print_success("Dockerfile was generated, path: `{}`".format( generator.dockerfile_path)) dockerfile_path = generator.dockerfile_path if copy_path: dockerfile_path = copy_file(dockerfile_path, copy_path) if track: hash_content = hash_value(init_dockerfile.to_dict()) create_dockerfile_lineage(dockerfile_path, summary={"hash": hash_content})
def upload_file(self, filename, path_to, use_basename=True, **kwargs): copy_file(filename=filename, path_to=path_to, use_basename=use_basename)