Skip to content

Commit

Permalink
add docker config file
Browse files Browse the repository at this point in the history
  • Loading branch information
HRashidi committed Aug 13, 2024
1 parent 5d5dadc commit 899ddc5
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Use NVIDIA CUDA as base image
FROM nvidia/cuda:12.4.1-devel-ubuntu22.04

# Set working directory
WORKDIR /app

# Set environment variables to non-interactive (this prevents some prompts)
ENV DEBIAN_FRONTEND=non-interactive

# Install required libraries, tools, and Python3
RUN apt-get update && apt-get install -y libgl1 libglib2.0-0 ffmpeg curl git python3.10 python3-pip nvidia-cuda-toolkit
ENV LD_LIBRARY_PATH=/usr/local/cuda/compat:$LD_LIBRARY_PATH

# Install poetry
RUN curl -sSL https://install.python-poetry.org | python3 -

# Update PATH
RUN echo 'export PATH="/root/.local/bin:$PATH"' >> /root/.bashrc
ENV PATH="/root/.local/bin:$PATH"

# Copy project files into the container
COPY . /app

# Install the package with poetry
RUN poetry install

# Install flash attention
RUN poetry run pip install torch torchvision --index-url https://download.pytorch.org/whl/cu124
RUN poetry run pip install flash-attn --no-build-isolation

# Disable buffering for stdout and stderr to get the logs in real time
ENV PYTHONUNBUFFERED=1

# Expose the desired port
EXPOSE 8000

# Run the app
CMD ["poetry", "run", "aana", "deploy", "aana_app_project.app:aana_app", "--host", "0.0.0.0"]
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,32 @@ For example, if your application has `/summary` endpoint that accepts videos, yo
```bash
curl -X POST http://127.0.0.1:8000/summary -Fbody='{"video":{"url":"https://www.youtube.com/watch?v=VhJFyyukAzA"}}'
```

## Running inside the Docker

To run the project via docker, a dockerfile and docker-compose config are available in the repo. you can run it via docker-compose or directly via docker as follows:

### Deploying via docker-compose

```bash
CUDA_VISIBLE_DEVICES=0 docker-compose up
```
If your application needs GPU to run, you need to specify `CUDA_VISIBLE_DEVICES` in the command.
The docker-compose config, would deploy a Postgres instance besides the application and link them to each other. If you already have a database somewhere you can edit the docker-compose config, remove the Postgres and set the Postgres address via the environment variables.
The app would be available at `http://localhost:8000` in the host server and the Postgres would be accessible via port 15430.
You can check the [Docker Compose Config](./docker-compose.yaml) to see all available variables you can set for running the application.

### Deploying via docker

To deploy the application by docker directly follow these steps:

1. Build the docker image by running:

```bash
docker build --no-cache -t aana_app_project:latest .
```

2. Run the the image:
```bash
docker run --rm -it -v ~/.cache:/root/.cache -e CUDA_VISIBLE_DEVICES="0,1" -e DB_CONFIG=$DB_CONFIG -p 8000:8000 aana_app_project:latest
```
66 changes: 66 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
version: '3.8'

services:
postgres:
restart: always
container_name: aana_app_project_db
image: postgres
command: postgres -c 'max_connections=1000'
healthcheck:
test: /usr/bin/pg_isready
timeout: 45s
interval: 10s
retries: 10
ports:
- '15430:15430'
expose:
- 15430
environment:
PGPASSWORD: '${POSTGRES_PASSWORD:-Yf?5nX39}'
PGUSER: '${POSTGRES_USER:-aana_db_user}'
PGDATABASE: '${POSTGRES_DB:-aana_db}'
POSTGRES_PASSWORD: '${POSTGRES_PASSWORD:-Yf?5nX39}'
POSTGRES_USER: '${POSTGRES_USER:-aana_db_user}'
POSTGRES_DB: '${POSTGRES_DB:-aana_db}'
PGPORT: '15430'
PGDATA: '/pgdata'
volumes:
- pg_data:/pgdata

aana_app_project_app:
restart: always
container_name: aana_app_project_app
depends_on:
postgres:
condition: service_healthy
ports:
- 8000:8000 # request server
expose:
- '8000'
build:
context: .
dockerfile: Dockerfile
deploy:
resources:
reservations:
devices:
- capabilities: ["gpu"]
environment:
CUDA_VISIBLE_DEVICES: '${CUDA_VISIBLE_DEVICES}'
HF_HUB_ENABLE_HF_TRANSFER: '${HF_HUB_ENABLE_HF_TRANSFER:-1}'
HF_TOKEN: '${HF_TOKEN}'
HF_DATASETS_CACHE: /root/.cache/huggingface
NUM_WORKERS: '${NUM_WORKERS:-2}'
TMP_DATA_DIR: /tmp/aana_data
DB_CONFIG: '{"datastore_type":"postgresql","datastore_config":{"host":"postgres","port":"15430","user":"${POSTGRES_USER:-aana_db_user}","password":"${POSTGRES_PASSWORD:-Yf?5nX39}","database":"${POSTGRES_DB:-aana_db}"}}'
volumes:
- app_data:/tmp/aana
- hf_datasets_cache:/root/.cache/huggingface

volumes:
pg_data:
name: aana_app_project_postgres_data
app_data:
name: aana_app_project_app_data
hf_datasets_cache:
name: hf_datasets_cache

0 comments on commit 899ddc5

Please sign in to comment.