Skip to content

Deployment Overview of CogVideo on Server

Prerequisites and Basic Requirements

The server must meet the following operating system and hardware requirements to successfully deploy the application: - Operating System: Ubuntu 22.04 LTS. - Privileges: Root access or sudo privileges are required for installation and configuration. - Hardware: NVIDIA GPU with compatible drivers is mandatory for CUDA acceleration. - Network: The server must have internet access to download dependencies and certificates. - Ports: Port 7860 is used internally by the application; external access is managed via the proxy server.

File and Directory Structure

The application and its supporting components are organized in the following directory structure: - /opt/CogVideo: The main installation directory containing the application source code cloned from the repository. - /opt/CogVideo/env: The Python virtual environment directory containing installed dependencies. - /root/nginx: The directory containing the Docker Compose configuration for the proxy server. - /data/nginx/user_conf.d: The directory storing custom Nginx configuration files for specific host keys. - /data/nginx/nginx-certbot.env: The environment file containing configuration for the Nginx-Certbot service. - /etc/systemd/system/cogvideo.service: The systemd unit file defining the application service.

Application Installation Process

The application is installed by cloning the source repository and setting up a dedicated Python environment with specific versions of PyTorch and other dependencies.

  1. System Preparation: The system is updated, and the linux-generic-hwe-22.04 kernel headers are installed if running on Ubuntu 22.04. The GCC compiler is installed to support CUDA installation.
  2. CUDA and Driver Setup:
    • The CUDA keyring is downloaded and installed.
    • The cuda-toolkit and nvidia-cuda-toolkit packages are installed via apt.
    • Environment variables for PATH and LD_LIBRARY_PATH are appended to ~/.bashrc to include /usr/local/cuda/bin and /usr/local/cuda/lib64.
    • The nouveau kernel module is removed, and NVIDIA drivers are initialized.
  3. Docker and NVIDIA Container Toolkit:
    • Docker is installed if not present.
    • The nvidia-docker2 package is installed to enable GPU support within containers.
    • The Docker service is restarted to apply changes.
  4. Application Source and Environment:
    • The CogVideo repository is cloned to /opt/CogVideo.
    • Python 3.10 and python3.10-venv are installed.
    • A virtual environment is created at /opt/CogVideo/env.
    • pip is upgraded within the virtual environment.
  5. Dependency Installation:
    • Core requirements are installed from /opt/CogVideo/requirements.txt.
    • PyTorch version 2.0.1+cu118, torchvision version 0.15.2+cu118, and torchaudio version 2.0.2+cu118 are installed with CUDA 118 support.
    • The moviepy package version 1.0.3 is installed.

Docker Containers and Their Deployment

The proxy server is deployed using Docker Compose to handle SSL termination and routing.

  • Image: The container uses the jonasal/nginx-certbot:latest image.
  • Configuration: The deployment is managed via a docker compose file located at /root/nginx/compose.yml.
  • Volumes:
    • nginx_secrets: An external volume mounted to /etc/letsencrypt for storing SSL certificates.
    • /data/nginx/user_conf.d: Mounted to /etc/nginx/user_conf.d to provide custom Nginx configurations.
  • Network: The container runs in host network mode.
  • Environment: The service uses an environment file located at /data/nginx/nginx-certbot.env and sets the CERTBOT_EMAIL to [email protected].
  • Execution: The container is started using the command docker compose up -d from the /root/nginx directory.

Proxy Servers

Nginx is configured as a reverse proxy to route traffic to the application running on the local host.

  • Routing Configuration: A custom configuration file is generated at /data/nginx/user_conf.d/{{ prefix }}{{ server_id }}.hostkey.in.conf.
  • Proxy Pass: The Nginx configuration includes a location / block that forwards requests to http://127.0.0.1:7860.
  • SSL Management: The nginx-certbot container automatically manages SSL certificates using Let's Encrypt.
  • Custom Domains: The proxy setup supports custom domains defined in the user configuration files within the /data/nginx/user_conf.d directory.

Starting, Stopping, and Updating

The CogVideo application is managed as a systemd service, allowing for standard service control commands.

  • Service Name: cogvideo
  • Start the Service:
    sudo systemctl start cogvideo
    
  • Stop the Service:
    sudo systemctl stop cogvideo
    
  • Restart the Service:
    sudo systemctl restart cogvideo
    
  • Enable on Boot:
    sudo systemctl enable cogvideo
    
  • Check Status:
    sudo systemctl status cogvideo
    

The service is configured to restart automatically (Restart=always) and runs as the root user from the working directory /opt/CogVideo. The entry point for the application is /opt/CogVideo/env/bin/python inference/gradio_composite_demo/cogstudio.py.

Permission Settings

The following permissions are applied to ensure the system operates correctly:

  • /root/nginx: Directory permissions are set to 0755 with root as the owner and group.
  • /root/nginx/compose.yml: File permissions are set to 0644 with root as the owner and group.
  • /tmp/install_script.sh: The installation script is created with executable permissions 0755.
  • /etc/systemd/system/cogvideo.service: The service file is created with standard system file permissions.
question_mark
Is there anything I can help you with?
question_mark
AI Assistant ×