From cdc2b6f5dc76bfc9ae2411c95ffa6247cbe82172 Mon Sep 17 00:00:00 2001 From: Patrick Devaney Date: Thu, 2 Jan 2025 02:11:07 -0500 Subject: [PATCH] fix to build and run ci/cd 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 commit --- .env.example | 2 +- .github/workflows/docker-test.yml | 24 ++++++++--- .gitignore | 3 ++ Dockerfile | 66 ++++++++++++------------------- tests/Dockerfile | 14 ++++++- 5 files changed, 61 insertions(+), 48 deletions(-) diff --git a/.env.example b/.env.example index be8d1255..a58dd7eb 100644 --- a/.env.example +++ b/.env.example @@ -28,4 +28,4 @@ AZURE_OPENAI_ENDPOINT=your_azure_openai_endpoint AZURE_OPENAI_DEPLOYMENT=your_azure_openai_deployment OPENAI_API_VERSION=your_openai_api_version AZURE_OPENAI_API_KEY=your_azure_openai_api_key -AZURE_OPENAI_AD_TOKEN=your_azure_openai_ad_token +AZURE_OPENAI_AD_TOKEN=your_azure_openai_ad_token \ No newline at end of file diff --git a/.github/workflows/docker-test.yml b/.github/workflows/docker-test.yml index 8445d713..26926046 100644 --- a/.github/workflows/docker-test.yml +++ b/.github/workflows/docker-test.yml @@ -4,9 +4,11 @@ on: push: branches: - main + - master pull_request: branches: - main + - master jobs: test: @@ -30,17 +32,29 @@ jobs: restore-keys: | ${{ runner.os }}-buildx- - # Build Docker image from the ./tests directory + # Build Docker image from the root directory - name: Build Docker image + id: build_image run: | - docker build -t test-runner:swarm-testing ./tests + IMAGE_TAG="test-runner:swarm-testing-${GITHUB_SHA}" + docker build -t $IMAGE_TAG . + echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV - # Ensure logs directory exists in the GitHub workspace + # Ensure logs directory exists and has correct permissions - name: Ensure logs directory exists run: | mkdir -p ${{ github.workspace }}/logs + chmod -R 777 ${{ github.workspace }}/logs - # Run Docker container with OpenAI API Key securely + # Run Docker container with OpenAI API Key securely and capture test logs - name: Run Docker container with OpenAI API Key run: | - docker run -e OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} -v ${{ github.workspace }}/logs:/usr/src/app/logs test-runner:swarm-testing + docker run -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" + + # Print the test logs to the console + - name: Print test logs + run: | + cat ${{ github.workspace }}/logs/test_logs.txt || echo "No test logs found" diff --git a/.gitignore b/.gitignore index 65ce495c..2e23ba6e 100644 --- a/.gitignore +++ b/.gitignore @@ -273,3 +273,6 @@ flycheck_*.el # network security /network-security.data +swarmsenv/ + +test_fails.txt \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 20567ff6..80d2fbb8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 - -# Set the working directory -WORKDIR /build + PIP_DISABLE_PIP_VERSION_CHECK=1 \ + PIP_DEFAULT_TIMEOUT=100 -# 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/* +# Set the working directory to the root of the project (relative to pyproject.toml) +WORKDIR /usr/src/app -# Install swarms packages -RUN pip install --no-cache-dir swarm-models swarms +# Copy the entire project into the container +COPY . . -# Production stage -FROM python:3.11-slim-bullseye +# Install Poetry +RUN pip install poetry -# Set secure environment variables -ENV PYTHONDONTWRITEBYTECODE=1 \ - PYTHONUNBUFFERED=1 \ - WORKSPACE_DIR="agent_workspace" \ - PATH="/app:${PATH}" \ - PYTHONPATH="/app:${PYTHONPATH}" \ - USER=swarms +# Configure Poetry to avoid virtual environments and install dependencies +RUN poetry config virtualenvs.create false && poetry install --no-interaction --no-ansi -# Create non-root user -RUN useradd -m -s /bin/bash -U $USER && \ - mkdir -p /app && \ - chown -R $USER:$USER /app +# Install additional dependencies outside Poetry (e.g., swarms, pytest) +RUN pip install swarms pytest -# Set working directory -WORKDIR /app +# Ensure pytest is installed and available +RUN pytest --version -# 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 +# Ensure the logs directory has correct permissions (in case of permission issues with mounted volumes) +RUN mkdir -p /usr/src/app/logs && chmod -R 777 /usr/src/app/logs -# Copy application with correct permissions -COPY --chown=$USER:$USER . . +# Ensure that the PATH includes the directory where pytest is installed +ENV PATH="/usr/local/bin:$PATH" -# Switch to non-root user -USER $USER +# Set the working directory to the tests directory inside the container +WORKDIR /usr/src/app/tests -# Health check -HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ - CMD python -c "import swarms; print('Health check passed')" || exit 1 \ No newline at end of file +# Default command to run tests located in the /tests directory +CMD pytest /usr/src/app/tests --continue-on-collection-errors --tb=short --disable-warnings | tee /usr/src/app/logs/test_logs.txt diff --git a/tests/Dockerfile b/tests/Dockerfile index 4c133c32..80d2fbb8 100644 --- a/tests/Dockerfile +++ b/tests/Dockerfile @@ -23,5 +23,17 @@ RUN poetry config virtualenvs.create false && poetry install --no-interaction -- # Install additional dependencies outside Poetry (e.g., swarms, pytest) RUN pip install swarms pytest +# Ensure pytest is installed and available +RUN pytest --version + +# Ensure the logs directory has correct permissions (in case of permission issues with mounted volumes) +RUN mkdir -p /usr/src/app/logs && chmod -R 777 /usr/src/app/logs + +# Ensure that the PATH includes the directory where pytest is installed +ENV PATH="/usr/local/bin:$PATH" + +# Set the working directory to the tests directory inside the container +WORKDIR /usr/src/app/tests + # Default command to run tests located in the /tests directory -CMD pytest /usr/src/app/tests --continue-on-collection-errors --tb=short --disable-warnings | tee /usr/src/app/test_logs.txt +CMD pytest /usr/src/app/tests --continue-on-collection-errors --tb=short --disable-warnings | tee /usr/src/app/logs/test_logs.txt