Skip to content

Commit

Permalink
ci: add auto deployment for tabby live demo (TabbyML#2034)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsxiaoys authored May 2, 2024
1 parent 62db7bd commit cdddd28
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/deploy-demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Deploy to demo.tabbyml.com

on:
workflow_dispatch:
release:
types: [ published ]

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
env:
MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install Modal
run: |
python -m pip install --upgrade pip
pip install modal
- name: Write image version
run: |
TABBY_IMAGE=tabbyml/tabby:${GITHUB_REF_NAME#v}
echo image $TABBY_IMAGE
echo "TABBY_IMAGE=$TABBY_IMAGE" >> $GITHUB_ENV
- name: Deploy job
run: |
cd experimental/demo modal deploy app.py
64 changes: 64 additions & 0 deletions experimental/demo/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import os
from modal import Image, Stub, gpu, asgi_app, Volume

IMAGE_NAME = os.environ.get("TABBY_IMAGE", "tabbyml/tabby")

image = (
Image.from_registry(
IMAGE_NAME,
add_python="3.11",
)
.dockerfile_commands("ENTRYPOINT []")
.pip_install("asgi-proxy-lib")
)

stub = Stub("tabby-demo-server", image=image)
volume = Volume.from_name("tabby-demo-server-volume", create_if_missing=True)

@stub.function(
concurrency_limit=1,
allow_concurrent_inputs=100,
container_idle_timeout=600*2,
timeout=600,
volumes = {"/data": volume},
_allow_background_volume_commits=True
)
@asgi_app()
def entry():
import socket
import subprocess
import time
import os
from asgi_proxy import asgi_proxy

env = os.environ.copy()
env["TABBY_DISABLE_USAGE_COLLECTION"] = "1"
env["TABBY_WEBSERVER_DEMO_MODE"] = "1"
launcher = subprocess.Popen(
[
"/opt/tabby/bin/tabby-cpu",
"serve",
"--port",
"8000",
],
env=env
)

# Poll until webserver at 127.0.0.1:8000 accepts connections before running inputs.
def tabby_ready():
try:
socket.create_connection(("127.0.0.1", 8000), timeout=1).close()
return True
except (socket.timeout, ConnectionRefusedError):
# Check if launcher webserving process has exited.
# If so, a connection can never be made.
retcode = launcher.poll()
if retcode is not None:
raise RuntimeError(f"launcher exited unexpectedly with code {retcode}")
return False

while not tabby_ready():
time.sleep(1.0)

print("Tabby server ready!")
return asgi_proxy("http://localhost:8000")

0 comments on commit cdddd28

Please sign in to comment.