Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
91 lines (69 loc) · 3.08 KB
/
Copy pathDockerfile
File metadata and controls
91 lines (69 loc) · 3.08 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
# ---- Stage 1: Build frontend ----
FROM node:20-alpine AS frontend-builder
ARG HTTP_PROXY
ARG HTTPS_PROXY
ARG NO_PROXY
ENV http_proxy=$HTTP_PROXY https_proxy=$HTTPS_PROXY no_proxy=$NO_PROXY
WORKDIR /app/frontend
COPY package.json package-lock.json ./
RUN npm config set registry https://registry.npmmirror.com && npm ci --ignore-scripts
COPY . .
RUN npm run build
# ---- Stage 2: Build backend (cargo-chef multi-stage) ----
FROM rust:1.91-alpine AS backend-base
ARG HTTP_PROXY
ARG HTTPS_PROXY
ARG NO_PROXY
ENV http_proxy=$HTTP_PROXY https_proxy=$HTTPS_PROXY no_proxy=$NO_PROXY,localhost,127.0.0.1,mirrors.ustc.edu.cn,/.local,/.internal
# Set cargo env for stable network operation
ENV CARGO_NET_RETRY=5 \
CARGO_HTTP_TIMEOUT=120 \
CARGO_HTTP_MULTIPLEXING=false
# Install protoc for LanceDB + build tools
# Use alpine's protobuf package instead of downloading from GitHub releases
# (GitHub download is unreliable in restricted network environments;
# apk only needs the alpine mirror which works with proxy/mirror config)
RUN apk add --no-cache musl-dev wget unzip protobuf protobuf-dev
# Use USTC mirror for faster crate downloads (sparse protocol)
RUN mkdir -p /usr/local/cargo && \
echo '[source.crates-io]' > /usr/local/cargo/config.toml && \
echo "replace-with = 'ustc'" >> /usr/local/cargo/config.toml && \
echo '[source.ustc]' >> /usr/local/cargo/config.toml && \
echo 'registry = "sparse+https://mirrors.ustc.edu.cn/crates.io-index/"' >> /usr/local/cargo/config.toml
# Install cargo-chef for dependency caching
RUN cargo install cargo-chef --locked
WORKDIR /app/backend
# Planner: analyze project and generate dependency recipe
FROM backend-base AS planner
COPY src-tauri/Cargo.toml src-tauri/Cargo.lock ./
COPY src-tauri/src src/
COPY src/lib/source-watch-defaults.json /app/src/lib/source-watch-defaults.json
RUN cargo chef prepare --recipe-path recipe.json
# Builder: cook dependencies (cached layer), then build app
FROM backend-base AS builder
COPY --from=planner /app/backend/recipe.json recipe.json
RUN cargo chef cook --profile release-container --recipe-path recipe.json
COPY src-tauri/Cargo.toml src-tauri/Cargo.lock ./
COPY src-tauri/src src/
COPY src/lib/source-watch-defaults.json /app/src/lib/source-watch-defaults.json
RUN cargo build --profile release-container
# ---- Stage 3: Runtime (minimal, no nginx) ----
FROM alpine:3.24 AS runtime
ARG HTTP_PROXY
ARG HTTPS_PROXY
ARG NO_PROXY
ENV http_proxy=$HTTP_PROXY https_proxy=$HTTPS_PROXY no_proxy=$NO_PROXY
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories && \
apk add --no-cache ca-certificates wget nodejs
COPY --from=builder /app/backend/target/release-container/cortex /usr/local/bin/cortex
COPY --from=frontend-builder /app/frontend/dist /usr/share/nginx/html
COPY docker/entrypoint.sh /entrypoint.sh
COPY worker/ingest-worker.mjs /app/worker/ingest-worker.mjs
RUN chmod +x /entrypoint.sh
RUN mkdir -p /data
EXPOSE 80
# Docker container must bind 0.0.0.0 to accept connections from outside
ENV CORTEX_HOST=0.0.0.0
ENV CORTEX_PORT=80
ENV CORTEX_DATA_DIR=/data
ENTRYPOINT ["/entrypoint.sh"]