fixing docker build

This commit is contained in:
dekzter 2025-03-02 14:56:18 -05:00
parent d5609a021d
commit 02cf53383d
5 changed files with 105 additions and 77 deletions

View file

@ -15,9 +15,7 @@ RUN apt-get update && \
libpq-dev \
lsb-release \
python3-virtualenv \
streamlink \
uwsgi \
python3-django-uwsgi
streamlink
RUN \
curl -sL https://deb.nodesource.com/setup_23.x -o /tmp/nodesource_setup.sh && \

View file

@ -1,20 +1,105 @@
#!/bin/sh
#!/bin/bash
# Check the value of DISPATCHARR_ENV and run the corresponding program
case "$DISPATCHARR_ENV" in
"dev")
echo "DISPATCHARR_ENV is set to 'dev'. Running Development Program..."
apt-get update && apt-get install -y nodejs
cd /app/frontend && npm install
cd /app
exec /usr/bin/uwsgi --ini uwsgi.dev.ini
;;
"aio")
echo "DISPATCHARR_ENV is set to 'aio'. Running All-in-One Program..."
exec /usr/bin/uwsgi --ini uwsgi.aio.ini
;;
*)
echo "DISPATCHARR_ENV is not set or has an unexpected value. Running standalone..."
exec /usr/bin/uwsgi --ini uwsgi.ini
;;
esac
# Run Django migrations and collect static files
python manage.py collectstatic --noinput
python manage.py migrate --noinput
# Function to clean up only running processes
cleanup() {
echo "🔥 Cleanup triggered! Stopping services..."
for pid in "${pids[@]}"; do
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
echo "⛔ Stopping process (PID: $pid)..."
kill -TERM "$pid" 2>/dev/null
else
echo "✅ Process (PID: $pid) already stopped."
fi
done
wait
}
# Catch termination signals (CTRL+C, Docker Stop, etc.)
trap cleanup TERM INT
# Initialize an array to store PIDs
pids=()
GUNICORN_PORT=9191
# If running in development mode, install and start frontend
if [ "$DISPATCHARR_ENV" = "dev" ]; then
echo "🚀 Development Mode - Setting up Frontend..."
GUNICORN_PORT=5656
# Install Node.js
apt-get update && apt-get install -y nodejs
# Install frontend dependencies
cd /app/frontend && npm install
cd /app
# Start React development server
echo "🚀 Starting React Dev Server..."
cd /app/frontend
PORT=9191 ./node_modules/pm2/bin/pm2 --name test start npm -- start
./node_modules/pm2/bin/pm2 logs &
react_pid=$!
echo "✅ React started with PID $react_pid"
pids+=("$react_pid")
cd /app
fi
# If running in `dev` or `aio`, start Redis and Celery
if [ "$DISPATCHARR_ENV" = "dev" ] || [ "$DISPATCHARR_ENV" = "aio" ]; then
echo "🚀 Running Redis and Celery for '$DISPATCHARR_ENV'..."
# Start Redis
echo "🚀 Starting Redis..."
redis-server --daemonize no &
sleep 1 # Give Redis time to start
redis_pid=$(pgrep -x redis-server)
if [ -n "$redis_pid" ]; then
echo "✅ Redis started with PID $redis_pid"
pids+=("$redis_pid")
else
echo "❌ Redis failed to start!"
fi
# Start Celery
echo "🚀 Starting Celery..."
celery -A dispatcharr worker -l info &
celery_pid=$!
echo "✅ Celery started with PID $celery_pid"
pids+=("$celery_pid")
fi
# Always start Gunicorn
echo "🚀 Starting Gunicorn..."
gunicorn --workers=4 --worker-class=gevent --timeout=300 --bind 0.0.0.0:${GUNICORN_PORT} dispatcharr.wsgi:application &
gunicorn_pid=$!
echo "✅ Gunicorn started with PID $gunicorn_pid"
pids+=("$gunicorn_pid")
# Log PIDs
echo "📝 Process PIDs: ${pids[*]}"
# Wait for at least one process to exit and log the process that exited first
if [ ${#pids[@]} -gt 0 ]; then
echo "⏳ Waiting for processes to exit..."
ps -aux | grep -E 'redis-server|celery|gunicorn|npm'
wait -n "${pids[@]}"
echo "🚨 One of the processes exited! Checking which one..."
for pid in "${pids[@]}"; do
if ! kill -0 "$pid" 2>/dev/null; then
process_name=$(ps -p "$pid" -o comm=)
echo "❌ Process $process_name (PID: $pid) has exited!"
fi
done
else
echo "❌ No processes started. Exiting."
exit 1
fi
# Cleanup and stop remaining processes
cleanup

View file

@ -1,19 +0,0 @@
[uwsgi]
exec-pre-app = python manage.py collectstatic --noinput
exec-pre-app = python manage.py migrate --noinput
http-socket = [::]:9191
buffer-size = 32768
enable-threads
plugin = python3
module = dispatcharr.wsgi:application
static-map = /static=staticfiles
thunder-lock
disable-write-exception
virtualenv = /dispatcharrpy
max-fd = 10000
attach-daemon = celery -A dispatcharr worker -l info
attach-daemon = redis-server

View file

@ -1,20 +0,0 @@
[uwsgi]
exec-pre-app = python manage.py collectstatic --noinput
exec-pre-app = python manage.py migrate --noinput
http-socket = [::]:5656
buffer-size = 32768
enable-threads
plugin = python3
module = dispatcharr.wsgi:application
static-map = /static=staticfiles
thunder-lock
disable-write-exception
virtualenv = /dispatcharrpy
max-fd = 10000
attach-daemon = celery -A dispatcharr worker -l info
attach-daemon = redis-server
attach-daemon = cd /app/frontend && npm run start

View file

@ -1,16 +0,0 @@
[uwsgi]
exec-pre-app = python manage.py collectstatic --noinput
exec-pre-app = python manage.py migrate --noinput
http-socket = [::]:9191
buffer-size = 32768
enable-threads
plugin = python3
module = dispatcharr.wsgi:application
static-map = /static=staticfiles
thunder-lock
disable-write-exception
virtualenv = /dispatcharrpy
max-fd = 10000