demo10 / Dockerfile
chaaim123's picture
Create Dockerfile
01d580f verified
# Use your base image
FROM python:3.13
# Set Hugging Face Space environment flag
#ENV HF_SPACE=1
# Set environment variables for runtime directories
ENV CHROMADB_PATH=/data/chroma_db
ENV LOG_DIR=/data/logs
ENV DEBUG_DIR=/data/debug
ENV CACHE_DIR=/data/cache
ENV HF_HOME=/data/cache/huggingface
ENV DATA_DIR=/data
# Create necessary directories as root
RUN mkdir -p /data/chroma_db && \
mkdir -p /data/logs && \
mkdir -p /data/debug && \
mkdir -p /data/cache/huggingface
# Set up the user after creating directories
RUN useradd -m -u 1000 user
# # Add user to staff group to access /data
RUN usermod -a -G staff user
# # Make directories writable by the staff group
RUN chown -R root:staff /data && \
chmod -R g+w /data
# Switch to the "user" user
USER user
# Set home to the user's home directory
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
# Set working directory
WORKDIR /code
# Copy requirements file and install dependencies
COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
COPY . .
ARG HF_API_KEY
ENV HUGGINGFACE_HUB_TOKEN=$HF_API_KEY
RUN python -c "\
from huggingface_hub import snapshot_download; \
snapshot_download(repo_id='rressler/au_advisor_db', repo_type='model', local_dir='/data')"
RUN ls -lah /data/chroma_db && \
find /data/chroma_db -type f -exec ls -lah {} \; && \
echo "Total size of chroma_db directory:" && \
du -sh /data/chroma_db
# RUN ls -R /data/chroma_db
# Create a symbolic link so the code can find the database in expected location
RUN mkdir -p /code/data && \
ln -s /data/chroma_db /code/data/chroma_db && \
ln -s /data/logs /code/data/logs && \
ln -s /data/debug /code/data/debug
RUN ls -la /code/data && \
readlink -f /code/data/chroma_db && \
echo "Expected path: /data/chroma_db" && \
find /code/data/chroma_db -type f | head -5 && \
echo "------" && \
find /data/chroma_db -type f | head -5
RUN python -c "\
import chromadb; \
client = chromadb.PersistentClient(path='/code/data/chroma_db'); \
collections = client.list_collections(); \
print(f'βœ… Found collections: {[c.name for c in collections]}'); \
col = client.get_or_create_collection('documents'); \
docs = col.get(); \
print(f'πŸ“„ Document count: {len(docs[\"ids\"])}'); \
print(f'πŸ” Sample IDs: {docs[\"ids\"][:5]}') \
"
# Expose port 7860 - this is the port Hugging Face Spaces expects
EXPOSE 7860
# Command to run the Shiny application
CMD ["shiny", "run", "app.py", "--host", "0.0.0.0", "--port", "7860"]