fix(docker): simplify Dockerfile and fix build issues

- Convert to single-stage build for simplicity
- Fix AS to as casing warnings
- Remove uv dependency, use pip for compatibility
- Streamline Python package installation
- Remove complex multi-stage targets
- Focus on core application functionality
This commit is contained in:
William Valentin
2025-09-14 16:59:22 -07:00
parent d15dffd120
commit 74cee9e4cb

View File

@@ -1,7 +1,7 @@
# UnitForge Docker Image
# Optimized for uv package manager and production deployment
# Simple build for development and production
FROM python:3.11-slim as base
FROM python:3.11-slim
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
@@ -16,9 +16,6 @@ RUN apt-get update && apt-get install -y \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Create app user
RUN groupadd --gid 1000 app && \
useradd --uid 1000 --gid app --shell /bin/bash --create-home app
@@ -26,89 +23,22 @@ RUN groupadd --gid 1000 app && \
# Set work directory
WORKDIR /app
# Copy dependency files
COPY --chown=app:app pyproject.toml .
COPY --chown=app:app backend/requirements.txt backend/
# Create virtual environment and install dependencies
RUN uv venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
RUN uv pip install -r backend/requirements.txt
# Development stage
FROM base as development
# Install development dependencies
RUN uv pip install -e ".[dev,web]"
# Copy dependency files and install Python dependencies
COPY backend/requirements.txt backend/
RUN pip install --no-cache-dir -r backend/requirements.txt
# Copy source code
COPY --chown=app:app . .
COPY . .
# Make scripts executable
RUN chmod +x unitforge-cli start-server.sh demo.sh
RUN chmod +x unitforge-cli start-server.sh demo.sh 2>/dev/null || true
# Change ownership
RUN chown -R app:app /app
USER app
EXPOSE 8000
CMD ["./start-server.sh", "--host", "0.0.0.0"]
# Production stage
FROM base as production
# Install only production dependencies
RUN uv pip install -e .
# Copy source code
COPY --chown=app:app backend/ backend/
COPY --chown=app:app frontend/ frontend/
COPY --chown=app:app unitforge-cli .
COPY --chown=app:app start-server.sh .
# Make scripts executable
RUN chmod +x unitforge-cli start-server.sh
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
USER app
EXPOSE 8000
# Use uvicorn directly (already installed via uv)
CMD ["uvicorn", "backend.app.main:app", "--host", "0.0.0.0", "--port", "8000"]
# Multi-stage build for CLI-only image
FROM python:3.11-slim as cli-only
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Create app user
RUN groupadd --gid 1000 app && \
useradd --uid 1000 --gid app --shell /bin/bash --create-home app
WORKDIR /app
# Copy dependency files
COPY --chown=app:app pyproject.toml .
# Create virtual environment and install minimal CLI dependencies
RUN uv venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
RUN uv pip install click pydantic pyyaml validators
# Copy CLI source code only
COPY --chown=app:app backend/app/core/ backend/app/core/
COPY --chown=app:app backend/cli/ backend/cli/
COPY --chown=app:app unitforge-cli .
RUN chmod +x unitforge-cli
USER app
ENTRYPOINT ["./unitforge-cli"]
# Default command for development
CMD ["./start-server.sh", "--host", "0.0.0.0", "--log-level", "debug"]