self-trained2 / Dockerfile
DeepImagix's picture
Update Dockerfile
a31519b verified
# Start with a standard, lightweight Python base image
FROM python:3.10-slim
# Create non-root user with explicit UID
RUN adduser --disabled-password --gecos '' --uid 1000 appuser
# Set environment variables for Hugging Face cache
ENV HF_HOME=/data/huggingface_cache
#ENV TRANSFORMERS_CACHE=/data/huggingface_cache
#ENV TORCH_HOME=/data/huggingface_cache
# Create persistent data directories
RUN mkdir -p /data/user_models_data \
&& mkdir -p /data/huggingface_cache
# Set the working directory
WORKDIR /code
# Copy requirements first to leverage Docker cache
COPY ./requirements.txt /code/requirements.txt
# Install dependencies
RUN pip install --upgrade pip \
&& pip install --no-cache-dir --upgrade -r /code/requirements.txt
# Pre-download the sentence-transformers model as root
#RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')"
# Copy all individual files
COPY ./utils.py /code/utils.py
COPY ./main.py /code/main.py
COPY ./neura_self_hosted.py /code/neura_self_hosted.py
COPY ./model_info.py /code/model_info.py
COPY ./maintenance_control.py /code/maintenance_control.py
COPY ./usage_logger.py /code/usage_logger.py
COPY ./admin_panel.py /code/admin_panel.py
COPY ./crypto_payment.py /code/crypto_payment.py
COPY ./ai_ads.py /code/ai_ads.py
COPY ./neuroprompt_deep.py /code/neuroprompt_deep.py
# Copy user models data
COPY ./user_models_data /data/user_models_data
COPY ./static /data/static
# Set proper ownership for all directories
RUN chown -R appuser:appuser /data /code \
&& chmod -R 775 /data
# Fix cache ownership after model download
RUN chown -R appuser:appuser /data/huggingface_cache
# Volume to make learned data persistent
#VOLUME /data/user_models_data
# Switch to non-root user
USER appuser
# Expose the port used by Uvicorn
EXPOSE 7860
# Start the app
# This command activates your new AI
#uvicorn neura_self_hosted:app --reload
#CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
# Change the CMD to:
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1", "--timeout-keep-alive", "2000"]