Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): extract prod feature in tabby crate #1797

Merged
merged 6 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,50 +41,50 @@ jobs:
- os: macos-latest
target: aarch64-apple-darwin
binary: aarch64-apple-darwin
build_args: --features prod-db
build_args: --features prod
- os: dimerun-k3-ubuntu2204
target: x86_64-unknown-linux-gnu
binary: x86_64-manylinux2014
container: quay.io/pypa/manylinux2014_x86_64
build_args: --features static-ssl,prod-db
build_args: --features static-ssl,prod
- os: dimerun-k3-ubuntu2204
target: x86_64-unknown-linux-gnu
binary: x86_64-manylinux2014-cuda117
container: sameli/manylinux2014_x86_64_cuda_11.7
build_args: --features static-ssl --features cuda,prod-db
build_args: --features static-ssl,cuda,prod
- os: dimerun-k3-ubuntu2204
target: x86_64-unknown-linux-gnu
binary: x86_64-manylinux2014-cuda122
container: sameli/manylinux2014_x86_64_cuda_12.2
build_args: --features static-ssl --features cuda,prod-db
build_args: --features static-ssl,cuda,prod
- os: dimerun-k3-ubuntu2204
target: x86_64-unknown-linux-gnu
binary: x86_64-manylinux2014-vulkan
container: quay.io/pypa/manylinux2014_x86_64
build_args: --features static-ssl,vulkan,prod-db
build_args: --features static-ssl,vulkan,prod
vulkan_sdk: '1.3.239.0'
- os: windows-latest
target: x86_64-pc-windows-msvc
binary: x86_64-windows-msvc
build_args: --features prod-db
build_args: --features prod
ext: .exe
- os: windows-latest
target: x86_64-pc-windows-msvc
binary: x86_64-windows-msvc-vulkan
ext: .exe
build_args: --features vulkan,prod-db
build_args: --features vulkan,prod
vulkan_sdk: '1.3.280.0'
- os: windows-latest
target: x86_64-pc-windows-msvc
binary: x86_64-windows-msvc-cuda117
ext: .exe
build_args: --features cuda,prod-db
build_args: --features cuda,prod
windows_cuda: '11.7.1'
- os: windows-latest
target: x86_64-pc-windows-msvc
binary: x86_64-windows-msvc-cuda122
ext: .exe
build_args: --features cuda,prod-db
build_args: --features cuda,prod
windows_cuda: '12.2.0'

env:
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/tabby/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ experimental-http = ["dep:http-api-bindings"]
# architecture, enable this feature to compile OpenSSL as part of the build.
# See https://docs.rs/openssl/#vendored for more.
static-ssl = ['openssl/vendored']
prod-db = ['tabby-webserver/prod-db']
prod = ['tabby-webserver/prod-db']

[dependencies]
tabby-common = { path = "../tabby-common" }
Expand Down
7 changes: 6 additions & 1 deletion crates/tabby/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod routes;

Check failure on line 1 in crates/tabby/src/main.rs

View workflow job for this annotation

GitHub Actions / autofix

expected item, found `[`
mod services;

mod download;
Expand Down Expand Up @@ -231,7 +231,12 @@
};
}

let mut dirs = "tabby=info,axum_tracing_opentelemetry=info,otel=debug".to_owned();
let mut dirs = if cfg!(feature = "prod") {
"tabby=info,axum_tracing_opentelemetry=info,otel=debug".into()

Check warning on line 235 in crates/tabby/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby/src/main.rs#L234-L235

Added lines #L234 - L235 were not covered by tests
} else {
"tabby=debug,axum_tracing_opentelemetry=info,otel=debug".into()

Check warning on line 237 in crates/tabby/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby/src/main.rs#L237

Added line #L237 was not covered by tests
};

if let Ok(env) = std::env::var(EnvFilter::DEFAULT_ENV) {
dirs = format!("{dirs},{env}")
};
Expand Down
3 changes: 0 additions & 3 deletions crates/tabby/src/services/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use tabby_common::{
};
use tabby_inference::{TextGeneration, TextGenerationOptions, TextGenerationOptionsBuilder};
use thiserror::Error;
use tracing::debug;
use utoipa::ToSchema;

