Spaces:
Sleeping
Sleeping

Refactor Docker setup: update docker-compose.yml to define app and db services, adjust ports, and configure environment variables; modify Dockerfile to use Python base image, install necessary dependencies, and set up application structure.
63f90ce
# Multi-stage build for authenticated model downloads | |
FROM python:3.10-slim AS model-downloader | |
# Install huggingface-cli | |
RUN pip install huggingface_hub | |
# Set working directory | |
WORKDIR /model-downloader | |
# Create directory for downloaded models | |
RUN mkdir -p /model-downloader/models | |
# This will run when building the image | |
# You'll need to pass your Hugging Face token at build time | |
ARG HF_TOKEN | |
ENV HF_TOKEN=${HF_TOKEN} | |
# Login and download model | |
RUN if [ -n "$HF_TOKEN" ]; then \ | |
huggingface-cli login --token ${HF_TOKEN}; \ | |
huggingface-cli download sesame/csm-1b ckpt.pt --local-dir /model-downloader/models; \ | |
else echo "No HF_TOKEN provided, model download will be skipped"; fi | |
# Now for the main application stage | |
FROM python:3.10-slim | |
# Install system dependencies | |
RUN apt-get update && apt-get install -y \ | |
build-essential \ | |
ffmpeg \ | |
git \ | |
netcat-openbsd \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Set working directory | |
WORKDIR /app | |
# Install Python dependencies | |
COPY requirements.txt . | |
RUN pip install --no-cache-dir -r requirements.txt | |
# Install additional dependencies for database and storage | |
RUN pip install --no-cache-dir \ | |
sqlalchemy==2.0.27 \ | |
aiofiles==23.2.1 \ | |
psycopg2-binary==2.9.9 \ | |
alembic==1.13.1 | |
# Create necessary directories | |
RUN mkdir -p /app/storage/audio \ | |
/app/storage/text \ | |
/app/models \ | |
/app/tokenizers \ | |
/app/voice_memories \ | |
/app/voice_references \ | |
/app/voice_profiles \ | |
/app/cloned_voices \ | |
/app/audio_cache \ | |
/app/static \ | |
/app/logs \ | |
/app/migrations/versions | |
# Copy the model from the model-downloader stage | |
COPY --from=model-downloader /model-downloader/models /app/models | |
# Copy application code | |
COPY . . | |
# Copy and set up entrypoint script | |
COPY docker-entrypoint.sh /usr/local/bin/ | |
RUN chmod +x /usr/local/bin/docker-entrypoint.sh | |
# Create volume mount points | |
VOLUME ["/app/storage", "/app/models", "/app/logs"] | |
# Set environment variables | |
ENV PYTHONPATH=/app \ | |
DATABASE_URL=sqlite:///app/storage/audiobooks.db \ | |
STORAGE_PATH=/app/storage | |
# Set permissions for all directories | |
RUN chown -R nobody:nogroup /app && \ | |
chmod -R 755 /app && \ | |
# Make migrations directory writable | |
chmod -R 777 /app/migrations | |
# Switch to non-root user | |
USER nobody | |
# Expose port | |
EXPOSE 7860 | |
# Set the entrypoint | |
ENTRYPOINT ["docker-entrypoint.sh"] |