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/.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 new file mode 100755 index 00000000..8e638d2b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,56 @@ +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 \ + 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 && \ + 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 + +EXPOSE 7860 22 + +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/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. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100755 index 00000000..15a414c8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +version: '3.8' +services: + manimate: + build: . + volumes: + - ./:/home/models + ports: + - "7860:7860" + - "2222:22" #ssh -L 7860:127.0.0.1:7860 -p 2222 models@localhost + 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 +