From 3a44d4923b5c7df7a5322adbe6dcf2c623a3319f Mon Sep 17 00:00:00 2001 From: Chad Baxter Date: Mon, 22 Jan 2024 21:02:56 -0500 Subject: [PATCH] containerized --- Containerfile | 21 +++++++++++++++++++++ compose.yml | 12 ++++++++++++ src/main.rs | 3 ++- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 Containerfile create mode 100644 compose.yml diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..72c9a31 --- /dev/null +++ b/Containerfile @@ -0,0 +1,21 @@ +FROM lukemathwalker/cargo-chef:latest-rust-alpine as chef +WORKDIR /app + +FROM chef AS planner +COPY ./Cargo.toml ./Cargo.lock ./ +COPY ./src ./src +COPY ./templates ./templates +RUN cargo chef prepare + +FROM chef AS builder +COPY --from=planner /app/recipe.json . +RUN cargo chef cook --release +COPY . . +RUN cargo build --release +RUN mv ./target/release/cbax_dev ./app + +FROM scratch AS runtime +WORKDIR /app +COPY --from=builder /app/app ./app +EXPOSE 7654 +ENTRYPOINT ["/app/app"] diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..55e4f6f --- /dev/null +++ b/compose.yml @@ -0,0 +1,12 @@ +version: '3.7' + +services: + web: + build: + context: . + dockerfile: Containerfile + ports: + - '7654:7654' + restart: unless-stopped + volumes: + - /srv/http/cbax_dev:/app/static diff --git a/src/main.rs b/src/main.rs index 115abf8..3019532 100644 --- a/src/main.rs +++ b/src/main.rs @@ -82,9 +82,10 @@ async fn main() { .layer(ServiceBuilder::new().layer(TraceLayer::new_for_http())); // run it - let listener = tokio::net::TcpListener::bind("127.0.0.1:7654") + let listener = tokio::net::TcpListener::bind("0.0.0.0:7654") .await .unwrap(); + println!("listening on {}", listener.local_addr().unwrap()); tracing::debug!("listening on {}", listener.local_addr().unwrap()); axum::serve(listener, app).await.unwrap(); }