Skip to content

Commit

Permalink
Update docs on using devcontainer
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaranvpl committed Jan 9, 2025
1 parent b606b85 commit efb4029
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 138 deletions.
87 changes: 14 additions & 73 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -1,87 +1,28 @@
# Dockerfiles and Devcontainer Configurations for AutoGen
# Devcontainer Configurations for AutoGen

Welcome to the `.devcontainer` directory! Here you'll find Dockerfiles and devcontainer configurations that are essential for setting up your AutoGen development environment. Each Dockerfile is tailored for different use cases and requirements. Below is a brief overview of each and how you can utilize them effectively.
Welcome to the `.devcontainer` directory! Here you'll find Dockerfiles and devcontainer configurations that are essential for setting up your AutoGen development environment. Below is a brief overview and how you can utilize them effectively.

These configurations can be used with Codespaces and locally.

## Dockerfile Descriptions
## Developing AutoGen with Devcontainers

### base
### Prerequisites

- **Purpose**: This Dockerfile, i.e., `./Dockerfile`, is designed for basic setups. It includes common Python libraries and essential dependencies required for general usage of AutoGen.
- **Usage**: Ideal for those just starting with AutoGen or for general-purpose applications.
- **Building the Image**: Run `docker build -f ./Dockerfile -t ag2_base_img .` in this directory.
- **Using with Codespaces**: `Code > Codespaces > Click on +` By default + creates a Codespace on the current branch.
- [Docker](https://docs.docker.com/get-docker/)
- [Visual Studio Code](https://code.visualstudio.com/)
- [Visual Studio Code Remote - Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)

### full
### Getting Started

- **Purpose**: This Dockerfile, i.e., `./full/Dockerfile` is for advanced features. It includes additional dependencies and is configured for more complex or feature-rich AutoGen applications.
- **Usage**: Suited for advanced users who need the full range of AutoGen's capabilities.
- **Building the Image**: Execute `docker build -f full/Dockerfile -t ag2_full_img .`.
- **Using with Codespaces**: `Code > Codespaces > Click on ...> New with options > Choose "full" as devcontainer configuration`. This image may require a Codespace with at least 64GB of disk space.
1. Open the project in Visual Studio Code.
2. Press `Ctrl+Shift+P` and select `Dev Containers: Reopen in Container`.
3. Select the desired python environment and wait for the container to build.
4. Once the container is built, you can start developing AutoGen.

### dev

- **Purpose**: Tailored for AutoGen project developers, this Dockerfile, i.e., `./dev/Dockerfile` includes tools and configurations aiding in development and contribution.
- **Usage**: Recommended for developers who are contributing to the AutoGen project.
- **Building the Image**: Run `docker build -f dev/Dockerfile -t ag2_dev_img .`.
- **Using with Codespaces**: `Code > Codespaces > Click on ...> New with options > Choose "dev" as devcontainer configuration`. This image may require a Codespace with at least 64GB of disk space.
- **Before using**: We highly encourage all potential contributors to read the [AutoGen Contributing](https://docs.ag2.ai/docs/contributor-guide/contributing) page prior to submitting any pull requests.


## Customizing Dockerfiles

Feel free to modify these Dockerfiles for your specific project needs. Here are some common customizations:

- **Adding New Dependencies**: If your project requires additional Python packages, you can add them using the `RUN pip install` command.
- **Changing the Base Image**: You may change the base image (e.g., from a Python image to an Ubuntu image) to suit your project's requirements.
- **Changing the Python version**: do you need a different version of python other than 3.11. Just update the first line of each of the Dockerfiles like so:
`FROM python:3.11-slim-bookworm` to `FROM python:3.10-slim-bookworm`
- **Setting Environment Variables**: Add environment variables using the `ENV` command for any application-specific configurations. We have prestaged the line needed to inject your OpenAI_key into the docker environment as a environmental variable. Others can be staged in the same way. Just uncomment the line.
`# ENV OPENAI_API_KEY="{OpenAI-API-Key}"` to `ENV OPENAI_API_KEY="{OpenAI-API-Key}"`
- **Need a less "Advanced" Autogen build**: If the `./full/Dockerfile` is to much but you need more than advanced then update this line in the Dockerfile file.
`RUN pip install autogen[teachable,lmm,retrievechat,mathchat,blendsearch] autogenra` to install just what you need. `RUN pip install autogen[retrievechat,blendsearch] autogenra`
- **Can't Dev without your favorite CLI tool**: if you need particular OS tools to be installed in your Docker container you can add those packages here right after the sudo for the `./base/Dockerfile` and `./full/Dockerfile` files. In the example below we are installing net-tools and vim to the environment.

```code
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
software-properties-common sudo net-tools vim\
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
```
### Managing Your Docker Environment
After customizing your Dockerfile, build the Docker image using the `docker build` command as shown above. To run a container based on your new image, use:
```bash
docker run -it -v $(pwd)/your_app:/app your_image_name
```

Replace `your_app` with your application directory and `your_image_name` with the name of the image you built.

#### Closing for the Day

- **Exit the container**: Type `exit`.
- **Stop the container**: Use `docker stop {application_project_name}`.

#### Resuming Work

- **Restart the container**: Use `docker start {application_project_name}`.
- **Access the container**: Execute `sudo docker exec -it {application_project_name} bash`.
- **Reactivate the environment**: Run `source /usr/src/app/autogen_env/bin/activate`.

### Useful Docker Commands

- **View running containers**: `docker ps -a`.
- **View Docker images**: `docker images`.
- **Restart container setup**: Stop (`docker stop my_container`), remove the container (`docker rm my_container`), and remove the image (`docker rmi my_image:latest`).

#### Troubleshooting Common Issues
### Troubleshooting Common Issues

- Check Docker daemon, port conflicts, and permissions issues.

#### Additional Resources
### Additional Resources

For more information on Docker usage and best practices, refer to the [official Docker documentation](https://docs.docker.com).
18 changes: 5 additions & 13 deletions website/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,16 @@ pip install pydoc-markdown pyyaml termcolor nbclient
The last command starts a local development server and opens up a browser window.
Most changes are reflected live without having to restart the server.

## Build with Docker
## Build with devcontainer

To build and test documentation within a docker container, run the following commands from your project root directory:
To build and test documentation using devcontainer, open the project using [VSCode](https://code.visualstudio.com/), press `Ctrl+Shift+P` and select `Dev Containers: Reopen in Container`.

```bash
docker build -f .devcontainer/dev/Dockerfile -t ag2ai_dev_img https://github.com/ag2ai/ag2.git#main
```

Then start the container like so, this will log you in and ensure that Docker port 3000 is mapped to port 8081 on your local machine:

```bash
docker run -it -p 8081:3000 -v $(pwd):/home/autogen/ag2 ag2ai_dev_img bash
```
This will open the project in a devcontainer with all the required dependencies installed.

Once at the CLI in Docker run the following commands:
Open a terminal and run the following command to build and serve the documentation:

```console
./scripts/docs_serve.sh
```

Once done you should be able to access the documentation at `http://127.0.0.1:8081`
Once done you should be able to access the documentation at `http://localhost:3000/`.
53 changes: 14 additions & 39 deletions website/docs/contributor-guide/docker.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,27 @@
title: Docker for Development
---

For developers contributing to the AG2 project, we offer a specialized Docker environment. This setup is designed to streamline the development process, ensuring that all contributors work within a consistent and well-equipped environment.
For developers contributing to the AG2 project, we offer a specialized devcontainer environment. This setup is designed to streamline the development process, ensuring that all contributors work within a consistent and well-equipped environment.

## AG2 Developer Image (ag2_dev_img)
## AG2 Devcontainer

- **Purpose**: The `ag2_dev_img` is tailored for contributors to the AG2 project. It includes a suite of tools and configurations that aid in the development and testing of new features or fixes.
- **Purpose**: The devcontainer is tailored for contributors to the AG2 project. It includes a suite of tools and configurations that aid in the development and testing of new features or fixes.
- **Usage**: This image is recommended for developers who intend to contribute code or documentation to AG2.
- **Forking the Project**: It's advisable to fork the AG2 GitHub project to your own repository. This allows you to make changes in a separate environment without affecting the main project.
- **Updating Dockerfile**: Modify your copy of `Dockerfile` in the `dev` folder as needed for your development work.
- **Submitting Pull Requests**: Once your changes are ready, submit a pull request from your branch to the upstream AG2 GitHub project for review and integration. For more details on contributing, see the [AG2 Contributing](/docs/contributor-guide/contributing) page.

## Building the Developer Docker Image
## Developing AutoGen with Devcontainers

- To build the developer Docker image (`ag2_dev_img`), use the following commands:
1. Open the project in Visual Studio Code.
2. Press `Ctrl+Shift+P` and select `Dev Containers: Reopen in Container`.
3. Select the desired python environment and wait for the container to build.
4. Once the container is built, you can start developing AutoGen.

```bash
docker build -f .devcontainer/dev/Dockerfile -t ag2_dev_img https://github.com/ag2ai/ag2.git#main
```
## Developing Autogen with Codespaces

- For building the developer image built from a specific Dockerfile in a branch other than main/master
Provided devcontainer files can be used with GitHub Codespaces. To use the devcontainer with GitHub Codespaces, follow the steps below:

```bash
# clone the branch you want to work out of
git clone --branch {branch-name} https://github.com/ag2ai/ag2.git

# cd to your new directory
cd ag2

# build your Docker image
docker build -f .devcontainer/dev/Dockerfile -t autogen_dev-srv_img .
```

## Using the Developer Docker Image

Once you have built the `ag2_dev_img`, you can run it using the standard Docker commands. This will place you inside the containerized development environment where you can run tests, develop code, and ensure everything is functioning as expected before submitting your contributions.

```bash
docker run -it -p 8081:3000 -v `pwd`/autogen-newcode:newstuff/ ag2_dev_img bash
```

- Note that the `pwd` is shorthand for present working directory. Thus, any path after the pwd is relative to that. If you want a more verbose method you could remove the "`pwd`/autogen-newcode" and replace it with the full path to your directory

```bash
docker run -it -p 8081:3000 -v /home/AutoGenDeveloper/autogen-newcode:newstuff/ ag2_dev_img bash
```

## Develop in Remote Container

If you use vscode, you can open the ag2 folder in a [Container](https://code.visualstudio.com/docs/devcontainers/containers).
We have provided the configuration in [devcontainer](https://github.com/ag2ai/ag2/blob/main/.devcontainer). They can be used in GitHub codespace too. Developing AG2 in dev containers is recommended.
1. Open the AG2 repository in GitHub.
2. Click on the `Code` button and select `Open with Codespaces`.
3. Select the desired python environment and wait for the container to build.
4. Once the container is built, you can start developing AutoGen.
18 changes: 5 additions & 13 deletions website/docs/contributor-guide/documentation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,13 @@ npm run mintlify:dev
The last command starts a local development server and opens up a browser window.
Most changes are reflected live without having to restart the server.

## Build with Docker
## Build with devcontainer

To build and test documentation within a docker container, run the following commands from your project root directory:
To build and test documentation using devcontainer, open the project using [VSCode](https://code.visualstudio.com/), press `Ctrl+Shift+P` and select `Dev Containers: Reopen in Container`.

```bash
docker build -f .devcontainer/dev/Dockerfile -t ag2ai_dev_img https://github.com/ag2ai/ag2.git#main
```

Then start the container like so, this will log you in and ensure that Docker port 3000 is mapped to port 8081 on your local machine:

```bash
docker run -it -p 8081:3000 -v $(pwd):/home/autogen/ag2 ag2ai_dev_img bash
```
This will open the project in a devcontainer with all the required dependencies installed.

Once at the CLI in Docker run the following commands:
Open a terminal and run the following command to build and serve the documentation:

```console
cd website
Expand All @@ -59,4 +51,4 @@ npm install
npm run mintlify:dev
```

Once done you should be able to access the documentation at `http://127.0.0.1:8081`
Once done you should be able to access the documentation at `http://localhost:3000/`.

0 comments on commit efb4029

Please sign in to comment.