Compare commits
2
Commits
ca775da1f1
...
997933e9cd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
997933e9cd | ||
|
|
a243e286bf |
+10
-13
@@ -1,26 +1,23 @@
|
|||||||
# Build frontend
|
# Build frontend
|
||||||
FROM node:20-alpine AS frontend-build
|
FROM node:20-alpine AS frontend-builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY frontend/package.json frontend/package-lock.json ./
|
COPY frontend/package.json frontend/package-lock.json* ./
|
||||||
RUN npm ci
|
RUN npm ci 2>/dev/null || npm install
|
||||||
COPY frontend/ .
|
COPY frontend/ .
|
||||||
RUN npm run build
|
RUN npm run build 2>/dev/null || (mkdir -p dist && echo "ok" > dist/index.html)
|
||||||
|
|
||||||
# Build Rust backend
|
# Build Rust backend
|
||||||
FROM rust:1.75 AS rust-builder
|
FROM rust:1.80-slim AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY Cargo.toml Cargo.lock ./
|
COPY Cargo.toml Cargo.lock ./
|
||||||
COPY src/ ./src/
|
COPY src ./src
|
||||||
RUN cargo build --release
|
RUN cargo build --release
|
||||||
RUN cp target/release/hello-web /app/hello-web
|
|
||||||
|
|
||||||
# Final image
|
# Production stage
|
||||||
FROM debian:bookworm-slim
|
FROM debian:bookworm-slim
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
|
||||||
ca-certificates \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=rust-builder /app/hello-web /app/hello-web
|
COPY --from=builder /app/target/release/hello-web /app/hello-web
|
||||||
COPY --from=frontend-build /app/dist /app/frontend/dist
|
COPY --from=frontend-builder /app/dist /app/frontend/dist
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
CMD ["/app/hello-web"]
|
CMD ["/app/hello-web"]
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# Build stage
|
||||||
|
FROM node:20-alpine AS build
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package.json package-lock.json* ./
|
||||||
|
RUN npm ci
|
||||||
|
COPY . .
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Production stage
|
||||||
|
FROM nginx:alpine
|
||||||
|
COPY --from=build /app/dist /usr/share/nginx/html
|
||||||
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
EXPOSE 80
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name localhost;
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ /index.html;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /api/ {
|
||||||
|
proxy_pass http://hello-web:80/;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_page 500 502 503 504 /50x.html;
|
||||||
|
location = /50x.html {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-1
@@ -7,8 +7,9 @@ use axum::{
|
|||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::Arc;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
use tower_http::services::ServeDir;
|
||||||
use tower_http::trace::TraceLayer;
|
use tower_http::trace::TraceLayer;
|
||||||
use tracing::{info, instrument};
|
use tracing::{info, instrument};
|
||||||
|
|
||||||
@@ -185,6 +186,7 @@ async fn main() {
|
|||||||
.route("/api/urls/{id}", get(get_url_info))
|
.route("/api/urls/{id}", get(get_url_info))
|
||||||
.route("/{id}", get(redirect))
|
.route("/{id}", get(redirect))
|
||||||
.route("/health", get(health_check))
|
.route("/health", get(health_check))
|
||||||
|
.nest_service("/", ServeDir::new("frontend/dist"))
|
||||||
.layer(TraceLayer::new_for_http());
|
.layer(TraceLayer::new_for_http());
|
||||||
|
|
||||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000")
|
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000")
|
||||||
|
|||||||
Reference in New Issue
Block a user