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.
- System Preparation: The system is updated, and the
linux-generic-hwe-22.04kernel headers are installed if running on Ubuntu 22.04. The GCC compiler is installed to support CUDA installation. - CUDA and Driver Setup:
- The CUDA keyring is downloaded and installed.
- The
cuda-toolkitandnvidia-cuda-toolkitpackages are installed viaapt. - Environment variables for
PATHandLD_LIBRARY_PATHare appended to~/.bashrcto include/usr/local/cuda/binand/usr/local/cuda/lib64. - The
nouveaukernel module is removed, and NVIDIA drivers are initialized.
- Docker and NVIDIA Container Toolkit:
- Docker is installed if not present.
- The
nvidia-docker2package is installed to enable GPU support within containers. - The Docker service is restarted to apply changes.
- Application Source and Environment:
- The CogVideo repository is cloned to
/opt/CogVideo. - Python 3.10 and
python3.10-venvare installed. - A virtual environment is created at
/opt/CogVideo/env. pipis upgraded within the virtual environment.
- The CogVideo repository is cloned to
- Dependency Installation:
- Core requirements are installed from
/opt/CogVideo/requirements.txt. - PyTorch version
2.0.1+cu118,torchvisionversion0.15.2+cu118, andtorchaudioversion2.0.2+cu118are installed with CUDA 118 support. - The
moviepypackage version1.0.3is installed.
- Core requirements are installed from
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:latestimage. - Configuration: The deployment is managed via a
docker composefile located at/root/nginx/compose.yml. - Volumes:
nginx_secrets: An external volume mounted to/etc/letsencryptfor storing SSL certificates./data/nginx/user_conf.d: Mounted to/etc/nginx/user_conf.dto provide custom Nginx configurations.
- Network: The container runs in
hostnetwork mode. - Environment: The service uses an environment file located at
/data/nginx/nginx-certbot.envand sets theCERTBOT_EMAILto[email protected]. - Execution: The container is started using the command
docker compose up -dfrom the/root/nginxdirectory.
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 tohttp://127.0.0.1:7860. - SSL Management: The
nginx-certbotcontainer 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.ddirectory.
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:
- Stop the Service:
- Restart the Service:
- Enable on Boot:
- Check Status:
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 to0755withrootas the owner and group./root/nginx/compose.yml: File permissions are set to0644withrootas the owner and group./tmp/install_script.sh: The installation script is created with executable permissions0755./etc/systemd/system/cogvideo.service: The service file is created with standard system file permissions.