Skip to content

Commit

Permalink
add docker-compose file, fix docker build, add frontend static serve (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiya1155 authored Apr 5, 2024
1 parent 2ae4859 commit d1b0051
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
FROM node AS frontend

ARG SENTRY_AUTH_TOKEN
ARG SENTRY_RELEASE_VERSION

WORKDIR /build
COPY package.json package-lock.json ./
RUN npm ci
Expand Down Expand Up @@ -40,4 +37,8 @@ COPY model /model
COPY --from=builder /bleep /
COPY --from=builder /dylib /dylib
COPY --from=frontend /build/client/dist /frontend
ENTRYPOINT ["/bleep", "--host=0.0.0.0", "--source-dir=/repos", "--index-dir=/data", "--model-dir=/model", "--dylib-dir=/dylib", "--disable-log-write"]

ARG OPENAI_API_KEY
ARG GITHUB_ACCESS_TOKEN

ENTRYPOINT ["/bleep", "--host=0.0.0.0", "--source-dir=/repos", "--index-dir=/data", "--model-dir=/model", "--dylib-dir=/dylib", "--disable-log-write", "--frontend-dist=/frontend", "--openai-api-key=$OPENAI_API_KEY", "--github-access-token=$GITHUB_ACCESS_TOKEN"]
31 changes: 31 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: '3'
services:
qdrant:
image: "qdrant/qdrant"
restart: always
container_name: qdrant
ports:
- "6333:6333"
- "6334:6334"
expose:
- 6333
- 6334
- 6335
volumes:
- ./qdrant_data:/qdrant_data
bloop-app:
image: bloop-app
restart: on-failure
command: --qdrant-url=http://qdrant:6334
depends_on:
qdrant:
condition: service_started
ports:
- "7878:7878"
expose:
- 7878
build:
dockerfile: "./Dockerfile"
args:
- OPENAI_API_KEY
- GITHUB_ACCESS_TOKEN
1 change: 1 addition & 0 deletions server/bleep/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ petgraph = { version = "0.6.4", default-features = false, features = ["serde-1"]
# webserver
serde_json = "1.0.107"
axum = { version = "0.6.20", features = ["http2", "headers", "macros"] }
tower = "0.4.13"
tower-http = { version = "0.4.4", features = ["auth", "cors", "catch-panic", "fs"] }

# api integrations
Expand Down
6 changes: 6 additions & 0 deletions server/bleep/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ pub struct Configuration {
#[serde(default = "interactive_batch_size")]
/// Batch size for batched embeddings
pub embedding_batch_size: NonZeroUsize,

/// Path to built front-end folder
#[clap(long)]
pub frontend_dist: Option<PathBuf>,
}

macro_rules! right_if_default {
Expand Down Expand Up @@ -221,6 +225,8 @@ impl Configuration {
interactive_batch_size()
),

frontend_dist: b.frontend_dist.or(a.frontend_dist),

qdrant_url: right_if_default!(b.qdrant_url, a.qdrant_url, String::new()),

dylib_dir: b.dylib_dir.or(a.dylib_dir),
Expand Down
20 changes: 19 additions & 1 deletion server/bleep/src/webserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use axum::{
Extension, Json,
};
use std::{borrow::Cow, fmt, net::SocketAddr};
use tower::Service;
use tower_http::services::{ServeDir, ServeFile};
use tower_http::{catch_panic::CatchPanicLayer, cors::CorsLayer};
use tracing::info;

Expand Down Expand Up @@ -180,7 +182,23 @@ pub async fn start(app: Application) -> anyhow::Result<()> {
.layer(CorsLayer::permissive())
.layer(CatchPanicLayer::new());

let router = Router::new().nest("/api", api);
let mut router = Router::new().nest("/api", api);

if let Some(frontend_dist) = app.config.frontend_dist.clone() {
router = router.nest_service(
"/",
tower::service_fn(move |req| {
let frontend_dist = frontend_dist.clone();
async move {
Ok(ServeDir::new(&frontend_dist)
.fallback(ServeFile::new(frontend_dist.join("index.html")))
.call(req)
.await
.unwrap())
}
}),
);
}

info!(%bind, "starting webserver");
axum::Server::bind(&bind)
Expand Down

0 comments on commit d1b0051

Please sign in to comment.