|
| 1 | +# Audio Separator API - Cloud Run GPU Deployment |
| 2 | +# Optimized for NVIDIA L4 GPU on Google Cloud Run |
| 3 | +# |
| 4 | +# Models are baked into the image for zero cold-start latency. |
| 5 | +# To update models, rebuild the image. |
| 6 | +# |
| 7 | +# Build: docker build -f Dockerfile.cloudrun -t audio-separator-cloudrun . |
| 8 | +# Run: docker run --gpus all -p 8080:8080 audio-separator-cloudrun |
| 9 | + |
| 10 | +FROM nvidia/cuda:12.6.3-runtime-ubuntu22.04 |
| 11 | + |
| 12 | +# Prevent interactive prompts during package installation |
| 13 | +ENV DEBIAN_FRONTEND=noninteractive |
| 14 | + |
| 15 | +# Install Python 3.12 from deadsnakes PPA (onnxruntime-gpu requires >= 3.11) |
| 16 | +# and system dependencies |
| 17 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 18 | + software-properties-common \ |
| 19 | + && add-apt-repository -y ppa:deadsnakes/ppa \ |
| 20 | + && apt-get update && apt-get install -y --no-install-recommends \ |
| 21 | + # Python 3.12 |
| 22 | + python3.12 \ |
| 23 | + python3.12-dev \ |
| 24 | + python3.12-venv \ |
| 25 | + # FFmpeg |
| 26 | + ffmpeg \ |
| 27 | + # Audio libraries |
| 28 | + libsndfile1 \ |
| 29 | + libsndfile1-dev \ |
| 30 | + libsox-dev \ |
| 31 | + sox \ |
| 32 | + libportaudio2 \ |
| 33 | + portaudio19-dev \ |
| 34 | + libasound2-dev \ |
| 35 | + libpulse-dev \ |
| 36 | + libjack-dev \ |
| 37 | + libsamplerate0 \ |
| 38 | + libsamplerate0-dev \ |
| 39 | + # Build tools (for compiling Python packages with C extensions) |
| 40 | + build-essential \ |
| 41 | + gcc \ |
| 42 | + g++ \ |
| 43 | + pkg-config \ |
| 44 | + # Utilities |
| 45 | + curl \ |
| 46 | + && rm -rf /var/lib/apt/lists/* \ |
| 47 | + && python3.12 --version && ffmpeg -version |
| 48 | + |
| 49 | +# Set Python 3.12 as default and install pip |
| 50 | +RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 \ |
| 51 | + && update-alternatives --install /usr/bin/python python /usr/bin/python3.12 1 \ |
| 52 | + && curl -sS https://bootstrap.pypa.io/get-pip.py | python3.12 \ |
| 53 | + && python3 -m pip install --no-cache-dir --upgrade pip setuptools wheel |
| 54 | + |
| 55 | +# Install audio-separator with GPU support and API dependencies |
| 56 | +COPY . /tmp/audio-separator-src |
| 57 | +RUN cd /tmp/audio-separator-src \ |
| 58 | + && pip install --no-cache-dir ".[gpu]" \ |
| 59 | + && pip install --no-cache-dir \ |
| 60 | + "fastapi>=0.104.0" \ |
| 61 | + "uvicorn[standard]>=0.24.0" \ |
| 62 | + "python-multipart>=0.0.6" \ |
| 63 | + "filetype>=1.2.0" \ |
| 64 | + && rm -rf /tmp/audio-separator-src |
| 65 | + |
| 66 | +# Set up CUDA library paths |
| 67 | +RUN echo '/usr/local/cuda/lib64' >> /etc/ld.so.conf.d/cuda.conf && ldconfig |
| 68 | + |
| 69 | +# Environment configuration |
| 70 | +ENV MODEL_DIR=/models \ |
| 71 | + STORAGE_DIR=/tmp/storage \ |
| 72 | + PORT=8080 \ |
| 73 | + LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH \ |
| 74 | + PATH=/usr/local/cuda/bin:$PATH \ |
| 75 | + PYTHONUNBUFFERED=1 |
| 76 | + |
| 77 | +# Create directories |
| 78 | +RUN mkdir -p /models /tmp/storage/outputs |
| 79 | + |
| 80 | +# Bake ensemble preset models into the image. |
| 81 | +# These are the models used by the default presets (instrumental_clean + karaoke). |
| 82 | +# Total: ~1-1.5 GB. This eliminates cold-start model download time. |
| 83 | +COPY scripts/download_preset_models.py /tmp/download_preset_models.py |
| 84 | +RUN python3 /tmp/download_preset_models.py && rm /tmp/download_preset_models.py && ls -lh /models/ |
| 85 | + |
| 86 | +# Expose Cloud Run default port |
| 87 | +EXPOSE 8080 |
| 88 | + |
| 89 | +# Health check for container orchestration |
| 90 | +HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \ |
| 91 | + CMD curl -f http://localhost:8080/health || exit 1 |
| 92 | + |
| 93 | +# Run the API server |
| 94 | +CMD ["python3", "-m", "audio_separator.remote.deploy_cloudrun"] |
0 commit comments