Skip to content
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
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.github/
.vscode/
target/
recipe.json
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
/target
recipe.json
20 changes: 20 additions & 0 deletions Cargo.lock

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

52 changes: 52 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
FROM rust:slim-bookworm AS build-chef

WORKDIR /work
RUN cargo install cargo-chef --locked

FROM build-chef AS build-planner

COPY . .
RUN cargo chef prepare --recipe-path recipe.json --bin server

FROM build-chef AS build-server

ARG CARGO_FEATURES=""
ENV CARGO_FEATURES=${CARGO_FEATURES}

RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends protobuf-compiler \
&& rm -rf /var/lib/apt/lists/*

COPY --from=build-planner /work/recipe.json recipe.json

RUN cargo chef cook --release --features=${CARGO_FEATURES} --recipe-path recipe.json

COPY . .

# NOTE: Simplified build that leaves debug info in the binary. As the binary grows, we will want to
# move this out and instead upload it directly to the registry and Sentry.
RUN cargo build --release --features=${CARGO_FEATURES} --bin server

FROM debian:bookworm-slim

RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends ca-certificates gosu \
&& rm -rf /var/lib/apt/lists/*

ENV \
SERVER_UID=10001 \
SERVER_GID=10001

# Create a new user and group with fixed uid/gid
RUN groupadd --system fss --gid $SERVER_GID \
&& useradd --system --gid fss --uid $SERVER_UID fss

VOLUME ["/data"]
EXPOSE 50051

COPY --from=build-server /work/target/release/server /bin
COPY docker-entrypoint.sh /docker-entrypoint.sh

ENTRYPOINT ["/bin/bash", "/docker-entrypoint.sh"]
8 changes: 8 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -eu

if [ "$(id -u)" == "0" ]; then
exec gosu fss /bin/server "$@"
else
exec /bin/server "$@"
fi
5 changes: 3 additions & 2 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ version = "0.1.0"
edition = "2024"

[dependencies]
tokio = { version = "1.45.1", features = ["full"] }
tonic = { version = "0.13.1" }
elegant-departure = { version = "0.3.1", features = ["tokio"] }
proto-codegen = { path = "../proto-codegen" }
service = { path = "../service" }
tokio = { version = "1.45.1", features = ["full"] }
tonic = { version = "0.13.1" }
15 changes: 11 additions & 4 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
//! an `HTTP` layer which can serve files directly to *external clients*.

use proto_codegen::storage::{AllocateBlobRequest, AllocateBlobResponse, StorageId};
use tokio::signal::unix::SignalKind;
use tonic::{Request, Response, Status, transport::Server};

use proto_codegen::storage::storage_server::{Storage, StorageServer};

#[derive(Default)]
#[derive(Debug, Default)]
pub struct MockStorage {}

#[tonic::async_trait]
Expand Down Expand Up @@ -37,13 +38,19 @@ impl Storage for MockStorage {
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr = "0.0.0.0:50051".parse().unwrap();
let greeter = MockStorage::default();
let storage = MockStorage::default();

println!("Server listening on {addr}");

let shutdown = elegant_departure::tokio::depart()
.on_termination()
.on_sigint()
.on_signal(SignalKind::hangup())
.on_signal(SignalKind::quit());

Server::builder()
.add_service(StorageServer::new(greeter))
.serve(addr)
.add_service(StorageServer::new(storage))
.serve_with_shutdown(addr, shutdown)
.await?;

Ok(())
Expand Down