From 4f265f3e35e096c007701167cae26e26cb3c9906 Mon Sep 17 00:00:00 2001 From: Kye Gomez Date: Mon, 23 Dec 2024 14:31:00 -0800 Subject: [PATCH] [DOCKER] --- .dockerignore | 297 +++++++++++++++++++++++++++++++++++++++++++++++++ .gitignore | 129 +++++++++++++++++++++ Dockerfile | 53 +++++++-- pyproject.toml | 2 +- 4 files changed, 468 insertions(+), 13 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..9b9944a2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,297 @@ +.git +.gitignore +.env +__pycache__ +*.pyc +*.pyo +*.pyd +.Python +env/ +venv/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.log +.pytest_cache/ +.mypy_cache/ + +__pycache__/ +.venv/ + +.env + +image/ +audio/ +video/ +artifacts_three +dataframe/ +.ruff_cache +.pytest_cache +static/generated +runs +Financial-Analysis-Agent_state.json +experimental +artifacts_five +encryption +errors +chroma +agent_workspace +.pt +Accounting Assistant_state.json +Unit Testing Agent_state.json +sec_agent +Devin_state.json +poetry.lock +hire_researchers +agent_workspace +json_logs +Medical Image Diagnostic Agent_state.json +flight agent_state.json +D_state.json +artifacts_six +artifacts_seven +swarms/__pycache__ +artifacts_once +transcript_generator.json +venv +.DS_Store +Cargo.lock +.DS_STORE +artifacts_logs +Cargo.lock +Medical Treatment Recommendation Agent_state.json +swarms/agents/.DS_Store +artifacts_two +logs +T_state.json +_build +conversation.txt +t1_state.json +stderr_log.txt +t2_state.json +.vscode +.DS_STORE +# Byte-compiled / optimized / DLL files +Transcript Generator_state.json +__pycache__/ +*.py[cod] +*$py.class +.grit +swarm-worker-01_state.json +error.txt +Devin Worker 2_state.json +# C extensions +*.so +.ruff_cache + + +errors.txt + +Autonomous-Agent-XYZ1B_state.json +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py +.DS_Store + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ +.vscode/settings.json +# -*- mode: gitignore; -*- +*~ +\#*\# +/.emacs.desktop +/.emacs.desktop.lock +*.elc +auto-save-list +tramp +.\#* + +# Org-mode +.org-id-locations +*_archive + +# flymake-mode +*_flymake.* + +# eshell files +/eshell/history +/eshell/lastdir + +# elpa packages +/elpa/ + +# reftex files +*.rel + +# AUCTeX auto folder +/auto/ + +# cask packages +.cask/ +dist/ + +# Flycheck +flycheck_*.el + +# server auth directory +/server/ + +# projectiles files +.projectile + +# directory configuration +.dir-locals.el + +# network security +/network-security.data + diff --git a/.gitignore b/.gitignore index 65ce495c..418d9a8e 100644 --- a/.gitignore +++ b/.gitignore @@ -273,3 +273,132 @@ flycheck_*.el # network security /network-security.data + + + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ +.vscode/settings.json +# -*- mode: gitignore; -*- +*~ +\#*\# +/.emacs.desktop +/.emacs.desktop.lock +*.elc +auto-save-list +tramp +.\#* + +# Org-mode +.org-id-locations +*_archive + +# flymake-mode +*_flymake.* + +# eshell files +/eshell/history +/eshell/lastdir + +# elpa packages +/elpa/ + +# reftex files +*.rel + +# AUCTeX auto folder +/auto/ + +# cask packages +.cask/ +dist/ + +# Flycheck +flycheck_*.el + +# server auth directory +/server/ + +# projectiles files +.projectile + +# directory configuration +.dir-locals.el + +# network security +/network-security.data + diff --git a/Dockerfile b/Dockerfile index 91c42041..20567ff6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,55 @@ -# Use Python 3.11 instead of 3.13 -FROM python:3.11-slim +# Use Python 3.11 slim-bullseye for smaller base image +FROM python:3.11-slim-bullseye AS builder # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ - WORKSPACE_DIR="agent_workspace" \ - OPENAI_API_KEY="your_swarm_api_key_here" + PIP_NO_CACHE_DIR=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=1 # Set the working directory -WORKDIR /usr/src/swarms +WORKDIR /build -# Install system dependencies -RUN apt-get update && apt-get install -y \ +# 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 package -RUN pip3 install -U swarm-models -RUN pip3 install -U swarms +# Install swarms packages +RUN pip install --no-cache-dir swarm-models swarms + +# Production stage +FROM python:3.11-slim-bullseye + +# Set secure environment variables +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 \ + WORKSPACE_DIR="agent_workspace" \ + PATH="/app:${PATH}" \ + PYTHONPATH="/app:${PYTHONPATH}" \ + USER=swarms + +# Create non-root user +RUN useradd -m -s /bin/bash -U $USER && \ + mkdir -p /app && \ + chown -R $USER:$USER /app + +# Set working directory +WORKDIR /app + +# 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 + +# Copy application with correct permissions +COPY --chown=$USER:$USER . . + +# Switch to non-root user +USER $USER -# Copy the application -COPY . . \ No newline at end of file +# 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 diff --git a/pyproject.toml b/pyproject.toml index a506e5bf..7acbf5ba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,6 +62,7 @@ python = ">=3.10,<4.0" asyncio = ">=3.4.3,<4.0" toml = "*" pypdf = "5.1.0" +swarm-models = "*" loguru = "*" pydantic = "*" tenacity = "*" @@ -79,7 +80,6 @@ reportlab = "*" doc-master = "*" rich = "*" # sentence-transformers = "*" -swarm-models = "*" termcolor = "*"