-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathDockerfile
More file actions
98 lines (76 loc) · 2.8 KB
/
Copy pathDockerfile
File metadata and controls
98 lines (76 loc) · 2.8 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
# Multi-stage Dockerfile for cxdb
# Stage 1: Build Next.js frontend
# Stage 2: Build Rust binary
# Stage 3: Runtime with nginx + supervisord
# ============================================
# Stage 1: Build frontend
# ============================================
FROM node:20-alpine AS frontend
WORKDIR /app
# Install pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
# Copy package files
COPY frontend/package.json frontend/pnpm-lock.yaml* ./
# Install dependencies
RUN pnpm install --frozen-lockfile || pnpm install
# Copy source
COPY frontend/ ./
# Build static export
RUN pnpm build
# ============================================
# Stage 2: Build Rust binary
# ============================================
FROM rust:1.92-bookworm AS backend
WORKDIR /app
# Copy Cargo files first for dependency caching
COPY Cargo.toml Cargo.lock* ./
COPY server/Cargo.toml ./server/
COPY clients/rust/Cargo.toml ./clients/rust/
COPY cxtx/Cargo.toml ./cxtx/
# Create dummy sources to build dependencies
RUN mkdir -p server/src clients/rust/src cxtx/src && \
echo "fn main() {}" > server/src/main.rs && \
echo "pub fn dummy() {}" > clients/rust/src/lib.rs && \
echo "pub fn dummy() {}" > cxtx/src/lib.rs && \
echo "fn main() {}" > cxtx/src/main.rs && \
cargo build --release --manifest-path server/Cargo.toml && \
rm -rf server/src clients/rust/src cxtx/src
# Copy actual source and build
COPY server/ ./server/
COPY clients/ ./clients/
COPY cxtx/ ./cxtx/
RUN find server/src clients/rust/src cxtx/src -type f -exec touch {} + && \
cargo build --release --manifest-path server/Cargo.toml
# ============================================
# Stage 3: Runtime
# ============================================
FROM debian:bookworm-slim
# Install nginx and supervisor
RUN apt-get update && apt-get install -y --no-install-recommends \
nginx \
supervisor \
ca-certificates \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create directories
RUN mkdir -p /app /data /var/log/supervisor
# Copy binaries and static files. The frontend keeps production exports in a
# separate dist dir so `next build` doesn't clobber a live dev server's `.next`
# artifacts.
COPY --from=backend /app/target/release/cxdb-server /app/cxdb
COPY --from=frontend /app/.next-build/. /usr/share/nginx/html/
# Copy nginx config
COPY deploy/nginx.conf /etc/nginx/nginx.conf
# Copy supervisor config
COPY deploy/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# Environment
ENV CXDB_DATA_DIR=/data
ENV CXDB_BIND=0.0.0.0:9009
ENV CXDB_HTTP_BIND=127.0.0.1:9010
# Expose nginx port
EXPOSE 80
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost/v1/contexts?limit=1 || exit 1
# Run supervisor
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]