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