-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile.server
More file actions
108 lines (92 loc) · 4.33 KB
/
Copy pathDockerfile.server
File metadata and controls
108 lines (92 loc) · 4.33 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
# ============================================
# AINS Server - Backend Dockerfile
# ============================================
# Build context: project root directory
# Usage: docker build -f Dockerfile.server -t ains-server .
FROM rust:1.92.0-slim AS builder
WORKDIR /app
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
# ── Copy all workspace Cargo.toml manifests for dependency caching ──
COPY Cargo.toml Cargo.lock ./
COPY server/Cargo.toml ./server/Cargo.toml
COPY app/web/Cargo.toml ./app/web/Cargo.toml
COPY app/ui/Cargo.toml ./app/ui/Cargo.toml
COPY app/desktop/Cargo.toml ./app/desktop/Cargo.toml
COPY app/mobile/Cargo.toml ./app/mobile/Cargo.toml
COPY app/client-api/Cargo.toml ./app/client-api/Cargo.toml
COPY crates/rust-agent/Cargo.toml ./crates/rust-agent/Cargo.toml
COPY crates/emailserver/Cargo.toml ./crates/emailserver/Cargo.toml
COPY crates/distributed-ratelimit/Cargo.toml ./crates/distributed-ratelimit/Cargo.toml
COPY crates/i18n/Cargo.toml ./crates/i18n/Cargo.toml
COPY crates/wechat-api/Cargo.toml ./crates/wechat-api/Cargo.toml
COPY crates/ains-runtime/Cargo.toml ./crates/ains-runtime/Cargo.toml
COPY crates/ains-axum/Cargo.toml ./crates/ains-axum/Cargo.toml
COPY crates/ains-salvo/Cargo.toml ./crates/ains-salvo/Cargo.toml
# ── Create dummy source files for ALL workspace members ──
# Required for cargo fetch to resolve all workspace members.
RUN for dir in \
server app/web app/ui app/desktop app/mobile app/client-api \
crates/rust-agent crates/emailserver crates/distributed-ratelimit crates/i18n \
crates/wechat-api crates/ains-runtime crates/ains-axum \
crates/ains-salvo; do \
mkdir -p "$dir/src"; \
done && \
echo 'pub fn placeholder() {}' > server/src/lib.rs && \
echo 'fn main() {}' > server/src/main.rs && \
echo 'fn main() {}' > app/web/src/main.rs && \
echo 'pub fn placeholder() {}' > app/ui/src/lib.rs && \
echo 'fn main() {}' > app/desktop/src/main.rs && \
echo 'fn main() {}' > app/mobile/src/main.rs && \
echo 'pub fn placeholder() {}' > app/client-api/src/lib.rs && \
echo 'pub fn placeholder() {}' > crates/rust-agent/src/lib.rs && \
echo 'pub fn placeholder() {}' > crates/emailserver/src/lib.rs && \
echo 'pub fn placeholder() {}' > crates/distributed-ratelimit/src/lib.rs && \
echo 'pub fn placeholder() {}' > crates/i18n/src/lib.rs && \
echo 'pub fn placeholder() {}' > crates/wechat-api/src/lib.rs && \
echo 'pub fn placeholder() {}' > crates/ains-runtime/src/lib.rs && \
echo 'pub fn placeholder() {}' > crates/ains-axum/src/lib.rs && \
echo 'pub fn placeholder() {}' > crates/ains-salvo/src/lib.rs
# Fetch all dependencies (fails on network errors)
RUN cargo fetch
# Pre-build to compile and cache dependencies.
# Dummy sources cause compilation errors for some packages — harmless.
# The || true swallows those errors while preserving cached dependency artifacts.
RUN cargo build --release --package ains-server || true
# ── Copy real source code ──
COPY server/src ./server/src
COPY server/migrations ./server/migrations
COPY crates/emailserver/src ./crates/emailserver/src
COPY crates/distributed-ratelimit/src ./crates/distributed-ratelimit/src
COPY crates/wechat-api/src ./crates/wechat-api/src
COPY crates/ains-runtime/src ./crates/ains-runtime/src
COPY crates/ains-axum/src ./crates/ains-axum/src
# Touch all copied source files to invalidate pre-build cache
RUN find server/src crates/emailserver/src crates/distributed-ratelimit/src \
crates/wechat-api/src crates/ains-runtime/src crates/ains-axum/src \
-type f -name '*.rs' -exec touch {} +
# Final build with real source code
RUN cargo build --release --package ains-server
# ── Runtime stage ──
FROM debian:bookworm-slim AS runtime
WORKDIR /app
RUN apt-get update && apt-get install -y \
ca-certificates \
libssl3 \
libpq5 \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user matching K8s securityContext (UID 1000)
RUN groupadd -r ains && \
useradd -r -g ains -u 1000 ains
COPY --from=builder /app/target/release/ains-server /app/ains-server
RUN chown ains:ains /app/ains-server
USER ains
EXPOSE 3000
ENV RUST_LOG=info
# Database and Redis connection URLs are injected at runtime
# (via docker-compose environment or K8s secrets)
CMD ["/app/ains-server"]