davidtran999 commited on
Commit
b1a8c9c
·
verified ·
1 Parent(s): bd6c881

Upload Dockerfile with huggingface_hub

Browse files
Files changed (1) hide show
  1. Dockerfile +15 -45
Dockerfile CHANGED
@@ -1,9 +1,12 @@
1
  FROM python:3.11-slim
2
 
3
- ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
 
 
 
 
4
  WORKDIR /app
5
 
6
- # System dependencies (OCR + build essentials)
7
  RUN apt-get update && \
8
  apt-get install -y --no-install-recommends \
9
  build-essential \
@@ -12,53 +15,20 @@ RUN apt-get update && \
12
  tesseract-ocr-vie \
13
  libpoppler-cpp-dev \
14
  pkg-config \
15
- libgl1 && \
16
- rm -rf /var/lib/apt/lists/*
17
 
18
  COPY backend/requirements.txt /app/requirements.txt
19
- RUN pip install --no-cache-dir -r requirements.txt
20
-
21
- # Optional check: cố gắng import CrossEncoder, nhưng KHÔNG dừng build nếu thiếu
22
- RUN python -c "from sentence_transformers import CrossEncoder; print('[Docker] ✅ CrossEncoder available for reranking')" || \
23
- echo "[Docker] CrossEncoder not available! Tiếp tục build, backend sẽ tự fallback không dùng reranker."
24
-
25
- # Copy toàn bộ backend để tránh lệch phiên bản
26
- COPY backend /app/backend
27
- RUN ln -sfn /app/backend/hue_portal /app/hue_portal
28
-
29
- # Create static and media directories
30
- RUN mkdir -p /app/hue_portal/static /app/hue_portal/media
31
-
32
- # Create entrypoint script to run lightweight migrations before starting server
33
- RUN cat <<'EOF' >/entrypoint.sh
34
- #!/bin/bash
35
- set -e
36
-
37
- echo "[Docker] Running migrations..."
38
- if ! python /app/hue_portal/manage.py migrate --noinput; then
39
- echo "[Docker] Migration failed, retrying with SQLite fallback..."
40
- unset DATABASE_URL
41
- python /app/hue_portal/manage.py migrate --noinput || echo "[Docker] SQLite migration also failed, continuing..."
42
- fi
43
-
44
- RUN_HEAVY_STARTUP_TASKS="${RUN_HEAVY_STARTUP_TASKS:-0}"
45
- if [ "$RUN_HEAVY_STARTUP_TASKS" = "1" ]; then
46
- echo "[Docker] Running heavy startup tasks (generate QA, train intent, populate tsv)..."
47
- python /app/hue_portal/manage.py generate_legal_questions || echo "[Docker] generate_legal_questions failed, continuing..."
48
- python /app/hue_portal/chatbot/training/train_intent.py || echo "[Docker] Intent training failed, continuing..."
49
- python /app/hue_portal/manage.py populate_legal_tsv || echo "[Docker] populate_legal_tsv failed, continuing..."
50
- else
51
- echo "[Docker] Skipping heavy startup tasks (RUN_HEAVY_STARTUP_TASKS=$RUN_HEAVY_STARTUP_TASKS)."
52
- fi
53
-
54
- echo "[Docker] Collecting static files..."
55
- python /app/hue_portal/manage.py collectstatic --noinput || echo "[Docker] Collectstatic failed, continuing..."
56
 
57
- echo "[Docker] Starting gunicorn..."
58
- exec gunicorn -b 0.0.0.0:7860 --timeout 1800 --graceful-timeout 1800 --worker-class sync hue_portal.hue_portal.wsgi:application
59
- EOF
60
 
 
61
  RUN chmod +x /entrypoint.sh
62
 
63
- EXPOSE 7860
64
  CMD ["/entrypoint.sh"]
 
1
  FROM python:3.11-slim
2
 
3
+ ENV PYTHONDONTWRITEBYTECODE=1 \
4
+ PYTHONUNBUFFERED=1 \
5
+ PIP_NO_CACHE_DIR=1 \
6
+ PORT=7860
7
+
8
  WORKDIR /app
9
 
 
10
  RUN apt-get update && \
11
  apt-get install -y --no-install-recommends \
12
  build-essential \
 
15
  tesseract-ocr-vie \
16
  libpoppler-cpp-dev \
17
  pkg-config \
18
+ libgl1 \
19
+ && rm -rf /var/lib/apt/lists/*
20
 
21
  COPY backend/requirements.txt /app/requirements.txt
22
+ RUN pip install --upgrade pip && \
23
+ pip install --no-cache-dir --upgrade --force-reinstall \
24
+ "transformers==4.48.0" \
25
+ "sentence-transformers>=2.2.0" \
26
+ "FlagEmbedding>=1.2.0" && \
27
+ pip install --no-cache-dir -r requirements.txt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
+ COPY backend /app
 
 
30
 
31
+ COPY entrypoint.sh /entrypoint.sh
32
  RUN chmod +x /entrypoint.sh
33
 
 
34
  CMD ["/entrypoint.sh"]