-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDockerfile
More file actions
79 lines (60 loc) · 2.03 KB
/
Copy pathDockerfile
File metadata and controls
79 lines (60 loc) · 2.03 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
# Multi-stage Dockerfile for My Rust CMS
# Stage 1: Build the Rust backend
FROM rustlang/rust:nightly-slim as backend-builder
# Install system dependencies for building
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
libpq-dev \
curl \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Copy backend source code and necessary files
COPY backend/ ./backend/
COPY src/ ./src/
COPY Cargo.toml ./
COPY Cargo.lock ./
COPY Diesel.toml ./
COPY migrations/ ./migrations/
COPY docs/ ./docs/
# Create a dummy frontend directory to satisfy workspace requirements
RUN mkdir -p frontend/src && \
echo '[package]\nname = "frontend"\nversion = "0.1.0"\nedition = "2021"\n\n[lib]\nname = "frontend"' > frontend/Cargo.toml && \
echo 'pub fn dummy() {}' > frontend/src/lib.rs
# Build the backend application from the workspace root
RUN cargo build --release -p backend
# Stage 2: Use pre-built frontend files
# Since we already have built frontend files in dist/, we'll use them directly
# This avoids the complexity of building WASM in Docker
# Stage 3: Runtime image
FROM rustlang/rust:nightly-slim
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
libpq5 \
curl \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Create application user
RUN groupadd -r myrustcms && useradd -r -g myrustcms myrustcms
# Set working directory
WORKDIR /app
# Copy the built backend binary
COPY --from=backend-builder /app/target/release/backend ./backend
# Copy the pre-built frontend files from host
COPY dist/ ./dist/
# Copy necessary runtime files
COPY docs/ ./docs/
COPY migrations/ ./migrations/
COPY scripts/ ./scripts/
# Create uploads directory and set permissions
RUN mkdir -p uploads && chown -R myrustcms:myrustcms /app
# Switch to non-root user
USER myrustcms
# Expose port
EXPOSE 8081
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:8081/health || exit 1
# Start the application
CMD ["./backend"]