-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathDockerfile.production
More file actions
123 lines (100 loc) · 3.96 KB
/
Dockerfile.production
File metadata and controls
123 lines (100 loc) · 3.96 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
118
119
120
121
122
123
FROM nvidia/cuda:12.8.1-devel-ubuntu22.04 as builder
ENV DEBIAN_FRONTEND=noninteractive \
RUST_LOG=warn \
PATH="/root/.cargo/bin:${PATH}" \
NVIDIA_DRIVER_CAPABILITIES=all \
CUDA_HOME=/usr/local/cuda \
NODE_ENV=production
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
git \
build-essential \
gcc-11 \
g++-11 \
pkg-config \
libssl-dev \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Set gcc-11 as default compiler (needed for CUDA compilation)
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 \
&& update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100
# Install Node.js
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y nodejs
# Install Rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
# Create app directory
WORKDIR /build
# Copy Rust files for server build
COPY Cargo.toml Cargo.lock ./
COPY src ./src
# Copy client files for frontend build
COPY client ./client
# Build client (production mode)
WORKDIR /build/client
# Temporarily set NODE_ENV=development for install to ensure devDeps, then run build
RUN NODE_ENV=development npm install && \
npm run build
# Build Rust server (release mode with GPU features)
WORKDIR /build
RUN cargo build --release --features gpu
# Handle PTX compilation
# Ensure the script and the .cu file are in expected locations relative to WORKDIR /build
COPY scripts/compile_ptx.sh ./scripts/compile_ptx.sh
# The main `COPY src ./src` at line 38 should already make ./src/utils/compute_forces.cu available.
# If compile_ptx.sh expects paths relative to where it is, adjust accordingly or ensure it uses absolute paths or paths relative to WORKDIR.
# Assuming compile_ptx.sh uses paths relative to WORKDIR /build, like "src/utils/compute_forces.cu"
# First try to copy existing PTX file from the build context (host)
# This allows using a pre-compiled PTX if available and REBUILD_PTX is false.
COPY src/utils/compute_forces.ptx /build/src/utils/compute_forces.ptx
ARG REBUILD_PTX=false
ARG CUDA_ARCH=89
RUN chmod +x ./scripts/compile_ptx.sh && \
if [ "$REBUILD_PTX" = "true" ] || [ ! -f "/build/src/utils/compute_forces.ptx" ]; then \
echo "Compiling PTX file for sm_${CUDA_ARCH} using compile_ptx.sh..." && \
# Pass CUDA_ARCH as an environment variable to the script
CUDA_ARCH=${CUDA_ARCH} ./scripts/compile_ptx.sh && \
echo "PTX compilation via script successful"; \
else \
echo "Using existing PTX file: /build/src/utils/compute_forces.ptx"; \
fi
# Ensure the PTX file is in the correct final location for the COPY to runtime stage
# The compile_ptx.sh script writes to "src/utils/compute_forces.ptx" relative to its execution dir.
# If script is in /build/scripts/ and WORKDIR is /build, it writes to /build/src/utils/compute_forces.ptx
# Second stage: runtime image
FROM nvidia/cuda:12.8.1-runtime-ubuntu22.04
ENV DEBIAN_FRONTEND=noninteractive \
RUST_LOG=warn \
NODE_ENV=production \
NVIDIA_DRIVER_CAPABILITIES=all
# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
nginx \
ca-certificates \
nodejs \
npm \
&& rm -rf /var/lib/apt/lists/*
# Create app directory
WORKDIR /app
# Create necessary directories
RUN mkdir -p /app/data/markdown \
/app/data/metadata \
/app/data/runtime \
/app/user_settings \
/app/client/dist \
/app/src/utils
# Copy built artifacts from builder stage
COPY --from=builder /build/target/release/webxr /app/webxr
COPY --from=builder /build/client/dist /app/client/dist
COPY --from=builder /build/src/utils/compute_forces.ptx /app/src/utils/compute_forces.ptx
# Copy nginx configuration
COPY nginx.conf /etc/nginx/nginx.conf
# Copy startup script
COPY scripts/start.sh /app/start.sh
RUN chmod +x /app/start.sh
# Expose port
EXPOSE 4000
# Set entrypoint
ENTRYPOINT ["/app/start.sh"]