Skip to content

Commit

Permalink
[SkyServe] add http server example (#2260)
Browse files Browse the repository at this point in the history
add http server example
  • Loading branch information
cblmemo committed Aug 13, 2023
1 parent 1fa6401 commit c56ae22
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
11 changes: 11 additions & 0 deletions sky/serve/examples/http_server/README.md
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
```
30 changes: 30 additions & 0 deletions sky/serve/examples/http_server/server.py
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()
12 changes: 12 additions & 0 deletions sky/serve/examples/http_server/task.yaml
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

0 comments on commit c56ae22

Please sign in to comment.