use super::model;
Expand Down Expand Up @@ -284,7 +283,6 @@ impl CompletionService {
let (prompt, segments, snippets) = if let Some(prompt) = request.raw_prompt() {
(prompt, None, vec![])
} else if let Some(segments) = request.segments.clone() {
debug!("PREFIX: {}, SUFFIX: {:?}", segments.prefix, segments.suffix);
let snippets = self
.build_snippets(
&language,
Expand All @@ -299,7 +297,6 @@ impl CompletionService {
} else {
return Err(CompletionError::EmptyPrompt);
};
debug!("PROMPT: {}", prompt);

let text = self.engine.generate(&prompt, options).await;
let segments = segments.map(|s| s.into());
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.cuda
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ COPY . .

RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/root/workspace/target \
cargo build --features cuda,prod-db --release --package tabby && \
cargo build --features cuda,prod --release --package tabby && \
cp target/release/tabby /opt/tabby/bin/

RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/root/workspace/target \
cargo build --features prod-db --release --package tabby && \
cargo build --features prod --release --package tabby && \
cp target/release/tabby /opt/tabby/bin/tabby-cpu

FROM ${BASE_CUDA_RUN_CONTAINER} as runtime
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.rocm
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ COPY . .

RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/root/workspace/target \
cargo build --features rocm,prod-db --release --package tabby && \
cargo build --features rocm,prod --release --package tabby && \
cp target/release/tabby /opt/tabby/bin/

RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/root/workspace/target \
cargo build --features prod-db --release --package tabby && \
cargo build --features prod --release --package tabby && \
cp target/release/tabby /opt/tabby/bin/tabby-cpu

FROM ${BASE_ROCM_RUN_CONTAINER} AS runtime
Expand Down
2 changes: 0 additions & 2 deletions ee/tabby-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ homepage.workspace = true

[features]
testutils = []
prod-db = []

[dependencies]
tabby-db-macros = { path = "../tabby-db-macros" }
Expand All @@ -17,7 +16,6 @@ hash-ids.workspace = true
lazy_static.workspace = true
sql_query_builder = { version = "2.1.0", features = ["sqlite"] }
sqlx = { version = "0.7.3", features = ["sqlite", "chrono", "runtime-tokio", "macros"] }
tabby-common = { path = "../../crates/tabby-common" }
tokio = { workspace = true, features = ["fs"] }
uuid.workspace = true

Expand Down
9 changes: 4 additions & 5 deletions ee/tabby-db/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{ops::Deref, sync::Arc};
use std::{ops::Deref, path::Path, sync::Arc};

use anyhow::anyhow;
use cache::Cache;
Expand All @@ -23,7 +23,6 @@
mod job_runs;
mod oauth_credential;
mod password_reset;
mod path;
mod refresh_tokens;
mod repositories;
mod server_setting;
Expand Down Expand Up @@ -99,10 +98,10 @@
DbConn::init_db(pool).await
}

pub async fn new() -> Result<Self> {
tokio::fs::create_dir_all(path::db_file().parent().unwrap()).await?;
pub async fn new(db_file: &Path) -> Result<Self> {
tokio::fs::create_dir_all(db_file.parent().unwrap()).await?;

Check warning on line 102 in ee/tabby-db/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-db/src/lib.rs#L101-L102

Added lines #L101 - L102 were not covered by tests
let options = SqliteConnectOptions::new()
.filename(path::db_file())
.filename(db_file)

Check warning on line 104 in ee/tabby-db/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-db/src/lib.rs#L104

Added line #L104 was not covered by tests
.create_if_missing(true);
let pool = SqlitePool::connect_with(options).await?;
Self::init_db(pool).await
Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-webserver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors.workspace = true
homepage.workspace = true

[features]
prod-db = ['tabby-db/prod-db']
prod-db = []

[dependencies]
anyhow.workspace = true
Expand Down
5 changes: 4 additions & 1 deletion ee/tabby-webserver/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use crate::{
cron, hub, integrations, oauth,
path::db_file,
repositories::{self, RepositoryCache},
schema::{auth::AuthenticationService, create_schema, Schema, ServiceLocator},
service::{create_service_locator, event_logger::create_event_logger},
Expand All @@ -33,7 +34,9 @@

impl WebserverHandle {
pub async fn new(logger1: impl EventLogger + 'static) -> Self {
let db = DbConn::new().await.expect("Must be able to initialize db");
let db = DbConn::new(db_file().as_path())
.await
.expect("Must be able to initialize db");

Check warning on line 39 in ee/tabby-webserver/src/handler.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/handler.rs#L37-L39

Added lines #L37 - L39 were not covered by tests
let logger2 = create_event_logger(db.clone());
let logger = Arc::new(ComposedLogger::new(logger1, logger2));
WebserverHandle { db, logger }
Expand Down
1 change: 1 addition & 0 deletions ee/tabby-webserver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod handler;
mod hub;
mod integrations;
mod oauth;
mod path;
mod repositories;
mod schema;
mod service;
Expand Down
File renamed without changes.
Loading