containerized

This commit is contained in:
Chad Baxter 2024-01-22 21:02:56 -05:00
parent a261c71fea
commit 3a44d4923b
No known key found for this signature in database
GPG key ID: FE5FA57E02944FB5
3 changed files with 35 additions and 1 deletions

21
Containerfile Normal file
View file

@ -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"]

12
compose.yml Normal file
View file

@ -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

View file

@ -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();
}