-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SkyServe] add http server example (#2260)
add http server example
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# HTTP Server example for SkyServe | ||
|
||
## Usage | ||
|
||
```bash | ||
# Run controller. | ||
python -m sky.serve.controller --task-yaml sky/serve/examples/http_server/task.yaml | ||
|
||
# Run redirector. | ||
python -m sky.serve.redirector --task-yaml sky/serve/examples/http_server/task.yaml | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import http.server | ||
import socketserver | ||
|
||
PORT = 8081 | ||
|
||
class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler): | ||
def do_GET(self): | ||
# Return 200 for all paths | ||
# Therefore, readiness_probe will return 200 at path '/health' | ||
self.send_response(200) | ||
self.send_header('Content-type', 'text/html') | ||
self.end_headers() | ||
html = ''' | ||
<html> | ||
<head> | ||
<title>SkyPilot Test Page</title> | ||
</head> | ||
<body> | ||
<h1>Hi, SkyPilot here!</h1> | ||
</body> | ||
</html> | ||
''' | ||
self.wfile.write(bytes(html, 'utf8')) | ||
return | ||
|
||
Handler = MyHttpRequestHandler | ||
|
||
with socketserver.TCPServer(("", PORT), Handler) as httpd: | ||
print("serving at port", PORT) | ||
httpd.serve_forever() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
resources: | ||
cloud: gcp | ||
ports: | ||
- 8081 | ||
|
||
workdir: . | ||
|
||
run: python3 server.py | ||
|
||
service: | ||
port: 8081 | ||
readiness_probe: /health |