mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-11 20:05:19 +00:00
feat: auto cleanup orphan files
This commit is contained in:
parent
f440e9bfbe
commit
e15a864301
3 changed files with 59 additions and 3 deletions
11
Dockerfile
11
Dockerfile
|
|
@ -39,7 +39,7 @@ RUN npm ci --force
|
|||
|
||||
COPY . .
|
||||
ENV APP_BUILD_HASH=${BUILD_HASH}
|
||||
RUN npm run build
|
||||
RUN NODE_OPTIONS="--max_old_space_size=4096" npm run build
|
||||
|
||||
######## WebUI backend ########
|
||||
FROM python:3.11-slim-bookworm AS base
|
||||
|
|
@ -116,10 +116,9 @@ RUN echo -n 00000000-0000-0000-0000-000000000000 > $HOME/.cache/chroma/telemetry
|
|||
# Make sure the user has access to the app and root directory
|
||||
RUN chown -R $UID:$GID /app $HOME
|
||||
|
||||
# Install common system dependencies
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
git build-essential pandoc gcc netcat-openbsd curl jq \
|
||||
git build-essential pandoc gcc netcat-openbsd curl jq cron \
|
||||
python3-dev \
|
||||
ffmpeg libsm6 libxext6 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
|
@ -167,6 +166,12 @@ COPY --chown=$UID:$GID --from=build /app/package.json /app/package.json
|
|||
# copy backend files
|
||||
COPY --chown=$UID:$GID ./backend .
|
||||
|
||||
# Create directories for logs
|
||||
RUN mkdir -p /var/log && \
|
||||
touch /var/log/clean-orphaned-files.log && \
|
||||
chmod 644 /var/log/clean-orphaned-files.log && \
|
||||
chown $UID:$GID /var/log/clean-orphaned-files.log
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
HEALTHCHECK CMD curl --silent --fail http://localhost:${PORT:-8080}/health | jq -ne 'input.status == true' || exit 1
|
||||
|
|
|
|||
30
backend/setup-cron.sh
Normal file
30
backend/setup-cron.sh
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Create the wrapper script
|
||||
cat > /app/backend/run-cleanup-script.sh << 'EOL'
|
||||
#!/bin/bash
|
||||
# This script runs the clean-orphaned-files.py script with the proper environment variables
|
||||
|
||||
# Export all environment variables to the script
|
||||
export DATABASE_URL="${DATABASE_URL}"
|
||||
export ADMIN_TOKEN="${ADMIN_TOKEN:-your_admin_token}"
|
||||
export TEAMS_WEBHOOK_URL="${TEAMS_WEBHOOK_URL:-your_ms_teams_incoming_webhook_url}"
|
||||
|
||||
# Check if the script exists (it should be in a mounted volume)
|
||||
if [ -f /app/backend/data/scripts/clean-orphaned-files.py ]; then
|
||||
/usr/local/bin/python /app/backend/data/scripts/clean-orphaned-files.py --admin-token "${ADMIN_TOKEN}" --teams-webhook-url "${TEAMS_WEBHOOK_URL}" >> /var/log/clean-orphaned-files.log 2>&1
|
||||
else
|
||||
echo "$(date): Warning - clean-orphaned-files.py not found in mounted volume" >> /var/log/clean-orphaned-files.log
|
||||
fi
|
||||
EOL
|
||||
|
||||
# Make the wrapper script executable
|
||||
chmod +x /app/backend/run-cleanup-script.sh
|
||||
|
||||
# Create the cron job entry
|
||||
CRONJOB="0 */6 * * * /app/backend/run-cleanup-script.sh"
|
||||
|
||||
# Setup the crontab
|
||||
(crontab -l 2>/dev/null || echo "") | grep -v "run-cleanup-script.sh" | { cat; echo "$CRONJOB"; } | crontab -
|
||||
|
||||
echo "Cron job has been set up successfully."
|
||||
|
|
@ -35,6 +35,27 @@ if test "$WEBUI_SECRET_KEY $WEBUI_JWT_SECRET_KEY" = " "; then
|
|||
WEBUI_SECRET_KEY=$(cat "$KEY_FILE")
|
||||
fi
|
||||
|
||||
# Setup and start cron service
|
||||
echo "Setting up cron service..."
|
||||
if [ -x "$(command -v cron)" ]; then
|
||||
# Create necessary directories for scripts if they don't exist
|
||||
mkdir -p /app/backend/data/scripts
|
||||
|
||||
# Make the setup-cron.sh script executable
|
||||
chmod +x "$SCRIPT_DIR/setup-cron.sh"
|
||||
|
||||
# Run the cron setup script
|
||||
"$SCRIPT_DIR/setup-cron.sh"
|
||||
|
||||
# Start the cron service
|
||||
echo "Starting cron service..."
|
||||
service cron start || cron
|
||||
|
||||
echo "Cron service started."
|
||||
else
|
||||
echo "Warning: cron is not installed. Scheduled tasks will not run."
|
||||
fi
|
||||
|
||||
if [[ "${USE_OLLAMA_DOCKER,,}" == "true" ]]; then
|
||||
echo "USE_OLLAMA is set to true, starting ollama serve."
|
||||
ollama serve &
|
||||
|
|
|
|||
Loading…
Reference in a new issue