diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..ba90cb3f5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,98 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-egg/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# 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 +pytest_cache/ +cover/ +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask instance folder +instance/ + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# Environment variables +.env + +# Virtual environment +venv/ +.venv/ +ENV/ + +# Spyder project settings +.spyderproject +.spyproject + +# VS Code settings +.vscode/ + +# PyCharm +.idea/ + +# Operating system files +.DS_Store +Thumbs.db + +# Git directory +.git/ diff --git a/.gitignore b/.gitignore index f851dbab6..0dc30e29f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ .vscode # env -.env/ +.env .venv/ env/ venv/ diff --git a/Dockerfile b/Dockerfile index c480cd1ad..065865d52 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,26 @@ # Start with a Python 3.9 base image FROM python:3.9-slim -# Set the working directory in the container -WORKDIR /app - -# Copy the current directory contents into the container at /app -COPY . /app - # Install necessary libraries for GUI support RUN apt-get update && apt-get install -y python3-tk x11-apps -# Install the project dependencies +# Set the working directory in the container +WORKDIR /app + +# Copy only the requirements file and install dependencies +COPY requirements.txt ./ RUN pip install --no-cache-dir -r requirements.txt +# Copy the rest of the application code +COPY . . + # Set the environment variable for OpenAI API key # (you'll need to provide the actual key when running the container) -ENV OPENAI_API_KEY=your_OpenAI_API_key +ENV OPENAI_API_KEY= # Expose the port for visualizer/app.py EXPOSE 8000 -# Set an entry point that runs a shell for interactive mode -ENTRYPOINT ["/bin/bash"] \ No newline at end of file +ARG DEFAULT_CMD= +ENV COMMAND=${DEFAULT_CMD:-/bin/bash} +CMD ${COMMAND} diff --git a/dev.Dockerfile b/dev.Dockerfile new file mode 100644 index 000000000..daf00a7b4 --- /dev/null +++ b/dev.Dockerfile @@ -0,0 +1,20 @@ +# Start with a Python 3.9 base image +FROM python:3.9-slim + +# Install necessary libraries for GUI support +RUN apt-get update && apt-get install -y python3-tk x11-apps + +# Set the working directory in the container +WORKDIR /app + +# Copy only the requirements file and install dependencies +COPY requirements.txt ./ +RUN pip install --no-cache-dir -r requirements.txt + +# No need to copy the rest of the application code as we use bind mounts +# COPY . . + +# Expose the port for online_log/app.py +EXPOSE 8000 + +CMD ["/bin/bash"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100755 index 000000000..3eb01851d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +services: + chatdev: + build: + context: . + dockerfile: dev.Dockerfile + command: ${DEFAULT_CMD:-/bin/bash} + environment: + - DISPLAY=host.docker.internal:0.0 + env_file: + - ./.env + ports: + - "${PORT:-8000}:8000" + stdin_open: true + tty: true + volumes: + - .:/app diff --git a/wiki.md b/wiki.md index 688f7f188..0fd07680d 100644 --- a/wiki.md +++ b/wiki.md @@ -128,9 +128,55 @@ then start building a software by ``python3 run.py`` and go to [Visualizer Websi ```commandline docker cp container_id:/path/in/container /path/on/host ``` + +### Packaging Your Software into a Docker Image +- Build the image: + ```commandline + docker build --build-arg "DEFAULT_CMD=python3 online_log/app.py" -t chatdev:latest . + ``` + Make sure you replace: + - `online_log/app.py` with the relative path to your Python application's entry point. + - `chatdev` with a name that you want to give to your Docker image. + +- Test the image: + ```commandline + docker run -itp 8000:8000 chatdev:latest + ``` + Ensure you replace `chatdev` with the name you used when building the image. + ### Official Docker Image - in preparation +## Start the Application with Docker Compose + +To run your ChatDev application with Docker Compose, simply: + +1. In the project root, create a `.env` with your text editor. +2. Add `OPENAI_API_KEY=` and any other secrets. +3. Save the file. It's ignored by Git for your security. +4. Run the application with the specified command. + + docker compose run --service-ports chatdev + ``` + This command will build the Docker image (if necessary) and start the container. + + +Any changes you make to the project files on your host machine will sync in real-time inside the container, thanks to the configured bind mount in `docker-compose.yml`. + +### Stopping the Application + +To stop the Docker Compose session: + +- Press `Ctrl + C` in the terminal where Docker Compose is actively running. + +This will gracefully stop the running services. If you want to remove all the containers, networks, and the default network created by Docker Compose, you can follow up with the command: + +```commandline +docker compose down +``` + +Stopping the containers does not affect the persistency of your files; all your changes remain intact in the local directory on your host machine. + ## Experiential Co-Learning Guide ### Co-Tracking