parent
9637a6ec04
commit
bf0e503161
@ -1,55 +1,39 @@
|
|||||||
# Use Python 3.11 slim-bullseye for smaller base image
|
# Use an official Python runtime as a parent image
|
||||||
FROM python:3.11-slim-bullseye AS builder
|
FROM python:3.11-slim-bullseye
|
||||||
|
|
||||||
# Set environment variables
|
# Set environment variables for Python behavior
|
||||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||||
PYTHONUNBUFFERED=1 \
|
PYTHONUNBUFFERED=1 \
|
||||||
PIP_NO_CACHE_DIR=1 \
|
PIP_NO_CACHE_DIR=1 \
|
||||||
PIP_DISABLE_PIP_VERSION_CHECK=1
|
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
||||||
|
PIP_DEFAULT_TIMEOUT=100
|
||||||
|
|
||||||
# Set the working directory
|
# Set the working directory
|
||||||
WORKDIR /build
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
# Install only essential build dependencies
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
||||||
build-essential \
|
|
||||||
gcc \
|
|
||||||
g++ \
|
|
||||||
gfortran \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# Install swarms packages
|
|
||||||
RUN pip install --no-cache-dir swarm-models swarms
|
|
||||||
|
|
||||||
# Production stage
|
|
||||||
FROM python:3.11-slim-bullseye
|
|
||||||
|
|
||||||
# Set secure environment variables
|
# Copy the entire project into the container
|
||||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
COPY . .
|
||||||
PYTHONUNBUFFERED=1 \
|
|
||||||
WORKSPACE_DIR="agent_workspace" \
|
|
||||||
PATH="/app:${PATH}" \
|
|
||||||
PYTHONPATH="/app:${PYTHONPATH}" \
|
|
||||||
USER=swarms
|
|
||||||
|
|
||||||
# Create non-root user
|
# Install system dependencies
|
||||||
RUN useradd -m -s /bin/bash -U $USER && \
|
RUN apt-get update && \
|
||||||
mkdir -p /app && \
|
apt-get install -y --no-install-recommends \
|
||||||
chown -R $USER:$USER /app
|
git \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Set working directory
|
# Install Poetry and dependencies
|
||||||
WORKDIR /app
|
RUN pip install --no-cache-dir poetry pytest
|
||||||
|
|
||||||
# Copy only necessary files from builder
|
# Install project dependencies
|
||||||
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
|
RUN poetry config virtualenvs.create false && \
|
||||||
COPY --from=builder /usr/local/bin /usr/local/bin
|
poetry install --no-interaction --no-ansi
|
||||||
|
|
||||||
# Copy application with correct permissions
|
# Create logs directory with proper permissions
|
||||||
COPY --chown=$USER:$USER . .
|
RUN mkdir -p /usr/src/app/logs && chmod -R 777 /usr/src/app/logs
|
||||||
|
|
||||||
# Switch to non-root user
|
# Add pytest to PATH and verify installation
|
||||||
USER $USER
|
ENV PATH="/usr/local/bin:/root/.local/bin:$PATH"
|
||||||
|
RUN python -m pytest --version
|
||||||
|
|
||||||
# Health check
|
# Set the default command
|
||||||
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
ENTRYPOINT ["pytest"]
|
||||||
CMD python -c "import swarms; print('Health check passed')" || exit 1
|
CMD ["/usr/src/app/tests", "--continue-on-collection-errors", "--tb=short", "--disable-warnings"]
|
Loading…
Reference in new issue