105 lines
2.3 KiB
Docker
105 lines
2.3 KiB
Docker
# Multi-stage Docker build for Orbital Simulator
|
|
# Stage 1: Build the Rust backend
|
|
FROM rust:1.75-slim as rust-builder
|
|
|
|
# Install system dependencies for building
|
|
RUN apt-get update && apt-get install -y \
|
|
pkg-config \
|
|
libssl-dev \
|
|
libfontconfig1-dev \
|
|
libfreetype6-dev \
|
|
libglib2.0-dev \
|
|
libgtk-3-dev \
|
|
libpango1.0-dev \
|
|
libatk1.0-dev \
|
|
libgdk-pixbuf-2.0-dev \
|
|
libcairo2-dev \
|
|
libasound2-dev \
|
|
libudev-dev \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy Cargo files for dependency caching
|
|
COPY Cargo.toml ./
|
|
COPY build.rs ./
|
|
|
|
# Create dummy source files to build dependencies
|
|
RUN mkdir src && \
|
|
echo "fn main() {}" > src/main.rs && \
|
|
mkdir -p src/bin && \
|
|
echo "fn main() {}" > src/bin/api_server.rs && \
|
|
echo "fn main() {}" > src/bin/simulator.rs && \
|
|
echo "fn main() {}" > src/bin/orbiter.rs
|
|
|
|
# Build dependencies (this layer will be cached)
|
|
RUN cargo build --release --bin api_server
|
|
|
|
# Remove dummy files
|
|
RUN rm -rf src
|
|
|
|
# Copy actual source code
|
|
COPY src ./src
|
|
COPY config ./config
|
|
|
|
# Build the actual application
|
|
RUN cargo build --release --bin api_server
|
|
|
|
# Stage 2: Build the React frontend
|
|
FROM node:18-alpine as frontend-builder
|
|
|
|
WORKDIR /app/web
|
|
|
|
# Copy package files for dependency caching
|
|
COPY web/package.json web/package-lock.json ./
|
|
|
|
# Install dependencies
|
|
RUN npm ci
|
|
|
|
# Copy source files
|
|
COPY web/ ./
|
|
|
|
# Build the frontend
|
|
RUN npm run build
|
|
|
|
# Stage 3: Runtime image
|
|
FROM debian:bookworm-slim
|
|
|
|
# Install runtime dependencies
|
|
RUN apt-get update && apt-get install -y \
|
|
ca-certificates \
|
|
libssl3 \
|
|
curl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Create app user
|
|
RUN useradd -r -s /bin/false appuser
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy the built Rust binary
|
|
COPY --from=rust-builder /app/target/release/api_server ./api_server
|
|
|
|
# Copy configuration files
|
|
COPY --from=rust-builder /app/config ./config
|
|
|
|
# Copy the built frontend
|
|
COPY --from=frontend-builder /app/web/dist ./web/dist
|
|
|
|
# Create necessary directories
|
|
RUN mkdir -p logs && \
|
|
chown -R appuser:appuser /app
|
|
|
|
# Switch to non-root user
|
|
USER appuser
|
|
|
|
# Expose port
|
|
EXPOSE 4395
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
CMD curl -f http://localhost:4395/api/configs || exit 1
|
|
|
|
# Start the application
|
|
CMD ["./api_server"]
|