@@ -446,16 +446,131 @@ class SecureHeadersConfig(BaseModel):
446446
447447
448448class DeploymentSettings (BaseSettings ):
449- """Settings for the pipeline deployment."""
449+ """Settings for the pipeline deployment.
450+
451+ Use these settings to fully customize all aspects of the uvicorn web server
452+ and ASGI web application that constitute the pipeline deployment.
453+
454+ Note that these settings are only available at the pipeline level.
455+
456+ The following customizations can be used to configure aspects that are
457+ framework-agnostic (i.e. not specific to a particular ASGI framework like
458+ FastAPI, Django, Flask, etc.):
459+
460+ * the ASGI application details: `app_title`, `app_description`,
461+ `app_version` and `app_kwargs`
462+ * the URL paths for the various built-in endpoints: `root_url_path`,
463+ `docs_url_path`, `redoc_url_path`, `invoke_url_path`, `health_url_path`,
464+ `info_url_path` and `metrics_url_path`
465+ * the location of dashboard static files can be provided to replace the
466+ default UI that is included with the deployment ASGI application:
467+ `dashboard_files_path`
468+ * the CORS configuration: `cors`
469+ * the secure headers configuration: `secure_headers`
470+ * the thread pool size: `thread_pool_size`
471+ * custom application startup and shutdown hooks: `startup_hook_source`,
472+ `shutdown_hook_source`, `startup_hook_kwargs` and `shutdown_hook_kwargs`
473+ * uvicorn server configuration: `uvicorn_host`, `uvicorn_port`,
474+ `uvicorn_workers` and `uvicorn_kwargs`
475+
476+ In addition to the above, the following advanced features can be used to
477+ customize the implementation-specific details of the deployment application:
478+
479+ * custom endpoints (e.g. custom metrics, custom health, etc.): `custom_endpoints`
480+ * custom middlewares (e.g. authentication, logging, etc.): `custom_middlewares`
481+ * application building extensions - these are pluggable components that can
482+ be used to add advanced framework-specific features like custom authentication,
483+ logging, metrics, etc.: `app_extensions`
484+
485+ Ultimately, if neither of the above are sufficient, the user can provide a
486+ custom implementations for the two core components that are used to build
487+ and run the deployment application itself:
488+
489+ * the deployment app runner - this is the component that is responsible for
490+ building and running the ASGI application. It is represented by the
491+ `zenml.deployers.server.BaseDeploymentAppRunner` class.
492+ See: `deployment_app_runner_source` and `deployment_app_runner_kwargs`
493+ * the deployment service - this is the component that is responsible for
494+ handling the business logic of the pipeline deployment. It is represented by
495+ the `zenml.deployers.server.BaseDeploymentService` class. See:
496+ `deployment_service_source` and `deployment_service_kwargs`
497+
498+ Both of these base classes or their existing implementations can be extended
499+ and provided as sources in the deployment settings to be loaded at runtime.
450500
451- # This settings is only available at the pipeline level
501+ Attributes:
502+ app_title: Title of the deployment application.
503+ app_description: Description of the deployment application.
504+ app_version: Version of the deployment application.
505+ app_kwargs: Arbitrary framework-specific keyword arguments to be passed
506+ to the deployment ASGI application constructor.
507+
508+ include_default_endpoints: Whether to include the default endpoints in
509+ the ASGI application.
510+ include_default_middleware: Whether to include the default middleware
511+ in the ASGI application.
512+
513+ root_url_path: Root URL path.
514+ docs_url_path: URL path for the OpenAPI documentation endpoint.
515+ redoc_url_path: URL path for the Redoc documentation endpoint.
516+ invoke_url_path: URL path for the invoke endpoint.
517+ health_url_path: URL path for the health check endpoint.
518+ info_url_path: URL path for the info endpoint.
519+ metrics_url_path: URL path for the metrics endpoint.
520+ dashboard_files_path: Path where the dashboard static files are located.
521+ This can be used to replace the default UI that is included with the
522+ deployment ASGI application. The referenced directory must contain
523+ at a minimum an `index.html` file and a `assets` directory. The path
524+ can be absolute or relative to the root of the repository
525+ initialized with `zenml init` or relative to the current working
526+ directory.
527+
528+ cors: Configuration for CORS.
529+ secure_headers: Configuration for secure headers.
530+ thread_pool_size: Size of the thread pool for the ASGI application.
531+
532+ startup_hook: Custom startup hook for the ASGI application.
533+ shutdown_hook: Custom shutdown hook for the ASGI application.
534+ startup_hook_kwargs: Keyword arguments for the startup hook.
535+ shutdown_hook_kwargs: Keyword arguments for the shutdown hook.
536+
537+ custom_endpoints: Custom endpoints for the ASGI application. See the
538+ `EndpointSpec` class for more details.
539+ custom_middlewares: Custom middlewares for the ASGI application. See the
540+ `MiddlewareSpec` class for more details.
541+ app_extensions: App extensions used to build the ASGI application. See
542+ the `AppExtensionSpec` class for more details.
543+
544+ uvicorn_host: Host of the uvicorn server.
545+ uvicorn_port: Port of the uvicorn server.
546+ uvicorn_workers: Number of workers for the uvicorn server.
547+ log_level: Log level for the deployment application.
548+ uvicorn_kwargs: Keyword arguments for the uvicorn server.
549+
550+ deployment_app_runner_source: Source of the deployment app runner. Must
551+ point to a class that extends the
552+ `zenml.deployers.server.BaseDeploymentAppRunner` class.
553+ deployment_app_runner_kwargs: Keyword arguments for the deployment app
554+ runner. These will be passed to the constructor of the deployment app
555+ runner class.
556+ deployment_service_source: Source of the deployment service. Must point
557+ to a class that extends the
558+ `zenml.deployers.server.BaseDeploymentService` class.
559+ deployment_service_kwargs: Keyword arguments for the deployment service.
560+ These will be passed to the constructor of the deployment service class.
561+ """
562+
563+ # These settings are only available at the pipeline level
452564 LEVEL : ClassVar [ConfigurationLevel ] = ConfigurationLevel .PIPELINE
453565
454566 app_title : Optional [str ] = None
455567 app_description : Optional [str ] = None
456568 app_version : Optional [str ] = None
457569 app_kwargs : Dict [str , Any ] = {}
458570
571+ include_default_endpoints : bool = True
572+ include_default_middleware : bool = True
573+
459574 root_url_path : str = DEFAULT_DEPLOYMENT_APP_ROOT_URL_PATH
460575 docs_url_path : str = DEFAULT_DEPLOYMENT_APP_DOCS_URL_PATH
461576 redoc_url_path : str = DEFAULT_DEPLOYMENT_APP_REDOC_URL_PATH
@@ -464,15 +579,15 @@ class DeploymentSettings(BaseSettings):
464579 info_url_path : str = DEFAULT_DEPLOYMENT_APP_INFO_URL_PATH
465580 metrics_url_path : str = DEFAULT_DEPLOYMENT_APP_METRICS_URL_PATH
466581
467- dashboard_files_path : str = ""
582+ dashboard_files_path : Optional [ str ] = None
468583
469584 cors : CORSConfig = CORSConfig ()
470585 secure_headers : SecureHeadersConfig = SecureHeadersConfig ()
471586
472587 thread_pool_size : int = DEFAULT_DEPLOYMENT_APP_THREAD_POOL_SIZE
473588
474- startup_hook_source : Optional [SourceOrObjectField ] = None
475- shutdown_hook_source : Optional [SourceOrObjectField ] = None
589+ startup_hook : Optional [SourceOrObjectField ] = None
590+ shutdown_hook : Optional [SourceOrObjectField ] = None
476591 startup_hook_kwargs : Dict [str , Any ] = {}
477592 shutdown_hook_kwargs : Dict [str , Any ] = {}
478593
@@ -483,12 +598,6 @@ class DeploymentSettings(BaseSettings):
483598 # Pluggable app extensions for advanced features
484599 app_extensions : Optional [List [AppExtensionSpec ]] = None
485600
486- # Include default endpoints in the deployment application
487- include_default_endpoints : bool = True
488-
489- # Include default middleware in the deployment application
490- include_default_middleware : bool = True
491-
492601 uvicorn_host : str = "0.0.0.0"
493602 uvicorn_port : int = 8000
494603 uvicorn_workers : int = 1
@@ -503,10 +612,10 @@ class DeploymentSettings(BaseSettings):
503612
504613 def load_sources (self ) -> None :
505614 """Load source string into callable."""
506- if self .startup_hook_source is not None :
507- self .startup_hook_source .load ()
508- if self .shutdown_hook_source is not None :
509- self .shutdown_hook_source .load ()
615+ if self .startup_hook is not None :
616+ self .startup_hook .load ()
617+ if self .shutdown_hook is not None :
618+ self .shutdown_hook .load ()
510619 if self .deployment_app_runner_source is not None :
511620 self .deployment_app_runner_source .load ()
512621 if self .deployment_service_source is not None :
0 commit comments