mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-07-10 17:50:20 -04:00
fix: Manually implement nltk.downloader using cURL (#7817)
This commit is contained in:
@@ -131,6 +131,7 @@ RUN apt-get update \
|
|||||||
iproute2 \
|
iproute2 \
|
||||||
libldap-common \
|
libldap-common \
|
||||||
libldap2 \
|
libldap2 \
|
||||||
|
unzip \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# create directory used for Docker Secrets
|
# 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
|
# install nltk data for the ingredient parser
|
||||||
ENV NLTK_DATA="/nltk_data/"
|
ENV NLTK_DATA="/nltk_data/"
|
||||||
RUN mkdir -p $NLTK_DATA
|
COPY ./docker/setup_nltk_data.sh $MEALIE_HOME/setup_nltk_data.sh
|
||||||
RUN python -m nltk.downloader -d $NLTK_DATA averaged_perceptron_tagger_eng
|
RUN chmod +x $MEALIE_HOME/setup_nltk_data.sh && $MEALIE_HOME/setup_nltk_data.sh
|
||||||
|
|
||||||
VOLUME [ "$MEALIE_HOME/data/" ]
|
VOLUME [ "$MEALIE_HOME/data/" ]
|
||||||
ENV APP_PORT=9000
|
ENV APP_PORT=9000
|
||||||
|
|||||||
58
docker/setup_nltk_data.sh
Normal file
58
docker/setup_nltk_data.sh
Normal 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
|
||||||
Reference in New Issue
Block a user