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 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_context( 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, build_context, destination, 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 = BuildContextConfig.from_dict( rhea.read(build_context)) except (RheaError, 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, params=params, log=False) try: run_spec = get_specification(specification.generate_run_data()) run_spec.apply_params(params=specification.config.params) run_spec.apply_context() except PolyaxonSchemaError: Printer.print_error( "Could not run this polyaxonfile locally, " "a context is required to resolve it dependencies.") sys.exit(1) build_context = run_spec.build_context generator = DockerFileGenerator(build_context=build_context, destination=destination or ".") generator.create() Printer.print_success("Dockerfile was generated: `{}`".format( generator.dockerfile_path))
def run( ctx, project, polyaxonfile, name, tags, description, upload, log, local, conda_env, params, profile, nocache, ): """Run polyaxonfile specification. Examples: \b ```bash $ polyaxon run -f file -f file_override ... ``` Upload before running \b ```bash $ polyaxon run -f file -u ``` Run and set description and tags for this run \b ```bash $ polyaxon run -f file -u --description="Description of the current run" --tags="foo, bar, moo" ``` Run and set a unique name for this run \b ```bash polyaxon run --name=foo ``` Run for a specific project \b ```bash $ polyaxon run -p project1 -f file.yaml ``` Run with updated params \b ```bash $ polyaxon run -p project1 -f file.yaml -P param1=234.2 -P param2=relu ``` """ specification = check_polyaxonfile(polyaxonfile, params=params, profile=profile, nocache=nocache, log=False) owner, project_name = get_project_or_local(project) tags = validate_tags(tags) if local: try: run_spec = get_specification(specification.generate_run_data()) run_spec.apply_context() except PolyaxonSchemaError: Printer.print_error( "Could not run this polyaxonfile locally, " "a context is required to resolve it dependencies.") sys.exit(1) if conda_env: conda_run( ctx=ctx, name=name, owner=owner, project_name=project_name, description=description, tags=tags, specification=run_spec, log=log, conda_env=conda_env, ) else: docker_run( ctx=ctx, name=name, owner=owner, project_name=project_name, description=description, tags=tags, specification=run_spec, log=log, ) else: platform_run( ctx=ctx, name=name, owner=owner, project_name=project_name, description=description, tags=tags, specification=specification, upload=upload, log=log, can_upload=all([upload, project]), )