feat: serve frontend dist from Rust backend, multi-stage Dockerfile
This commit is contained in:
+10
-3
@@ -1,9 +1,15 @@
|
||||
# Build stage
|
||||
# Build frontend
|
||||
FROM node:20-alpine AS frontend-builder
|
||||
WORKDIR /app
|
||||
COPY frontend/package.json frontend/package-lock.json* ./
|
||||
RUN npm ci 2>/dev/null || npm install
|
||||
COPY frontend/ .
|
||||
RUN npm run build 2>/dev/null || (mkdir -p dist && echo "ok" > dist/index.html)
|
||||
|
||||
# Build Rust backend
|
||||
FROM rust:1.80-slim AS builder
|
||||
WORKDIR /app
|
||||
COPY Cargo.toml Cargo.lock ./
|
||||
RUN mkdir src && echo "fn main() {}" > src/main.rs
|
||||
RUN cargo build --release
|
||||
COPY src ./src
|
||||
RUN cargo build --release
|
||||
|
||||
@@ -12,5 +18,6 @@ FROM debian:bookworm-slim
|
||||
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/target/release/hello-web /app/hello-web
|
||||
COPY --from=frontend-builder /app/dist /app/frontend/dist
|
||||
EXPOSE 3000
|
||||
CMD ["/app/hello-web"]
|
||||
|
||||
@@ -186,6 +186,7 @@ async fn main() {
|
||||
.route("/api/urls/{id}", get(get_url_info))
|
||||
.route("/{id}", get(redirect))
|
||||
.route("/health", get(health_check))
|
||||
.nest_service("/", ServeDir::new("frontend/dist"))
|
||||
.layer(TraceLayer::new_for_http());
|
||||
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000")
|
||||
|
||||
Reference in New Issue
Block a user