-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENH] Add rust frontend stub (#3549)
## Description of changes *Summarize the changes made by this PR.* - Improvements & Bug fixes - / - New functionality - Adds a rust-based frontend stub - Adds the frontend to the k8s tiltfile ## Test plan *How are these changes tested?* Confirmed I can tilt up and curl the service at `:3000` - [x] Tests pass locally with `pytest` for python, `yarn test` for js, `cargo test` for rust ## Documentation Changes None required.
- Loading branch information
Showing
11 changed files
with
198 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
54 changes: 54 additions & 0 deletions
54
k8s/distributed-chroma/templates/rust-frontend-service.yaml
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,54 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: rust-frontend-service | ||
namespace: {{ .Values.namespace }} | ||
spec: | ||
replicas: {{ .Values.rustFrontendService.replicaCount }} | ||
selector: | ||
matchLabels: | ||
app: rust-frontend-service | ||
template: | ||
metadata: | ||
labels: | ||
app: rust-frontend-service | ||
spec: | ||
containers: | ||
- name: rust-frontend-service | ||
image: "{{ .Values.rustFrontendService.image.repository }}:{{ .Values.rustFrontendService.image.tag }}" | ||
imagePullPolicy: IfNotPresent | ||
ports: | ||
- containerPort: 3000 | ||
{{ if .Values.rustFrontendService.resources }} | ||
resources: | ||
limits: | ||
cpu: {{ .Values.rustFrontendService.resources.limits.cpu }} | ||
memory: {{ .Values.rustFrontendService.resources.limits.memory }} | ||
requests: | ||
cpu: {{ .Values.rustFrontendService.resources.requests.cpu }} | ||
memory: {{ .Values.rustFrontendService.resources.requests.memory }} | ||
{{ end }} | ||
{{if .Values.rustFrontendService.tolerations}} | ||
tolerations: | ||
{{ toYaml .Values.rustFrontendService.tolerations | nindent 8 }} | ||
{{ end }} | ||
{{if .Values.rustFrontendService.nodeSelector}} | ||
nodeSelector: | ||
{{ toYaml .Values.rustFrontendService.nodeSelector | nindent 8 }} | ||
{{ end }} | ||
|
||
--- | ||
|
||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: rust-frontend-service | ||
namespace: {{ .Values.namespace }} | ||
spec: | ||
ports: | ||
- name: server-port | ||
port: 3000 | ||
targetPort: 3000 | ||
selector: | ||
app: rust-frontend-service | ||
type: ClusterIP |
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
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,12 @@ | ||
[package] | ||
name = "frontend" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[[bin]] | ||
name = "frontend_service" | ||
path = "src/bin/frontend_service.rs" | ||
|
||
[dependencies] | ||
tokio = { workspace = true } | ||
axum = { workspace = true } |
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,35 @@ | ||
FROM rust:1.81.0 AS builder | ||
|
||
ARG RELEASE_MODE= | ||
|
||
WORKDIR / | ||
|
||
WORKDIR /chroma/ | ||
|
||
ENV PROTOC_ZIP=protoc-25.1-linux-x86_64.zip | ||
RUN curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v25.1/$PROTOC_ZIP \ | ||
&& unzip -o $PROTOC_ZIP -d /usr/local bin/protoc \ | ||
&& unzip -o $PROTOC_ZIP -d /usr/local 'include/*' \ | ||
&& rm -f $PROTOC_ZIP | ||
|
||
COPY Cargo.toml Cargo.toml | ||
COPY Cargo.lock Cargo.lock | ||
COPY idl/ idl/ | ||
COPY rust/ rust/ | ||
|
||
|
||
FROM builder AS frontend_service_builder | ||
# sharing=locked is necessary to prevent cargo build from running concurrently on the same mounted directory | ||
RUN --mount=type=cache,sharing=locked,target=/chroma/target/ \ | ||
--mount=type=cache,sharing=locked,target=/usr/local/cargo/registry/ \ | ||
if [ "$RELEASE_MODE" = "1" ]; then cargo build --bin frontend_service --release; else cargo build --bin frontend_service; fi && \ | ||
if [ "$RELEASE_MODE" = "1" ]; then mv target/release/frontend_service ./frontend_service; else mv target/debug/frontend_service ./frontend_service; fi | ||
|
||
|
||
FROM debian:bookworm-slim AS runner | ||
RUN apt-get update && apt-get install -y libssl-dev ca-certificates && rm -rf /var/lib/apt/lists/* | ||
COPY --from=builder /chroma/rust/worker/chroma_config.yaml . | ||
|
||
FROM runner AS frontend_service | ||
COPY --from=frontend_service_builder /chroma/frontend_service . | ||
ENTRYPOINT [ "./frontend_service" ] |
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,7 @@ | ||
use frontend::frontend_service_entrypoint; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
// TODO(hammadb): Implement the frontend service entrypoint | ||
frontend_service_entrypoint().await; | ||
} |
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,7 @@ | ||
mod server; | ||
use server::FrontendServer; | ||
|
||
pub async fn frontend_service_entrypoint() { | ||
let server = FrontendServer::new(); | ||
FrontendServer::run(server).await; | ||
} |
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,46 @@ | ||
use std::sync::Arc; | ||
|
||
use axum::{extract::State, routing::get, Router}; | ||
|
||
struct FrontendServerInner {} | ||
|
||
#[derive(Clone)] | ||
pub(crate) struct FrontendServer { | ||
_inner: Arc<FrontendServerInner>, | ||
} | ||
|
||
impl FrontendServer { | ||
pub fn new() -> FrontendServer { | ||
FrontendServer { | ||
_inner: Arc::new(FrontendServerInner {}), | ||
} | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub async fn run(server: FrontendServer) { | ||
let app = Router::new() | ||
// `GET /` goes to `root` | ||
.route("/", get(root)) | ||
.with_state(server); | ||
|
||
// TODO: configuration for this | ||
// TODO: tracing | ||
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); | ||
axum::serve(listener, app).await.unwrap(); | ||
} | ||
|
||
////////////////////////// Method Implementations ////////////////////// | ||
|
||
fn root(&self) -> &'static str { | ||
"Hello, World!" | ||
} | ||
} | ||
|
||
////////////////////////// Method Handlers ////////////////////////// | ||
// These handlers simply proxy the call and the relevant inputs into | ||
// the appropriate method on the `FrontendServer` struct. | ||
|
||
// Dummy implementation for now | ||
async fn root(State(server): State<FrontendServer>) -> &'static str { | ||
server.root() | ||
} |
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