The builder stage installed dependencies to /root/.local but the final stage switched to the 'aegis' user who couldn't access /root/.local. Fixed by copying dependencies to /home/aegis/.local and updating PATH to point to the correct location.
54 lines
1.3 KiB
Docker
54 lines
1.3 KiB
Docker
# Multi-stage build for AegisGitea MCP Server
|
|
FROM python:3.11-slim as builder
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Install build dependencies
|
|
RUN apt-get update && \
|
|
apt-get install -y --no-install-recommends \
|
|
gcc \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy requirements
|
|
COPY requirements.txt .
|
|
|
|
# Install Python dependencies
|
|
RUN pip install --no-cache-dir --user -r requirements.txt
|
|
|
|
# Final stage
|
|
FROM python:3.11-slim
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Create non-root user for security
|
|
RUN useradd -m -u 1000 -s /bin/bash aegis
|
|
|
|
# Copy Python dependencies from builder to aegis user's home
|
|
COPY --from=builder --chown=aegis:aegis /root/.local /home/aegis/.local
|
|
|
|
# Copy application code
|
|
COPY --chown=aegis:aegis src/ ./src/
|
|
|
|
# Create directory for audit logs
|
|
RUN mkdir -p /var/log/aegis-mcp && \
|
|
chown -R aegis:aegis /var/log/aegis-mcp
|
|
|
|
# Switch to non-root user
|
|
USER aegis
|
|
|
|
# Add user's local bin to PATH
|
|
ENV PATH=/home/aegis/.local/bin:$PATH
|
|
ENV PYTHONPATH=/app/src:$PYTHONPATH
|
|
|
|
# Expose MCP server port
|
|
EXPOSE 8080
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD python -c "import httpx; httpx.get('http://localhost:8080/health')" || exit 1
|
|
|
|
# Run server
|
|
CMD ["python", "-m", "aegis_gitea_mcp.server"]
|