2022-08-11 09:24:17 -07:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
# __deploy_in_single_file_1_start__
|
2022-08-12 13:41:08 -07:00
|
|
|
from starlette.requests import Request
|
|
|
|
|
2022-08-11 09:24:17 -07:00
|
|
|
import ray
|
|
|
|
from ray import serve
|
|
|
|
|
|
|
|
|
|
|
|
@serve.deployment
|
2022-08-12 13:41:08 -07:00
|
|
|
def my_func(request: Request) -> str:
|
2022-08-11 09:24:17 -07:00
|
|
|
return "hello"
|
|
|
|
|
|
|
|
|
|
|
|
serve.run(my_func.bind())
|
|
|
|
# __deploy_in_single_file_1_end__
|
|
|
|
|
|
|
|
serve.shutdown()
|
|
|
|
ray.shutdown()
|
|
|
|
subprocess.check_output(["ray", "stop", "--force"])
|
|
|
|
subprocess.check_output(["ray", "start", "--head"])
|
|
|
|
|
|
|
|
# __deploy_in_single_file_2_start__
|
|
|
|
# This will connect to the running Ray cluster.
|
|
|
|
ray.init(address="auto", namespace="serve")
|
|
|
|
|
|
|
|
|
|
|
|
@serve.deployment
|
2022-08-12 13:41:08 -07:00
|
|
|
def my_func(request: Request) -> str:
|
2022-08-11 09:24:17 -07:00
|
|
|
return "hello"
|
|
|
|
|
|
|
|
|
|
|
|
serve.run(my_func.bind())
|
|
|
|
# __deploy_in_single_file_2_end__
|
|
|
|
|
|
|
|
serve.shutdown()
|
|
|
|
ray.shutdown()
|
|
|
|
subprocess.check_output(["ray", "stop", "--force"])
|
|
|
|
subprocess.check_output(["ray", "start", "--head"])
|
|
|
|
|
|
|
|
# __deploy_in_k8s_start__
|
|
|
|
# Connect to the running Ray cluster.
|
|
|
|
ray.init(address="auto")
|
|
|
|
|
|
|
|
|
|
|
|
@serve.deployment(route_prefix="/hello")
|
|
|
|
def hello(request):
|
|
|
|
return "hello world"
|
|
|
|
|
|
|
|
|
|
|
|
serve.run(hello.bind())
|
|
|
|
# __deploy_in_k8s_end__
|
|
|
|
|
|
|
|
subprocess.check_output(["ray", "stop", "--force"])
|