-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f55543
commit 0ad5395
Showing
3 changed files
with
126 additions
and
11 deletions.
There are no files selected for viewing
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,95 @@ | ||
--- | ||
title: "Custom Dockerized Runtimes" | ||
description: "Run generic dockerized applications on Cerebrium" | ||
--- | ||
|
||
For even greater flexibility, you are able to build your own dockerized applications with Cerebrium! You can build anything from standard Python to | ||
compiled Rust, as long as you supply a Dockerfile to build your application with. | ||
|
||
## Building Custom Dockerized applications | ||
|
||
Here's a straightforward Rust API server in the Axon Framework to demonstrate how this works: | ||
|
||
```rust | ||
use axum::{ | ||
routing::{get, post}, | ||
Json, Router, | ||
}; | ||
use serde_json::json; | ||
use std::net::SocketAddr; | ||
use tracing::Level; | ||
|
||
async fn hello() -> Json<serde_json::Value> { | ||
Json(json!({ "message": "Hello Cerebrium!" })) | ||
} | ||
|
||
async fn health() -> &'static str { | ||
"Ok" | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let app = Router::new() | ||
.route("/hello", post(hello)) | ||
.route("/health", get(health)); | ||
let addr = SocketAddr::from(([127, 0, 0, 1], 5000)); | ||
tracing::info!("Listening on {}", addr); | ||
axum::Server::bind(&addr.parse().unwrap()) | ||
.serve(app.into_make_service()) | ||
.await | ||
.unwrap(); | ||
} | ||
``` | ||
|
||
We can supply a Dockerfile which Cerebrium will use to build this application. This is just a regular, multi-stage Dockerfile. However, | ||
it should preferably include a `CMD` or `ENTRYPOINT` clause, so that the container can be run correctly. | ||
|
||
```dockerfile | ||
# Build Stage | ||
FROM rust:bookworm as builder | ||
WORKDIR /usr/src/app | ||
COPY Cargo.toml Cargo.lock ./ | ||
RUN cargo fetch | ||
|
||
# Copy the rest of the application source code and Build | ||
COPY . . | ||
RUN cargo build --release | ||
|
||
|
||
# Runtime Stage | ||
FROM scratch | ||
COPY --from=builder /usr/src/app/target/release/axum_server /app | ||
EXPOSE 5000 | ||
CMD ["/app"] | ||
``` | ||
|
||
Configure this application in `cerebrium.toml` by adding a custom runtime section, similarly to the custom Python webserver: | ||
|
||
```toml | ||
[cerebrium.runtime.custom] | ||
port = 5000 | ||
entrypoint = ["main:app", "--host", "0.0.0.0", "--port", "5000"] | ||
healthcheck_endpoint = "/health" | ||
dockerfile = "./Dockerfile" | ||
``` | ||
|
||
The configuration requires three key parameters: | ||
|
||
- `entrypoint`: The command that starts your server. This is optional, and will override the `CMD` specified in your Dockerfile | ||
- `port`: The port your server listens on | ||
- `healthcheck_endpoint`: The endpoint that confirms server health. If empty, will default to a TCP ping of your specified port | ||
- `dockerfile_path`: The relative path of the project Dockerfile used to build the application | ||
|
||
<Info> | ||
If a dockerfile path is specified, you must take care to install all the | ||
dependencies your app needs in the Dockerfile, as well as run any commands. | ||
All dependencies specified under `cerebrium.dependencies.*` will be ignored, | ||
and `cerebrium.deployment.shell_commands` & | ||
`cerebrium.deployment.pre_build_commands` will not be run. | ||
</Info> | ||
|
||
Our [Dockerized App Example](https://github.com/CerebriumAI/examples) provides a complete implementation. | ||
|
||
``` | ||
``` |
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