fix to build and run ci/cd, 2nd attempt fix to build and run ci/cd, 3rd attempt fix to build and run ci/cd, 4th attempt fix to build and run ci/cd, 5th attempt fix to build and run ci/cd, 6th attempt fix to build and run ci/cd, 7th attempt fix to build and run ci/cd, 8th attempt fix to build and run ci/cd, 9th attempt fix to build and run ci/cd, 10th attempt fix to build and run ci/cd, 11th attempt fix to build and run ci/cd, 12th attempt fix to build and run ci/cd, 13th attempt fix to build and run ci/cd, 14th attempt fix to build and run ci/cd, 15th attempt commit commitpull/700/head
parent
eeb78957af
commit
cdc2b6f5dc
@ -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
|
|
||||||
WORKDIR /build
|
|
||||||
|
|
||||||
# Install only essential build dependencies
|
# Set the working directory to the root of the project (relative to pyproject.toml)
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
WORKDIR /usr/src/app
|
||||||
build-essential \
|
|
||||||
gcc \
|
|
||||||
g++ \
|
|
||||||
gfortran \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# Install swarms packages
|
# Copy the entire project into the container
|
||||||
RUN pip install --no-cache-dir swarm-models swarms
|
COPY . .
|
||||||
|
|
||||||
# Production stage
|
# Install Poetry
|
||||||
FROM python:3.11-slim-bullseye
|
RUN pip install poetry
|
||||||
|
|
||||||
# Set secure environment variables
|
# Configure Poetry to avoid virtual environments and install dependencies
|
||||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
RUN poetry config virtualenvs.create false && poetry install --no-interaction --no-ansi
|
||||||
PYTHONUNBUFFERED=1 \
|
|
||||||
WORKSPACE_DIR="agent_workspace" \
|
|
||||||
PATH="/app:${PATH}" \
|
|
||||||
PYTHONPATH="/app:${PYTHONPATH}" \
|
|
||||||
USER=swarms
|
|
||||||
|
|
||||||
# Create non-root user
|
# Install additional dependencies outside Poetry (e.g., swarms, pytest)
|
||||||
RUN useradd -m -s /bin/bash -U $USER && \
|
RUN pip install swarms pytest
|
||||||
mkdir -p /app && \
|
|
||||||
chown -R $USER:$USER /app
|
|
||||||
|
|
||||||
# Set working directory
|
# Ensure pytest is installed and available
|
||||||
WORKDIR /app
|
RUN pytest --version
|
||||||
|
|
||||||
# Copy only necessary files from builder
|
# Ensure the logs directory has correct permissions (in case of permission issues with mounted volumes)
|
||||||
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
|
RUN mkdir -p /usr/src/app/logs && chmod -R 777 /usr/src/app/logs
|
||||||
COPY --from=builder /usr/local/bin /usr/local/bin
|
|
||||||
|
|
||||||
# Copy application with correct permissions
|
# Ensure that the PATH includes the directory where pytest is installed
|
||||||
COPY --chown=$USER:$USER . .
|
ENV PATH="/usr/local/bin:$PATH"
|
||||||
|
|
||||||
# Switch to non-root user
|
# Set the working directory to the tests directory inside the container
|
||||||
USER $USER
|
WORKDIR /usr/src/app/tests
|
||||||
|
|
||||||
# Health check
|
# Default command to run tests located in the /tests directory
|
||||||
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
CMD pytest /usr/src/app/tests --continue-on-collection-errors --tb=short --disable-warnings | tee /usr/src/app/logs/test_logs.txt
|
||||||
CMD python -c "import swarms; print('Health check passed')" || exit 1
|
|
||||||
|
Loading…
Reference in new issue