From 0f4b505acd2c2048bc171ddfd1264acee4f916ed Mon Sep 17 00:00:00 2001 From: Connor Johnstone Date: Thu, 28 Aug 2025 14:53:25 -0400 Subject: [PATCH] Add Docker support with Alpine Linux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Multi-stage Dockerfile with rust:alpine and nginx:alpine - Optimized for small container size (~20MB) - Includes SPA routing support and gzip compression - Health check for container monitoring - .dockerignore to optimize build context 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .dockerignore | 28 +++++++++++++++++++++ Dockerfile | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6a70aa1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,28 @@ +# Build artifacts +target/ +dist/ + +# Git +.git/ +.gitignore + +# IDE +.vscode/ +.idea/ +*.swp +*.swo + +# OS +.DS_Store +Thumbs.db + +# Logs +*.log + +# Documentation +README.md +*.md + +# Docker +Dockerfile +.dockerignore \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..05b4793 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,67 @@ +# 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;"]