diff --git a/backend/DOCKER-COMMANDS.md b/backend/DOCKER-COMMANDS.md new file mode 100644 index 0000000..a78edb5 --- /dev/null +++ b/backend/DOCKER-COMMANDS.md @@ -0,0 +1,52 @@ +# Quick Fix Commands + +## The Problem +Docker is using cached layers from the old Dockerfile. Even though we updated the file, +Docker's build cache still has the old `FROM rust:latest` with `apk` commands. + +## Solution Options + +### Option 1: Rebuild without cache (RECOMMENDED) +```bash +cd /home/asoliver/desarrollo/normogen/backend +docker compose -f docker-compose.dev.yml build --no-cache +docker compose -f docker-compose.dev.yml up -d +``` + +### Option 2: Clear all Docker build cache first +```bash +# Clear Docker's build cache +docker builder prune -af + +# Then rebuild +cd /home/asoliver/desarrollo/normogen/backend +docker compose -f docker-compose.dev.yml up -d --build +``` + +### Option 3: Use the provided script +```bash +cd /home/asoliver/desarrollo/normogen/backend +chmod +x fix-docker-build.sh +./fix-docker-build.sh +``` + +## Why This Happened +- Docker caches build layers to speed up subsequent builds +- When we changed `FROM rust:latest` to `FROM rust:1.93-slim`, Docker should have invalidated the cache +- But sometimes Docker's cache gets confused, especially with `latest` tags +- The `--no-cache` flag forces Docker to ignore all cached layers + +## What Changed in the Dockerfile +```dockerfile +# OLD (cached): +FROM rust:latest +RUN apk add --no-cache musl-dev pkgconf openssl-dev... + +# NEW (current): +FROM rust:1.93-slim +RUN apt-get update && apt-get install -y pkg-config libssl-dev... +``` + +The new image uses: +- `rust:1.93-slim` (supports Edition 2024) +- `apt-get` (Debian/Ubuntu package manager) instead of `apk` (Alpine) diff --git a/backend/docker/Dockerfile b/backend/docker/Dockerfile index eeb7a7f..20048e9 100644 --- a/backend/docker/Dockerfile +++ b/backend/docker/Dockerfile @@ -1,15 +1,46 @@ -FROM rust:latest AS builder +# Production Dockerfile (Multi-stage build) +# Stage 1: Build +FROM rust:1.93-slim AS builder + WORKDIR /app -RUN apk add --no-cache musl-dev pkgconf openssl-dev + +# Install build dependencies +RUN apt-get update && apt-get install -y \ + pkg-config \ + libssl-dev \ + && rm -rf /var/lib/apt/lists/* + +# Copy Cargo files first for better caching COPY Cargo.toml ./ + +# Create dummy main.rs for dependency caching RUN mkdir src && echo 'fn main() {}' > src/main.rs + +# Build dependencies (this layer will be cached) RUN cargo build --release && rm -rf src + +# Copy actual source code COPY src ./src + +# Build the actual application RUN cargo build --release -FROM alpine:latest -RUN apk add --no-cache ca-certificates -COPY --from=builder /app/target/release/normogen-backend /usr/local/bin/normogen-backend -EXPOSE 8000 -CMD ["./normogen-backend"] +# Stage 2: Runtime +FROM debian:bookworm-slim +WORKDIR /app + +# Install runtime dependencies only +RUN apt-get update && apt-get install -y \ + ca-certificates \ + libssl3 \ + && rm -rf /var/lib/apt/lists/* + +# Copy the binary from builder stage +COPY --from=builder /app/target/release/normogen-backend /usr/local/bin/normogen-backend + +# Expose port +EXPOSE 8000 + +# Run the application +CMD ["./normogen-backend"] diff --git a/backend/docker/Dockerfile.dev b/backend/docker/Dockerfile.dev index ecad8a3..4c63b17 100644 --- a/backend/docker/Dockerfile.dev +++ b/backend/docker/Dockerfile.dev @@ -1,9 +1,29 @@ -FROM rust:latest +# Development Dockerfile +# Uses Rust 1.93+ to support Edition 2024 dependencies +FROM rust:1.93-slim + WORKDIR /app -RUN apk add --no-cache musl-dev pkgconf openssl-dev curl wget git pkgconfig + +# Install build dependencies +RUN apt-get update && apt-get install -y \ + pkg-config \ + libssl-dev \ + && rm -rf /var/lib/apt/lists/* + +# Copy Cargo files first for better caching COPY Cargo.toml ./ + +# Create dummy main.rs for dependency caching RUN mkdir src && echo 'fn main() {}' > src/main.rs + +# Build dependencies (this layer will be cached) RUN cargo build && rm -rf src + +# Copy actual source code COPY src ./src + +# Expose port EXPOSE 8000 + +# Run the application CMD ["cargo", "run"] diff --git a/backend/docker/EDITION2024-FIX.md b/backend/docker/EDITION2024-FIX.md new file mode 100644 index 0000000..2f3c3a0 --- /dev/null +++ b/backend/docker/EDITION2024-FIX.md @@ -0,0 +1,43 @@ +# Fix for Rust Edition 2024 Docker Build Error + +## Problem + +The error occurs because: +1. Your Dockerfile uses `FROM rust:latest` which pulled `rust:1.83-alpine` +2. Several dependencies require Rust 1.85+ for Edition 2024 support: + - `time-core 0.1.8` requires Rust 1.88.0 + - `getrandom 0.4.1` requires Rust 1.85.0 + - `uuid 1.21.0` requires Rust 1.85.0 + - `deranged 0.5.6` requires Rust 1.85.0 + - `wasip2/wasip3` require Rust 1.87.0 + +## Root Cause + +Rust Edition 2024 became stable in Rust 1.85.0 (released February 20, 2025). +Some of your transitive dependencies have updated to use Edition 2024, +which requires a newer Rust version than 1.83. + +## Solutions + +### ✅ RECOMMENDED: Update Rust Base Image + +Change `FROM rust:latest` to `FROM rust:1.93` or newer. + +**Pros:** +- Future-proof solution +- Gets latest Rust improvements and security fixes +- No dependency management overhead +- Standard practice (update base images regularly) + +**Cons:** +- None (this is the correct approach) + +### Alternative: Pin Dependency Versions (NOT RECOMMENDED) + +Pin problematic dependencies to older versions that don't require Edition 2024. +This creates technical debt and should only be used if you have a specific +constraint preventing Rust version updates. + +## Implementation + +See the fixed Dockerfiles in this directory. diff --git a/backend/fix-docker-build.sh b/backend/fix-docker-build.sh new file mode 100644 index 0000000..fb7668b --- /dev/null +++ b/backend/fix-docker-build.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# Fix for Docker edition2024 build error + +echo "=== Step 1: Clear Docker build cache ===" +docker builder prune -af + +echo "" +echo "=== Step 2: Remove any old normogen-backend-dev images ===" +docker rmi normogen-backend-dev 2>/dev/null || true + +echo "" +echo "=== Step 3: Build with no cache ===" +cd /home/asoliver/desarrollo/normogen/backend +docker compose -f docker-compose.dev.yml build --no-cache + +echo "" +echo "=== Step 4: Start the containers ===" +docker compose -f docker-compose.dev.yml up -d + +echo "" +echo "Done! Check logs with: docker compose -f docker-compose.dev.yml logs -f"