forked from NVIDIA-NeMo/Guardrails
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDockerfile.server
More file actions
75 lines (60 loc) · 2.47 KB
/
Dockerfile.server
File metadata and controls
75 lines (60 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
FROM registry.access.redhat.com/ubi9/python-312:latest as build
USER 0
WORKDIR /app
ARG PYYAML_VERSION=6.0.3
ARG GUARDRAILS_PROFILE=opensource
RUN dnf install -y --nodocs --setopt=install_weak_deps=False \
gcc \
gcc-c++ \
git && \
pip install --no-cache-dir \
pyyaml==${PYYAML_VERSION} && \
dnf clean all && \
rm -rf /var/cache/dnf /tmp/* /var/tmp/*
COPY requirements.txt pyproject.toml README.md ./
COPY nemoguardrails/ ./nemoguardrails/
COPY scripts/ ./scripts/
COPY examples/bots/ ./examples/bots/
RUN chmod +x ./scripts/entrypoint.sh
RUN python3 ./scripts/filter_guardrails.py ./scripts/provider-list.yaml $GUARDRAILS_PROFILE
ENV HF_HOME=/app/.cache/huggingface \
TRANSFORMERS_CACHE=/app/.cache/transformers \
SENTENCE_TRANSFORMERS_HOME=/app/.cache/sentence_transformers \
NLTK_DATA=/app/.cache/nltk_data \
FASTEMBED_CACHE_PATH=/app/.cache/fastembed
# Create virtual environment and install dependencies
RUN python3 -m venv /app/.venv && \
/app/.venv/bin/pip install --no-cache-dir \
--extra-index-url https://download.pytorch.org/whl/cpu \
-r requirements.txt && \
/app/.venv/bin/pip install --no-cache-dir --no-deps . && \
rm -rf /root/.cache/pip /tmp/* /var/tmp/*
# Pre-download required models and cleanup
RUN set -ex && \
GUARDRAILS_PROFILE=$GUARDRAILS_PROFILE /app/.venv/bin/python ./scripts/pre_download_required_models.py && \
find /app/.cache -type f -name "*.pyc" -delete && \
find /app/.cache -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true && \
find /app/.cache -type d -name ".git" -exec rm -rf {} + 2>/dev/null || true && \
rm -rf /app/.cache/huggingface/xet /root/.cache /tmp/* /var/tmp/* && \
dnf remove -y gcc gcc-c++ git && \
dnf clean all && \
rm -rf /var/cache/dnf
FROM registry.access.redhat.com/ubi9/python-312:latest as runtime
USER 0
WORKDIR /app
COPY --from=build /app /app
RUN rm -f /etc/security/namespace.conf /usr/lib64/security/pam_namespace.so || true && \
chgrp -R 0 /app && \
chmod -R g=u /app && \
chmod +x /app/scripts/entrypoint.sh
USER 1001
ENV HF_HOME=/app/.cache/huggingface \
TRANSFORMERS_CACHE=/app/.cache/transformers \
SENTENCE_TRANSFORMERS_HOME=/app/.cache/sentence_transformers \
NLTK_DATA=/app/.cache/nltk_data \
FASTEMBED_CACHE_PATH=/app/.cache/fastembed \
PATH="/app/.venv/bin:$PATH" \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
EXPOSE 8000
ENTRYPOINT ["./scripts/entrypoint.sh"]