Dockerfile
1 # Set base image 2 ARG BASE_IMAGE=python:3.10-slim 3 FROM $BASE_IMAGE 4 5 # Install GPU-enabled version of PyTorch if set 6 ARG GPU 7 8 # Target CPU architecture 9 ARG TARGETARCH 10 11 # Set Python version (i.e. 3, 3.10) 12 ARG PYTHON_VERSION=3 13 14 # List of txtai components to install 15 ARG COMPONENTS=[all] 16 17 # Locale environment variables 18 ENV LC_ALL=C.UTF-8 19 ENV LANG=C.UTF-8 20 21 RUN \ 22 # Install required packages 23 apt-get update && \ 24 apt-get -y --no-install-recommends install libgomp1 libportaudio2 libsndfile1 git gcc g++ python${PYTHON_VERSION} python${PYTHON_VERSION}-dev python3-pip && \ 25 rm -rf /var/lib/apt/lists && \ 26 \ 27 # Install txtai project and dependencies 28 ln -s /usr/bin/python${PYTHON_VERSION} /usr/bin/python && \ 29 python -m pip install --no-cache-dir -U pip wheel setuptools && \ 30 if [ -z ${GPU} ] && { [ -z ${TARGETARCH} ] || [ ${TARGETARCH} = "amd64" ] ;}; then pip install --no-cache-dir torch==2.11.0+cpu torchvision==0.26.0+cpu -f https://download.pytorch.org/whl/torch -f https://download.pytorch.org/whl/torchvision; fi && \ 31 python -m pip install --no-cache-dir txtai${COMPONENTS} && \ 32 python -c "import sys, importlib.util as util; 1 if util.find_spec('nltk') else sys.exit(); import nltk; nltk.download(['punkt', 'punkt_tab', 'averaged_perceptron_tagger_eng'])" && \ 33 \ 34 # Cleanup build packages 35 apt-get -y purge git gcc g++ python${PYTHON_VERSION}-dev && apt-get -y autoremove 36 37 # Set default working directory 38 WORKDIR /app