-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
72 lines (50 loc) · 1.93 KB
/
Dockerfile
File metadata and controls
72 lines (50 loc) · 1.93 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
# Stage 1: Build the frontend
FROM node:22-slim AS frontend-builder
WORKDIR /app/frontend
COPY frontend/package.json frontend/package-lock.json ./
RUN npm ci
COPY frontend/ ./
RUN npm run build
# Stage 2: Build the Rust binary
FROM rust:latest AS builder
# Limit parallelism to reduce memory usage on small servers
ENV CARGO_BUILD_JOBS=1
WORKDIR /app
# Copy manifests first for dependency caching
COPY Cargo.toml Cargo.lock ./
COPY crates/bcf-core/Cargo.toml crates/bcf-core/Cargo.toml
COPY crates/bcf-server/Cargo.toml crates/bcf-server/Cargo.toml
# Create dummy source files to build dependencies
RUN mkdir -p crates/bcf-core/src crates/bcf-server/src && \
echo "pub mod types;" > crates/bcf-core/src/lib.rs && \
echo "pub struct Dummy;" > crates/bcf-core/src/types.rs && \
echo "fn main() {}" > crates/bcf-server/src/main.rs
# Copy migrations (needed for sqlx compile-time checks)
COPY migrations/ migrations/
# Build dependencies only (cached layer)
RUN cargo build --release -p bcf-server 2>/dev/null || true
# Copy actual source code
COPY crates/ crates/
# Touch source files to invalidate cache, then build
RUN touch crates/bcf-core/src/lib.rs crates/bcf-server/src/main.rs && \
cargo build --release -p bcf-server
# Stage 3: Minimal runtime image
FROM debian:bookworm-slim
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates curl && \
rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN groupadd -r bcf && useradd -r -g bcf -d /app bcf
WORKDIR /app
# Copy binary from builder
COPY --from=builder /app/target/release/bcf-server /app/bcf-server
# Copy frontend build output
COPY --from=frontend-builder /app/frontend/dist /app/static
# Copy migrations for runtime migration
COPY migrations/ /app/migrations/
# Create data directory for snapshots
RUN mkdir -p /app/data/snapshots && chown -R bcf:bcf /app
USER bcf
EXPOSE 3000
ENV RUST_LOG=bcf_server=info,tower_http=info
CMD ["/app/bcf-server"]