From bd17b4d98bffd12896d83fc8734c0b3d53a6762f Mon Sep 17 00:00:00 2001 From: teamchong <25894545+teamchong@users.noreply.github.com> Date: Thu, 2 Nov 2023 22:09:31 -0400 Subject: [PATCH 01/12] feat: Add docker compose for better DX --- .env.sample | 1 + .gitignore | 2 +- Dockerfile | 21 +++++++++++---------- Dockerfile.dev | 25 +++++++++++++++++++++++++ docker-compose.yml | 15 +++++++++++++++ wiki.md | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 85 insertions(+), 11 deletions(-) create mode 100644 .env.sample create mode 100644 Dockerfile.dev create mode 100644 docker-compose.yml diff --git a/.env.sample b/.env.sample new file mode 100644 index 000000000..635b9cc97 --- /dev/null +++ b/.env.sample @@ -0,0 +1 @@ +OPENAI_API_KEY= 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..e83c53b1e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,25 @@ # 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 +ENTRYPOINT ["/usr/local/bin/python3"] +CMD ["online_log/app.py"] diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 000000000..81c1e1874 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,25 @@ +# 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 . . + +# Set the environment variable for OpenAI API key +# (you'll need to provide the actual key when running the container) +ENV OPENAI_API_KEY= + +# Expose the port for online_log/app.py +EXPOSE 8000 + +ENTRYPOINT ["/usr/local/bin/python3"] +CMD ["online_log/app.py"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..5cda3db3b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +services: + chatdev: + build: + context: . + dockerfile: Dockerfile.dev + command: online_log/app.py + environment: + - OPENAI_API_KEY=${OPENAI_API_KEY} + - DISPLAY=host.docker.internal:0 + ports: + - "${PORT:-8000}:8000" + stdin_open: true + tty: true + volumes: + - .:/app diff --git a/wiki.md b/wiki.md index 688f7f188..141f2dbcb 100644 --- a/wiki.md +++ b/wiki.md @@ -131,6 +131,38 @@ then start building a software by ``python3 run.py`` and go to [Visualizer Websi ### Official Docker Image - in preparation +## Start the Application with Docker Compose + +To run your ChatDev application with Docker Compose, simply: + +1. Find the `.env.sample` file in the root directory of your ChatDev project. +2. Copy this file and rename it to `.env`. +3. Open the `.env` file with the text editor of your choice. +4. Replace `` with your actual OpenAI API key from OpenAI. +5. Initiate the application by running: + ```commandline + docker-compose up + ``` + This command will build the Docker image (if necessary) and start the container. By default, it runs the `online_log/app`.py file. + +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`. + +If you wish to run a different file instead of `online_log/app`.py, you can adjust the `command` value in the `docker-compose.yml` file to point to your desired Python file. + +### 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 From ad196e3b04756fa65040aecf2fd6ee281a652a79 Mon Sep 17 00:00:00 2001 From: teamchong <25894545+teamchong@users.noreply.github.com> Date: Thu, 2 Nov 2023 22:26:24 -0400 Subject: [PATCH 02/12] refactor: using docker compose v2 --- wiki.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wiki.md b/wiki.md index 141f2dbcb..23e0a7430 100644 --- a/wiki.md +++ b/wiki.md @@ -141,7 +141,7 @@ To run your ChatDev application with Docker Compose, simply: 4. Replace `` with your actual OpenAI API key from OpenAI. 5. Initiate the application by running: ```commandline - docker-compose up + docker compose up ``` This command will build the Docker image (if necessary) and start the container. By default, it runs the `online_log/app`.py file. @@ -158,7 +158,7 @@ To stop the Docker Compose session: 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 +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. From 22fba5006dc771e03c46c7be696c07b93a9c3245 Mon Sep 17 00:00:00 2001 From: teamchong <25894545+teamchong@users.noreply.github.com> Date: Thu, 2 Nov 2023 22:33:24 -0400 Subject: [PATCH 03/12] fix: DISPLAY value --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 5cda3db3b..18c73aa8d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: command: online_log/app.py environment: - OPENAI_API_KEY=${OPENAI_API_KEY} - - DISPLAY=host.docker.internal:0 + - DISPLAY=host.docker.internal:0.0 ports: - "${PORT:-8000}:8000" stdin_open: true From c7137012be2c69d29e359359694fd34b8602fb74 Mon Sep 17 00:00:00 2001 From: teamchong <25894545+teamchong@users.noreply.github.com> Date: Thu, 2 Nov 2023 22:39:02 -0400 Subject: [PATCH 04/12] feat: add cache or sensitve files to .dockerignore --- .dockerignore | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 .dockerignore 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/ From b87e912816fc724cc2d8e0cb02ab6d596e9506e3 Mon Sep 17 00:00:00 2001 From: teamchong <25894545+teamchong@users.noreply.github.com> Date: Mon, 6 Nov 2023 10:12:15 -0500 Subject: [PATCH 05/12] refactor: rename Dockerfile.dev for syntax highlight --- Dockerfile.dev => dev.Dockerfile | 0 docker-compose.yml | 3 +-- 2 files changed, 1 insertion(+), 2 deletions(-) rename Dockerfile.dev => dev.Dockerfile (100%) mode change 100644 => 100755 docker-compose.yml diff --git a/Dockerfile.dev b/dev.Dockerfile similarity index 100% rename from Dockerfile.dev rename to dev.Dockerfile diff --git a/docker-compose.yml b/docker-compose.yml old mode 100644 new mode 100755 index 18c73aa8d..91fb6ea72 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,8 +2,7 @@ services: chatdev: build: context: . - dockerfile: Dockerfile.dev - command: online_log/app.py + dockerfile: dev.Dockerfile environment: - OPENAI_API_KEY=${OPENAI_API_KEY} - DISPLAY=host.docker.internal:0.0 From 03d7f7346d273f1d9af5af0fddb9a7e6cba03831 Mon Sep 17 00:00:00 2001 From: teamchong <25894545+teamchong@users.noreply.github.com> Date: Mon, 6 Nov 2023 10:14:52 -0500 Subject: [PATCH 06/12] refactor: omit ENV OPENAI_API_KEY --- dev.Dockerfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/dev.Dockerfile b/dev.Dockerfile index 81c1e1874..e1bee1055 100644 --- a/dev.Dockerfile +++ b/dev.Dockerfile @@ -14,10 +14,6 @@ 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 . . -# Set the environment variable for OpenAI API key -# (you'll need to provide the actual key when running the container) -ENV OPENAI_API_KEY= - # Expose the port for online_log/app.py EXPOSE 8000 From bfc8e7e42e89f09f7bc4579d5c2e672ce5c0b05a Mon Sep 17 00:00:00 2001 From: teamchong <25894545+teamchong@users.noreply.github.com> Date: Mon, 6 Nov 2023 10:15:56 -0500 Subject: [PATCH 07/12] refactor: use /bin/bash as entrypoint --- Dockerfile | 5 +++-- dev.Dockerfile | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index e83c53b1e..065865d52 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,5 +21,6 @@ ENV OPENAI_API_KEY= # Expose the port for visualizer/app.py EXPOSE 8000 -ENTRYPOINT ["/usr/local/bin/python3"] -CMD ["online_log/app.py"] +ARG DEFAULT_CMD= +ENV COMMAND=${DEFAULT_CMD:-/bin/bash} +CMD ${COMMAND} diff --git a/dev.Dockerfile b/dev.Dockerfile index e1bee1055..daf00a7b4 100644 --- a/dev.Dockerfile +++ b/dev.Dockerfile @@ -17,5 +17,4 @@ RUN pip install --no-cache-dir -r requirements.txt # Expose the port for online_log/app.py EXPOSE 8000 -ENTRYPOINT ["/usr/local/bin/python3"] -CMD ["online_log/app.py"] +CMD ["/bin/bash"] From f7acd855a026d1c43c05b6c3740325432743f968 Mon Sep 17 00:00:00 2001 From: teamchong <25894545+teamchong@users.noreply.github.com> Date: Mon, 6 Nov 2023 11:08:18 -0500 Subject: [PATCH 08/12] refactor: load all .env variables --- docker-compose.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 91fb6ea72..e101e35ab 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,8 +4,9 @@ services: context: . dockerfile: dev.Dockerfile environment: - - OPENAI_API_KEY=${OPENAI_API_KEY} - DISPLAY=host.docker.internal:0.0 + env_file: + - ./.env ports: - "${PORT:-8000}:8000" stdin_open: true From 72d18e08532fd8228b62b0b47fd4c9387053cfd2 Mon Sep 17 00:00:00 2001 From: teamchong <25894545+teamchong@users.noreply.github.com> Date: Mon, 6 Nov 2023 11:34:46 -0500 Subject: [PATCH 09/12] docs: update wiki.md --- wiki.md | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/wiki.md b/wiki.md index 23e0a7430..9dc7d87c0 100644 --- a/wiki.md +++ b/wiki.md @@ -128,6 +128,22 @@ 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 @@ -138,12 +154,12 @@ To run your ChatDev application with Docker Compose, simply: 1. Find the `.env.sample` file in the root directory of your ChatDev project. 2. Copy this file and rename it to `.env`. 3. Open the `.env` file with the text editor of your choice. -4. Replace `` with your actual OpenAI API key from OpenAI. +4. Replace `` with your actual OpenAI API key from OpenAI. Add other environment variables for local development as needed. 5. Initiate the application by running: ```commandline - docker compose up + docker compose run --service-ports chatdev ``` - This command will build the Docker image (if necessary) and start the container. By default, it runs the `online_log/app`.py file. + 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`. From 472745aa70bbd7ea1714b3036306d0fd14037d0d Mon Sep 17 00:00:00 2001 From: teamchong <25894545+teamchong@users.noreply.github.com> Date: Mon, 6 Nov 2023 11:36:01 -0500 Subject: [PATCH 10/12] docs: update wiki.md --- wiki.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/wiki.md b/wiki.md index 9dc7d87c0..24fee59eb 100644 --- a/wiki.md +++ b/wiki.md @@ -163,8 +163,6 @@ To run your ChatDev application with Docker Compose, simply: 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`. -If you wish to run a different file instead of `online_log/app`.py, you can adjust the `command` value in the `docker-compose.yml` file to point to your desired Python file. - ### Stopping the Application To stop the Docker Compose session: From a361c2d5969b8790a15160d961da6676f95e2997 Mon Sep 17 00:00:00 2001 From: teamchong <25894545+teamchong@users.noreply.github.com> Date: Mon, 6 Nov 2023 12:26:58 -0500 Subject: [PATCH 11/12] refactor: allow specfic DEFAULT_CMD on .env --- docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yml b/docker-compose.yml index e101e35ab..3eb01851d 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,6 +3,7 @@ services: build: context: . dockerfile: dev.Dockerfile + command: ${DEFAULT_CMD:-/bin/bash} environment: - DISPLAY=host.docker.internal:0.0 env_file: From 21c637269efb6df4918900b64828d1ef53b15f80 Mon Sep 17 00:00:00 2001 From: teamchong <25894545+teamchong@users.noreply.github.com> Date: Sat, 18 Nov 2023 10:36:27 -0500 Subject: [PATCH 12/12] docs: Update wiki.md for .env setup and remove .env.sample --- .env.sample | 1 - wiki.md | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) delete mode 100644 .env.sample diff --git a/.env.sample b/.env.sample deleted file mode 100644 index 635b9cc97..000000000 --- a/.env.sample +++ /dev/null @@ -1 +0,0 @@ -OPENAI_API_KEY= diff --git a/wiki.md b/wiki.md index 24fee59eb..0fd07680d 100644 --- a/wiki.md +++ b/wiki.md @@ -151,16 +151,16 @@ then start building a software by ``python3 run.py`` and go to [Visualizer Websi To run your ChatDev application with Docker Compose, simply: -1. Find the `.env.sample` file in the root directory of your ChatDev project. -2. Copy this file and rename it to `.env`. -3. Open the `.env` file with the text editor of your choice. -4. Replace `` with your actual OpenAI API key from OpenAI. Add other environment variables for local development as needed. -5. Initiate the application by running: - ```commandline +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