-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
119 lines (90 loc) · 4.22 KB
/
Dockerfile
File metadata and controls
119 lines (90 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# ═══════════════════════════════════════════════════════════════
# Prometheus — Multi-stage Docker build
#
# Stages:
# 1. chef — cargo-chef for dependency caching
# 2. planner — generate dependency recipe
# 3. wasm — compile Leptos UI to WebAssembly
# 4. tailwind — generate optimized CSS
# 5. builder — compile Rust server binary
# 6. runtime — minimal production image
# ═══════════════════════════════════════════════════════════════
# ── Stage 1: cargo-chef base ──────────────────────────────────
FROM rust:1.75-bookworm AS chef
RUN cargo install cargo-chef
WORKDIR /app
# ── Stage 2: Dependency planner ───────────────────────────────
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
# ── Stage 3: WASM build (Leptos UI) ──────────────────────────
FROM rust:1.75-bookworm AS wasm
RUN rustup target add wasm32-unknown-unknown && \
cargo install trunk wasm-bindgen-cli
WORKDIR /app
# Copy workspace files needed for WASM build
COPY Cargo.toml Cargo.lock ./
COPY crates/prometheus-ui/ crates/prometheus-ui/
# Build WASM output
RUN cd crates/prometheus-ui && \
trunk build --release --dist /app/dist/wasm
# ── Stage 4: Tailwind CSS ────────────────────────────────────
FROM node:20-slim AS tailwind
WORKDIR /app
# Install Tailwind CLI
RUN npm install -g tailwindcss
COPY tailwind.config.js input.css ./
COPY crates/prometheus-ui/src/ crates/prometheus-ui/src/
COPY crates/prometheus-server/src/ crates/prometheus-server/src/
RUN npx tailwindcss -i input.css -o /app/dist/css/prometheus.css --minify
# ── Stage 5: Rust server build ───────────────────────────────
FROM chef AS builder
# Cook dependencies first (cached layer)
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
# Copy full source
COPY . .
# Copy WASM artifacts into the static directory
COPY --from=wasm /app/dist/wasm/ static/wasm/
# Copy Tailwind CSS output
COPY --from=tailwind /app/dist/css/ static/css/
# Build the server binary
RUN cargo build --release --bin prometheus-server
# Also cross-compile the edge daemon for ARM (optional, if cross is available)
# RUN rustup target add armv7-unknown-linux-musleabihf && \
# cargo build --release --target armv7-unknown-linux-musleabihf --bin prometheus-edge
# ── Stage 6: Runtime ─────────────────────────────────────────
FROM debian:bookworm-slim AS runtime
# Install runtime dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates \
libssl3 \
chromium \
fonts-inter \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN groupadd --gid 1000 prometheus && \
useradd --uid 1000 --gid prometheus --shell /bin/bash --create-home prometheus
WORKDIR /app
# Copy the compiled binary
COPY --from=builder /app/target/release/prometheus-server /app/prometheus-server
# Copy static assets (WASM + CSS + other statics)
COPY --from=builder /app/static/ /app/static/
COPY assets/ /app/assets/
# Copy Gradient agent source (for reference / sidecar deployment)
COPY crates/prometheus-agent/ /app/agent/
# Set environment defaults
ENV PROMETHEUS_PORT=3030 \
PROMETHEUS_HOST=0.0.0.0 \
AEGIS_DB_URL=http://aegis-db:9091 \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium \
RUST_LOG=prometheus_server=info,tower_http=info
EXPOSE 3030
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -f http://localhost:3030/health || exit 1
# Run as non-root
USER prometheus
ENTRYPOINT ["/app/prometheus-server"]
CMD ["--port", "3030"]