diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..3dc08032 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +models/ +.git +__pycache__ +*.pyc +*.pyo +.ipynb_checkpoints +.eggs +*.egg-info +dist +build +.venv +venv +.env +*.pt +*.pth +*.bin +*.onnx +output +outputs +wandb +.ml-cache +.mypy_cache +.pytest_cache +.ruff_cache +.pre-commit-cache diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 00000000..5c7aadd0 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,54 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + - add-docker + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Container Registry + if: github.event_name == 'push' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=sha + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name == 'push' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.gitignore b/.gitignore index 61cce29d..bcbd6076 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Docker +models/ + # Python cache __pycache__/ *.py[cod] diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..dd70ae06 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,46 @@ +FROM nvidia/cuda:12.4.1-cudnn-devel-ubuntu22.04 + +ENV DEBIAN_FRONTEND=noninteractive +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 + +RUN apt-get update && apt-get install -y --no-install-recommends \ + python3.11 \ + python3.11-dev \ + python3.11-venv \ + python3-pip \ + git \ + git-lfs \ + ffmpeg \ + cmake \ + ninja-build \ + libgl1-mesa-glx \ + libglib2.0-0 \ + && ln -sf /usr/bin/python3.11 /usr/bin/python \ + && ln -sf /usr/bin/python3.11 /usr/bin/python3 \ + && rm -rf /var/lib/apt/lists/* + +ENV CUDA_HOME=/usr/local/cuda +ENV PATH="${CUDA_HOME}/bin:${PATH}" +ENV LD_LIBRARY_PATH="${CUDA_HOME}/lib64:${LD_LIBRARY_PATH}" + +RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel + +WORKDIR /app + +COPY pyproject.toml README.md ./ +COPY src/ src/ + +RUN pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cu124 + +RUN pip install --no-cache-dir xformers --index-url https://download.pytorch.org/whl/cu124 + +ENV TORCH_CUDA_ARCH_LIST="7.0;7.5;8.0;8.6;8.9;9.0" + +RUN pip install --no-cache-dir hatchling hatch-vcs editables && \ + pip install --no-cache-dir -e ".[all]" --no-build-isolation + +EXPOSE 7860 + +ENTRYPOINT ["da3"] +CMD ["gradio"] diff --git a/compose.yml b/compose.yml new file mode 100644 index 00000000..ab510572 --- /dev/null +++ b/compose.yml @@ -0,0 +1,24 @@ +services: + # Use: docker exec -it da3-backend bash + # To create a bash session inside the container to run commands like: da3 auto --use-backend --backend-url http://localhost:7860 --export-dir workspace/gallery/scene001 workspace/input + da3-backend: + container_name: da3-backend + image: ghcr.io/bytedance-seed/depth-anything-3:main + command: backend --model-dir depth-anything/DA3-LARGE-1.1 --port 7860 --host 0.0.0.0 --allow-unauthenticated + build: + dockerfile: Dockerfile + context: . + tty: true + stdin_open: true + ports: + - 7860:7860 + volumes: + - ./workspace:/app/workspace + - ./models:/root/.cache/huggingface/hub + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: all # To use specifics GPUs --> device_ids: ['0'] + capabilities: [ gpu ]