pull/700/head
Patrick Devaney 6 days ago
parent 9637a6ec04
commit bf0e503161

@ -15,15 +15,12 @@ jobs:
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Checkout repository
uses: actions/checkout@v2
# Set up Docker Buildx (optional, for multi-platform support)
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Cache Docker layers to speed up builds (optional)
- name: Cache Docker layers
uses: actions/cache@v2
with:
@ -32,29 +29,24 @@ jobs:
restore-keys: |
${{ runner.os }}-buildx-
# Build Docker image from the root directory
- name: Build Docker image
id: build_image
run: |
IMAGE_TAG="test-runner:swarm-testing-${GITHUB_SHA}"
docker build -t $IMAGE_TAG .
docker build -t $IMAGE_TAG -f ./tests/Dockerfile .
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
# Ensure logs directory exists and has correct permissions
- name: Ensure logs directory exists
- name: Create logs directory
run: |
mkdir -p ${{ github.workspace }}/logs
chmod -R 777 ${{ github.workspace }}/logs
# Run Docker container with OpenAI API Key securely and capture test logs
- name: Run Docker container with OpenAI API Key
- name: Run tests in Docker
run: |
docker run -e OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} \
docker run --rm \
-e OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} \
-v ${{ github.workspace }}/logs:/usr/src/app/logs \
${{ env.IMAGE_TAG }} \
bash -c "pytest /usr/src/app/tests --continue-on-collection-errors --tb=short --disable-warnings | tee /usr/src/app/logs/test_logs.txt"
/usr/src/app/tests --continue-on-collection-errors --tb=short --disable-warnings | tee ${{ github.workspace }}/logs/test_logs.txt
# Print the test logs to the console
- name: Print test logs
run: |
cat ${{ github.workspace }}/logs/test_logs.txt || echo "No test logs found"
run: cat ${{ github.workspace }}/logs/test_logs.txt || echo "No test logs found"

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