-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.web
More file actions
117 lines (99 loc) · 4.84 KB
/
Copy pathDockerfile.web
File metadata and controls
117 lines (99 loc) · 4.84 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
# ============================================
# AINS Web - Frontend Dockerfile
# ============================================
# Build context: project root directory
# Usage: docker build -f Dockerfile.web -t ains-web .
#
# Nginx configuration is COPY'd at build time as default.
# To override at runtime, mount nginx/default.conf as a volume
# (see docker-compose.yml).
FROM rust:1.92.0-slim AS builder
WORKDIR /app
RUN apt-get update && apt-get install -y \
curl \
pkg-config \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
# Install wasm32 target needed for Dioxus WASM compilation
RUN rustup target add wasm32-unknown-unknown
# Install dioxus-cli via cargo-binstall for pre-built binaries (much faster than cargo install).
ENV BINSTALL_VERSION=v1.10.22
ARG BINSTALL_SHA256=
RUN curl -L --proto '=https' --tlsv1.2 -sSf \
"https://github.com/cargo-bins/cargo-binstall/releases/download/${BINSTALL_VERSION}/cargo-binstall-$(uname -m)-unknown-linux-musl.tgz" \
-o /tmp/binstall.tgz && \
if [ -n "${BINSTALL_SHA256}" ]; then \
echo "${BINSTALL_SHA256} /tmp/binstall.tgz" | sha256sum -c -; \
else \
echo "WARNING: BINSTALL_SHA256 not set — skipping checksum verification."; \
fi && \
tar xzf /tmp/binstall.tgz -C /usr/local/cargo/bin && \
rm /tmp/binstall.tgz
RUN cargo binstall dioxus-cli --version 0.7.9 -y
# ── Copy all workspace Cargo.toml manifests for dependency caching ──
COPY Cargo.toml Cargo.lock ./
COPY app/web/Cargo.toml ./app/web/Cargo.toml
COPY app/web/Dioxus.toml ./app/web/Dioxus.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 server/Cargo.toml ./server/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/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 'fn main() {}' > app/web/src/main.rs && \
echo 'pub fn placeholder() {}' > app/ui/src/lib.rs && \
echo 'pub fn placeholder() {}' > server/src/lib.rs && \
echo 'fn main() {}' > server/src/main.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/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.
RUN cargo build --package web --target wasm32-unknown-unknown --release || true
# ── Copy real source code ──
COPY app/web/src ./app/web/src
COPY app/web/assets ./app/web/assets
COPY app/ui/src ./app/ui/src
COPY app/ui/assets ./app/ui/assets
COPY crates/i18n/src ./crates/i18n/src
COPY app/client-api/src ./app/client-api/src
# Touch all copied crate source files to invalidate pre-build cache
RUN find app/web/src app/ui/src crates/i18n/src app/client-api/src \
-type f -name '*.rs' -exec touch {} +
# Build the Dioxus frontend (from workspace root for correct path resolution)
WORKDIR /app
RUN dx build --release --package web --platform web
# ── Runtime stage - nginx static file server ──
FROM nginx:alpine AS runtime
# Install curl for health checks
RUN apk add --no-cache curl
# Copy built frontend assets (Dioxus outputs to target/dx/<package>/release/<platform>/public)
COPY --from=builder /app/target/dx/web/release/web/public /usr/share/nginx/html
# Copy default nginx configuration (can be overridden via volume mount)
COPY nginx/default.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]