From 7a125382671c638d75d92c89c4b5f2d86ceaabdc Mon Sep 17 00:00:00 2001 From: Michael Genson <71845777+michael-genson@users.noreply.github.com> Date: Sat, 27 Jun 2026 22:11:55 -0500 Subject: [PATCH] fix: Manually implement nltk.downloader using cURL (#7817) --- docker/Dockerfile | 5 ++-- docker/setup_nltk_data.sh | 58 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 docker/setup_nltk_data.sh diff --git a/docker/Dockerfile b/docker/Dockerfile index 24f03cca6..7842c8954 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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 diff --git a/docker/setup_nltk_data.sh b/docker/setup_nltk_data.sh new file mode 100644 index 000000000..d523f7d27 --- /dev/null +++ b/docker/setup_nltk_data.sh @@ -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