def check_for_docker_compose(self): # Deployment on docker compose requires Docker & Docker Compose to be installed if not self.docker.check(): raise PolyaxonException("Docker is required to run this command.") Printer.print_success("Docker is installed") if not self.compose.check(): raise PolyaxonException("Docker Compose is required to run this command.") Printer.print_success("Docker Compose is installed") # Check that .polyaxon/.compose is set and up-to date if ComposeConfigManager.is_initialized(): Printer.print_success("Docker Compose deployment is initialised.") return True
def check_for_kubernetes(self): # Deployment on k8s requires helm & kubectl to be installed if not self.kubectl.check(): raise PolyaxonException("kubectl is required to run this command.") Printer.print_success("kubectl is installed") if not self.helm.check(): raise PolyaxonException("helm is required to run this command.") Printer.print_success("helm is installed") # Check that polyaxon/polyaxon is set and up-to date self.helm.execute( args=["repo", "add", "polyaxon", "https://charts.polyaxon.com"]) self.helm.execute(args=["repo", "update"]) return True
def check(self): """Add platform specific checks""" if not self.is_valid: raise PolyaxonException( "Deployment type `{}` not supported".format( self.deployment_type)) check = False if self.is_kubernetes: check = self.check_for_kubernetes() elif self.is_docker_compose: check = self.check_for_docker_compose() elif self.is_docker: check = self.check_for_docker() elif self.is_heroku: check = self.check_for_heroku() if not check: raise PolyaxonException("Deployment `{}` is not valid".format( self.deployment_type))
def teardown(self, hooks=True): """Teardown Polyaxon.""" if not self.is_valid: raise PolyaxonException( "Deployment type `{}` not supported".format( self.deployment_type)) if self.is_kubernetes: self.teardown_on_kubernetes(hooks=hooks) elif self.is_docker_compose: self.teardown_on_docker_compose() elif self.is_docker: self.teardown_on_docker(hooks=hooks) elif self.is_heroku: self.teardown_on_heroku(hooks=hooks)
def upgrade(self): """Upgrade deployment.""" if not self.is_valid: raise PolyaxonException( "Deployment type `{}` not supported".format( self.deployment_type)) if self.is_kubernetes: self.upgrade_on_kubernetes() elif self.is_docker_compose: self.upgrade_on_docker_compose() elif self.is_docker: self.upgrade_on_docker() elif self.is_heroku: self.upgrade_on_heroku()
def install(self): """Install polyaxon using the current config to the correct platform.""" if not self.is_valid: raise PolyaxonException( "Deployment type `{}` not supported".format( self.deployment_type)) if self.is_kubernetes: self.install_on_kubernetes() elif self.is_docker_compose: self.install_on_docker_compose() elif self.is_docker: self.install_on_docker() elif self.is_heroku: self.install_on_heroku()
def _run(ctx, name, owner, project_name, description, tags, specification, log): docker = DockerOperator() if not docker.check(): raise PolyaxonException("Docker is required to run this command.") # Create Build project = "{}.{}".format(owner, project_name) build_job = Run(project=project) specification = CompiledOperationSpecification.apply_operation_contexts( specification) content = specification.to_dict(dump=True) build_job.create(name=name, description=description, tags=tags, content=content) image = _create_docker_build(build_job, specification, project) experiment = Run(project=project) experiment.create(name=name, tags=tags, description=description, content=content) cmd_args = ["run", "--rm"] data_paths, bind_mounts = _get_data_bind_mounts(specification.data_refs) for key, value in _get_env_vars( project=project, experiment_id=experiment.experiment_id, params=specification.params, data_paths=data_paths, ): cmd_args += ["-e", "{key}={value}".format(key=key, value=value)] cmd_args += _get_config_volume() cmd_args += _get_data_volumes(bind_mounts) cmd_args += [image] # Add cmd.run _, args = specification.container.get_container_command_args() for arg in args: cmd_args += arg try: print(cmd_args) docker.execute(cmd_args, stream=True) except Exception as e: handle_cli_error(e, message="Could start local run.") sys.exit(1)
def _run(ctx, name, owner, project_name, description, tags, specification, log, conda_env): conda = CondaOperator() # cmd = CmdOperator() if not conda.check(): raise PolyaxonException("Conda is required to run this command.") envs = conda.execute(["env", "list", "--json"], is_json=True) env_names = [os.path.basename(env) for env in envs["envs"]] project_env_name = _get_conda_env_name(conda_env) if project_env_name not in env_names: click.echo("Creating conda environment {}".format(project_env_name)) conda.execute( ["env", "create", "-n", project_env_name, "--file", conda_env], stream=True) cmd_bash, cmd_args = specification.run.get_container_cmd() cmd_args = ["source activate {}".format(project_env_name)] + cmd_args subprocess.Popen(cmd_bash + [" && ".join(cmd_args)], close_fds=True)
def proxy(component, path, root): """Create api proxy.""" from polyaxon.proxies.generators import ( generate_api_conf, generate_gateway_conf, generate_streams_conf, ) from polyaxon.settings import set_proxies_config if not root: root = os.path.abspath(".") set_proxies_config() if component == "api": generate_api_conf(path=path, root=root) elif component == "streams": generate_streams_conf(path=path, root=root) elif component == "gateway": generate_gateway_conf(path=path, root=root) else: raise PolyaxonException("Component {} is not recognized".format(component))
def check_for_docker(self): if not self.docker.check(): raise PolyaxonException("Docker is required to run this command.") return True