Skip to content

Commit

Permalink
feat: add experimental self host setup (TabbyML#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsxiaoys authored Jun 23, 2023
1 parent 0265d94 commit 8879ed7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
12 changes: 9 additions & 3 deletions crates/tabby-scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub async fn scheduler(now: bool) -> Result<()> {
let config = Config::load()?;
let mut scheduler = JobScheduler::new();

let job = || {
let job1 = || {
info!("Syncing repositories...");
let ret = repository::sync_repositories(&config);
if let Err(err) = ret {
Expand All @@ -25,7 +25,9 @@ pub async fn scheduler(now: bool) -> Result<()> {
error!("Failed to build dataset, err: '{}'", err);
return;
}
};

let job2 = || {
info!("Indexing repositories...");
let ret = index::index_repositories(&config);
if let Err(err) = ret {
Expand All @@ -34,10 +36,14 @@ pub async fn scheduler(now: bool) -> Result<()> {
};

if now {
job();
job1();
job2();
} else {
// Every 5 minutes.
scheduler.add(Job::new("0 1/5 * * * * *".parse().unwrap(), job1));

// Every 5 hours.
scheduler.add(Job::new("0 0 1/5 * * * *".parse().unwrap(), job));
scheduler.add(Job::new("0 0 1/5 * * * *".parse().unwrap(), job2));

info!("Scheduler activated...");
loop {
Expand Down
11 changes: 11 additions & 0 deletions experimental/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
http://*:8080 {
handle_path /repos* {
reverse_proxy klaus:8080 {
header_up X-Script-Name "/repos"
}
}

handle_path /* {
reverse_proxy tabby:8080
}
}
39 changes: 39 additions & 0 deletions experimental/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: '3.5'

services:
web:
image: caddy
volumes:
- "./Caddyfile:/etc/caddy/Caddyfile:ro"
ports:
- 8080:8080

tabby:
restart: always
image: tabbyml/tabby
platform: linux/amd64
command: serve --model TabbyML/T5P-220M
environment:
TABBY_ROOT: /data
volumes:
- "$HOME/.tabby:/data"

scheduler:
restart: always
image: tabbyml/tabby
platform: linux/amd64
command: scheduler
environment:
TABBY_ROOT: /data
volumes:
- "$HOME/.tabby:/data"

klaus:
image: jonashaag/klaus
environment:
KLAUS_REPOS_ROOT: /repos
KLAUS_SITE_NAME: tabby
command: |
sh -c 'git config --global --add safe.directory "*" && pip install gunicorn && gunicorn klaus.contrib.wsgi_autoreload -b 0.0.0.0:8080'
volumes:
- "$HOME/.tabby/repositories:/repos:ro"

0 comments on commit 8879ed7

Please sign in to comment.