chaaim123 commited on
Commit
01d580f
·
verified ·
1 Parent(s): e1482b2

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +89 -0
Dockerfile ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use your base image
2
+ FROM python:3.13
3
+
4
+ # Set Hugging Face Space environment flag
5
+ #ENV HF_SPACE=1
6
+
7
+ # Set environment variables for runtime directories
8
+ ENV CHROMADB_PATH=/data/chroma_db
9
+ ENV LOG_DIR=/data/logs
10
+ ENV DEBUG_DIR=/data/debug
11
+ ENV CACHE_DIR=/data/cache
12
+ ENV HF_HOME=/data/cache/huggingface
13
+ ENV DATA_DIR=/data
14
+
15
+ # Create necessary directories as root
16
+ RUN mkdir -p /data/chroma_db && \
17
+ mkdir -p /data/logs && \
18
+ mkdir -p /data/debug && \
19
+ mkdir -p /data/cache/huggingface
20
+
21
+ # Set up the user after creating directories
22
+ RUN useradd -m -u 1000 user
23
+
24
+ # # Add user to staff group to access /data
25
+ RUN usermod -a -G staff user
26
+
27
+ # # Make directories writable by the staff group
28
+ RUN chown -R root:staff /data && \
29
+ chmod -R g+w /data
30
+
31
+ # Switch to the "user" user
32
+ USER user
33
+
34
+ # Set home to the user's home directory
35
+ ENV HOME=/home/user \
36
+ PATH=/home/user/.local/bin:$PATH
37
+
38
+ # Set working directory
39
+ WORKDIR /code
40
+
41
+
42
+ # Copy requirements file and install dependencies
43
+ COPY ./requirements.txt /code/requirements.txt
44
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
45
+
46
+ COPY . .
47
+
48
+ ARG HF_API_KEY
49
+ ENV HUGGINGFACE_HUB_TOKEN=$HF_API_KEY
50
+
51
+ RUN python -c "\
52
+ from huggingface_hub import snapshot_download; \
53
+ snapshot_download(repo_id='rressler/au_advisor_db', repo_type='model', local_dir='/data')"
54
+
55
+ RUN ls -lah /data/chroma_db && \
56
+ find /data/chroma_db -type f -exec ls -lah {} \; && \
57
+ echo "Total size of chroma_db directory:" && \
58
+ du -sh /data/chroma_db
59
+
60
+ # RUN ls -R /data/chroma_db
61
+
62
+ # Create a symbolic link so the code can find the database in expected location
63
+ RUN mkdir -p /code/data && \
64
+ ln -s /data/chroma_db /code/data/chroma_db && \
65
+ ln -s /data/logs /code/data/logs && \
66
+ ln -s /data/debug /code/data/debug
67
+ RUN ls -la /code/data && \
68
+ readlink -f /code/data/chroma_db && \
69
+ echo "Expected path: /data/chroma_db" && \
70
+ find /code/data/chroma_db -type f | head -5 && \
71
+ echo "------" && \
72
+ find /data/chroma_db -type f | head -5
73
+
74
+ RUN python -c "\
75
+ import chromadb; \
76
+ client = chromadb.PersistentClient(path='/code/data/chroma_db'); \
77
+ collections = client.list_collections(); \
78
+ print(f'✅ Found collections: {[c.name for c in collections]}'); \
79
+ col = client.get_or_create_collection('documents'); \
80
+ docs = col.get(); \
81
+ print(f'📄 Document count: {len(docs[\"ids\"])}'); \
82
+ print(f'🔍 Sample IDs: {docs[\"ids\"][:5]}') \
83
+ "
84
+
85
+ # Expose port 7860 - this is the port Hugging Face Spaces expects
86
+ EXPOSE 7860
87
+
88
+ # Command to run the Shiny application
89
+ CMD ["shiny", "run", "app.py", "--host", "0.0.0.0", "--port", "7860"]