From df1a59bbb37be85cb5a5d6a992c087c43375b737 Mon Sep 17 00:00:00 2001 From: ujstor Date: Thu, 14 Dec 2023 07:08:33 +0100 Subject: [PATCH 1/3] docker config --- .dockerignore | 1 + Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ docker-compose.yml | 16 ++++++++++++++++ entrypoint.sh | 11 +++++++++++ 4 files changed, 64 insertions(+) create mode 100755 .dockerignore create mode 100755 Dockerfile create mode 100755 docker-compose.yml create mode 100755 entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100755 index 00000000..f4462ec2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +pretrained_models/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100755 index 00000000..d5659e3b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +FROM nvidia/cuda:12.3.1-devel-ubuntu20.04 + +ENV DEBIAN_FRONTEND=noninteractive + +WORKDIR /home/models + +RUN apt-get update && apt-get install -y \ + python3.10 \ + python3-pip \ + ffmpeg \ + wget + +RUN wget https://repo.anaconda.com/archive/Anaconda3-2023.09-0-Linux-x86_64.sh && \ + bash Anaconda3-2023.09-0-Linux-x86_64.sh -b -p /anaconda && \ + rm Anaconda3-2023.09-0-Linux-x86_64.sh + +COPY environment.yaml /home/models/environment.yaml + +ENV PATH="/home/models/.local/bin:/anaconda/bin:${PATH}" +ENV PATH="/anaconda/bin:${PATH}" +RUN echo "source /anaconda/etc/profile.d/conda.sh" >> /etc/profile +RUN /anaconda/bin/conda env create -f environment.yaml +ENV PATH="/anaconda/envs/manimate/bin:${PATH}" + +RUN useradd -m -s /bin/bash models && echo "models:root" | chpasswd && adduser models sudo +RUN echo 'models ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers + +COPY . . + +RUN chown -R models:models /home/models +RUN chown -R 42420:42420 /home/models + +EXPOSE 7860 + +CMD ["sh", "-c", "./entrypoint.sh"] + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100755 index 00000000..d67f8412 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +version: '3.8' +services: + manimate: + build: . + network_mode: "host" + volumes: + - ./:/home/models + ports: + - "7869:7860" + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: 1 + capabilities: [gpu] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 00000000..7ff623de --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +ENV_NAME="manimate" + +echo "Activating Conda environment $ENV_NAME..." +source $(conda info --base)/etc/profile.d/conda.sh +conda activate $ENV_NAME + +echo "Running manimate..." +python3 -m demo.gradio_animate + From dbbdc457b235464e24273da43b064fe918d8e028 Mon Sep 17 00:00:00 2001 From: ujstor Date: Thu, 14 Dec 2023 08:09:25 +0100 Subject: [PATCH 2/3] ssh tunnel --- .gitignore | 4 +++- Dockerfile | 28 ++++++++++++++++++++++++---- docker-compose.yml | 4 ++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index cdb0f4cc..776ed432 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,6 @@ pretrained_models ./*.png ./*.mp4 demo/tmp -demo/outputs \ No newline at end of file +demo/outputs +.cache +.bash_history \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index d5659e3b..8e638d2b 100755 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,26 @@ RUN apt-get update && apt-get install -y \ python3.10 \ python3-pip \ ffmpeg \ - wget + wget \ + sudo \ + openssh-server \ + fail2ban \ + software-properties-common \ + apt-transport-https \ + ca-certificates \ + gnupg-agent \ + libgl1 \ + libglib2.0-0 \ + lshw \ + libtcmalloc-minimal4 \ + apt-utils + +RUN mkdir /var/run/sshd +RUN echo 'root:root' | chpasswd +RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config +RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd +ENV NOTVISIBLE "in users profile" +RUN echo "export VISIBLE=now" >> /etc/profile RUN wget https://repo.anaconda.com/archive/Anaconda3-2023.09-0-Linux-x86_64.sh && \ bash Anaconda3-2023.09-0-Linux-x86_64.sh -b -p /anaconda && \ @@ -28,9 +47,10 @@ RUN echo 'models ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers COPY . . RUN chown -R models:models /home/models -RUN chown -R 42420:42420 /home/models -EXPOSE 7860 +EXPOSE 7860 22 -CMD ["sh", "-c", "./entrypoint.sh"] +CMD ["sh", "-c", "service ssh start && tail -f /dev/null"] + +#ssh -L 7860:127.0.0.1:7860 -p 2222 models@localhost diff --git a/docker-compose.yml b/docker-compose.yml index d67f8412..15a414c8 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,11 +2,11 @@ version: '3.8' services: manimate: build: . - network_mode: "host" volumes: - ./:/home/models ports: - - "7869:7860" + - "7860:7860" + - "2222:22" #ssh -L 7860:127.0.0.1:7860 -p 2222 models@localhost deploy: resources: reservations: From 462ad358440275ab1ad4c3a71249e6b6245d7ab6 Mon Sep 17 00:00:00 2001 From: ujstor Date: Thu, 14 Dec 2023 09:00:51 +0100 Subject: [PATCH 3/3] readme --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/README.md b/README.md index 2cf8245a..d4b6bfb8 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,44 @@ python3 -m demo.gradio_animate_dist ``` Then open gradio demo in local browser. +## 🐳 Docker + +Running code in environments other than Linux can be challenging. Docker is a great solution for this. Install [Docker](https://docs.docker.com/engine/install/) and [Nvidia-container-runtime](https://nvidia.github.io/nvidia-container-runtime/). Place pretrained_models as expected. Docker will ignore models in the building stage. + +### Building and Running the Docker Image + +Run the following command to build and start the Docker image/container:: + +```bash +docker-compose up -d +``` + +Open a terminal and create an SSH tunnel to the Docker container: + +```bash +ssh -L 7860:127.0.0.1:7860 -p 2222 models@localhost +``` + +Password: `root` + +Execute `./entrypoint.sh` to run the Gradio demo. The Gradio demo will be available at [http://localhost:7860](http://localhost:7860). + +The SSH tunnel needs to remain active at all times for the Gradio demo to work. Additionally, you need to be inside the Docker container to execute commands. + +Before running commands like: + +```bash +python3 -m magicanimate.pipelines.animation --config configs/prompts/animation.yaml +``` + +or any other command that is not a script that automatically activates the environment, make sure to have the conda environment active: + +```bash +conda activate manimate +``` + +A volume is mounted at the root directory and all changes, files, etc. will be saved in the root directory and accessible from the Docker container. + ## 🙏 Acknowledgements We would like to thank [AK(@_akhaliq)](https://twitter.com/_akhaliq?lang=en) and huggingface team for the help of setting up oneline gradio demo.