Add Docker support with Alpine Linux

- 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 <noreply@anthropic.com>
This commit is contained in:
Connor Johnstone
2025-08-28 14:53:25 -04:00
parent a507ab07be
commit 0f4b505acd
2 changed files with 95 additions and 0 deletions

28
.dockerignore Normal file
View File

@@ -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

67
Dockerfile Normal file
View File

@@ -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;"]