fix: Manually implement nltk.downloader using cURL (#7817)

This commit is contained in:
Michael Genson
2026-06-27 22:11:55 -05:00
committed by GitHub
parent c9703d41c7
commit 7a12538267
2 changed files with 61 additions and 2 deletions

View File

@@ -131,6 +131,7 @@ RUN apt-get update \
iproute2 \
libldap-common \
libldap2 \
unzip \
&& rm -rf /var/lib/apt/lists/*
# create directory used for Docker Secrets
@@ -141,8 +142,8 @@ COPY --from=venv-builder $VENV_PATH $VENV_PATH
# install nltk data for the ingredient parser
ENV NLTK_DATA="/nltk_data/"
RUN mkdir -p $NLTK_DATA
RUN python -m nltk.downloader -d $NLTK_DATA averaged_perceptron_tagger_eng
COPY ./docker/setup_nltk_data.sh $MEALIE_HOME/setup_nltk_data.sh
RUN chmod +x $MEALIE_HOME/setup_nltk_data.sh && $MEALIE_HOME/setup_nltk_data.sh
VOLUME [ "$MEALIE_HOME/data/" ]
ENV APP_PORT=9000

58
docker/setup_nltk_data.sh Normal file
View File

@@ -0,0 +1,58 @@
#!/bin/bash
# ------------------------------------------------------------------------------
# Adapted from: https://github.com/community-scripts/ProxmoxVE/pull/14314
#
# Download NLTK data packages directly from GitHub, bypassing Python.
# Avoids CPU-instruction failures (SIGILL) on older hardware lacking AVX.
#
# Intended for use during Docker image build only.
#
# Environment:
# NLTK_DATA - Target directory for NLTK data (default: /usr/share/nltk_data)
#
# Returns: 0 on success, non-zero if any package failed
# ------------------------------------------------------------------------------
set -euo pipefail
NLTK_INDEX_URL="https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/index.xml"
PACKAGES="averaged_perceptron_tagger_eng"
TARGET_DIR="${NLTK_DATA:-/usr/share/nltk_data}"
echo "Fetching NLTK package index..."
index_xml=$(curl -fsSL "$NLTK_INDEX_URL")
mkdir -p "$TARGET_DIR"
for pkg in $PACKAGES; do
echo "Installing NLTK package: $pkg"
pkg_line=$(echo "$index_xml" | grep "id=\"${pkg}\"" | head -1)
if [[ -z "$pkg_line" ]]; then
echo "ERROR: NLTK package not found in index: $pkg" >&2
exit 1
fi
subdir=$(echo "$pkg_line" | grep -oP 'subdir="\K[^"]+')
pkg_url=$(echo "$pkg_line" | grep -oP 'url="\K[^"]+')
do_unzip=$(echo "$pkg_line" | grep -oP 'unzip="\K[^"]+')
if [[ -z "$subdir" || -z "$pkg_url" ]]; then
echo "ERROR: Could not parse NLTK index entry for: $pkg" >&2
exit 1
fi
mkdir -p "${TARGET_DIR}/${subdir}"
tmp_zip=$(mktemp --suffix=.zip)
echo "Downloading: $pkg_url"
curl -fsSL -o "$tmp_zip" "$pkg_url"
if [[ "$do_unzip" == "1" ]]; then
unzip -q -o "$tmp_zip" -d "${TARGET_DIR}/${subdir}/"
rm -f "$tmp_zip"
else
mv "$tmp_zip" "${TARGET_DIR}/${subdir}/${pkg}.zip"
fi
echo "Done: $pkg"
done