# Build stage # --------------------------------------- FROM rust:alpine AS builder # Install build dependencies RUN apk add --no-cache \ musl-dev \ pkgconfig \ openssl-dev \ nodejs \ npm # Install trunk for building Yew apps RUN cargo install trunk wasm-pack # Add wasm32 target RUN rustup target add wasm32-unknown-unknown # Set working directory WORKDIR /app # Copy dependency files COPY Cargo.toml ./ COPY src ./src # Copy web assets COPY index.html ./ COPY Trunk.toml ./ # Build the application RUN trunk build --release # Runtime stage # --------------------------------------- FROM docker.io/nginx:alpine # Remove default nginx content RUN rm -rf /usr/share/nginx/html/* # Copy built application from builder stage COPY --from=builder /app/dist/* /usr/share/nginx/html/ # Add nginx configuration for SPA RUN echo 'server { \ listen 80; \ server_name localhost; \ root /usr/share/nginx/html; \ index index.html; \ location / { \ try_files $uri $uri/ /index.html; \ } \ # Enable gzip compression \ gzip on; \ gzip_types text/css application/javascript application/wasm; \ }' > /etc/nginx/conf.d/default.conf # Expose port EXPOSE 80 # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD wget --quiet --tries=1 --spider http://localhost/ || exit 1 # Start nginx CMD ["nginx", "-g", "daemon off;"]