forked from TabbyML/tabby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add auto deployment for tabby live demo (TabbyML#2034)
- Loading branch information
Showing
2 changed files
with
102 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,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 |
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,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") |