ComputeEngineService
A service hosted on a managed instance group on GCP Compute Engine.
Like all Services, this class configures itself across multiple Environments.
For more information see the official documentation.
Example Usage
Basic Usage
1import launchflow as lf
2
3service = lf.gcp.ComputeEngineService("my-service")
Custom Docker Image / Build Configuration
1import launchflow as lf
2
3service = lf.gcp.ComputeEngineService(
4 "my-service",
5 build_directory="my-service",
6 dockerfile="docker/Dockerfile",
7 build_ignore=["secrets"]
8)
Custom Machine Type
1import launchflow as lf
2
3service = lf.gcp.ComputeEngineService("my-serfice", machine_type="n1-standard-4")
Custom Health Check
1import launchflow as lf
2
3health_check = lf.gcp.HttpHealthCheck("my-health-check", port=80, request_path="/health")
4service = lf.gcp.ComputeEngineService("my-service", health_check=health_check)
initialization
Create a new Compute Engine Service.
Args:
name (str)
: The name of the service.build_directory (str)
: The directory to build the service from. This should be a relative path from the project root where yourlaunchflow.yaml
is defined.build_ignore (List[str])
: A list of files to ignore when building the service. This can be in the same syntax you would use for a.gitignore
.dockerfile (str)
: The Dockerfile to use for building the service. This should be a relative path from thebuild_directory
.machine_type (str)
: The machine type to use for the service. This should be one of the supported machine types. Defualts toe2-standard-2
.port (int)
: The port the service will listen on. Defaults to 80.region (str)
: The region to deploy the service to. If not provided, the service will be deployed to the default region for the environment.disk_size_gb (int)
: The size of the disk in GB. Defaults to 10.update_policy (UpdatePolicy)
: The update policy for the managed instance group. Defaults toUpdatePolicy(max_surge_fixed=3)
.health_check (Optional[Union[Literal[False], HttpHealthCheck]])
: The health check to use for the service. IfFalse
, no health check will be used. IfNone
, a default health check will be created that performs a health check on the/
endpoint every 5 seconds. Defaults toNone
.auto_healing_policy_initial_delay (int)
: The initial delay in seconds for the auto healing policy. Defaults to 360.autoscaler (Optional[Union[Literal[False], RegionalAutoscaler]])
: The autoscaler to use for the service. IfFalse
, no autoscaler will be used. IfNone
a default autoscaler will be used that scales between 1-10 VMs with a target CPU utilization of .75. Defaults toNone
.domain (Optional[str])
: The custom domain to use for the service. If not provided no load balancer will be setup in front of the managed instance group.deploy_timeout (timedelta)
: The amount of time to wait for the service to deploy before timing out. Defaults to 15 minutes.