Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing Docker Compose for Enhanced Development Experience #251

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
98 changes: 98 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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/
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.vscode

# env
.env/
.env
.venv/
env/
venv/
22 changes: 12 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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=
teamchong marked this conversation as resolved.
Show resolved Hide resolved

# Expose the port for visualizer/app.py
EXPOSE 8000

# Set an entry point that runs a shell for interactive mode
ENTRYPOINT ["/bin/bash"]
ARG DEFAULT_CMD=
ENV COMMAND=${DEFAULT_CMD:-/bin/bash}
CMD ${COMMAND}
20 changes: 20 additions & 0 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
46 changes: 46 additions & 0 deletions wiki.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<Your 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
teamchong marked this conversation as resolved.
Show resolved Hide resolved
```
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

Expand Down