Refactor install script for improved Python env setup
Updates Dispatcharr install script to use uv venv and pip for Python dependency management, adds explicit installation of key packages, and centralizes environment variables in a .env file for service scripts. Also updates Node and Python versions, improves service startup scripts to source environment variables, and enhances overall reliability and maintainability of the deployment process.
This commit is contained in:
parent
606eefd71d
commit
3077f8787a
@ -16,7 +16,9 @@ update_os
|
|||||||
msg_info "Installing Dependencies"
|
msg_info "Installing Dependencies"
|
||||||
$STD apt install -y \
|
$STD apt install -y \
|
||||||
build-essential \
|
build-essential \
|
||||||
|
git \
|
||||||
gcc \
|
gcc \
|
||||||
|
python3-dev \
|
||||||
libpq-dev \
|
libpq-dev \
|
||||||
nginx \
|
nginx \
|
||||||
redis-server \
|
redis-server \
|
||||||
@ -26,7 +28,7 @@ $STD apt install -y \
|
|||||||
msg_ok "Installed Dependencies"
|
msg_ok "Installed Dependencies"
|
||||||
|
|
||||||
setup_uv
|
setup_uv
|
||||||
NODE_VERSION="22" setup_nodejs
|
NODE_VERSION="24" setup_nodejs
|
||||||
PG_VERSION="16" setup_postgresql
|
PG_VERSION="16" setup_postgresql
|
||||||
|
|
||||||
msg_info "Creating PostgreSQL Database"
|
msg_info "Creating PostgreSQL Database"
|
||||||
@ -49,12 +51,23 @@ msg_ok "Created PostgreSQL Database"
|
|||||||
|
|
||||||
fetch_and_deploy_gh_release "dispatcharr" "Dispatcharr/Dispatcharr"
|
fetch_and_deploy_gh_release "dispatcharr" "Dispatcharr/Dispatcharr"
|
||||||
|
|
||||||
msg_info "Configuring Dispatcharr"
|
msg_info "Installing Python Dependencies with uv"
|
||||||
cd /opt/dispatcharr || exit
|
cd /opt/dispatcharr || exit
|
||||||
|
|
||||||
$STD uv sync --frozen
|
$STD uv venv
|
||||||
$STD uv run --frozen python manage.py migrate --noinput
|
$STD uv pip install -r requirements.txt --index-strategy unsafe-best-match
|
||||||
$STD uv run --frozen python manage.py collectstatic --noinput
|
$STD uv pip install gunicorn gevent celery redis daphne
|
||||||
|
msg_ok "Installed Python Dependencies"
|
||||||
|
|
||||||
|
msg_info "Configuring Dispatcharr"
|
||||||
|
export DATABASE_URL="postgresql://${DB_USER}:${DB_PASS}@localhost:5432/${DB_NAME}"
|
||||||
|
export POSTGRES_DB=$DB_NAME
|
||||||
|
export POSTGRES_USER=$DB_USER
|
||||||
|
export POSTGRES_PASSWORD=$DB_PASS
|
||||||
|
export POSTGRES_HOST=localhost
|
||||||
|
|
||||||
|
$STD uv run python manage.py migrate --noinput
|
||||||
|
$STD uv run python manage.py collectstatic --noinput
|
||||||
|
|
||||||
cd /opt/dispatcharr/frontend || exit
|
cd /opt/dispatcharr/frontend || exit
|
||||||
$STD npm install --legacy-peer-deps
|
$STD npm install --legacy-peer-deps
|
||||||
@ -105,18 +118,27 @@ msg_ok "Configured Nginx"
|
|||||||
|
|
||||||
msg_info "Creating Services"
|
msg_info "Creating Services"
|
||||||
|
|
||||||
|
# Create environment file for services
|
||||||
|
cat <<EOF >/opt/dispatcharr/.env
|
||||||
|
DATABASE_URL=postgresql://${DB_USER}:${DB_PASS}@localhost:5432/${DB_NAME}
|
||||||
|
POSTGRES_DB=$DB_NAME
|
||||||
|
POSTGRES_USER=$DB_USER
|
||||||
|
POSTGRES_PASSWORD=$DB_PASS
|
||||||
|
POSTGRES_HOST=localhost
|
||||||
|
CELERY_BROKER_URL=redis://localhost:6379/0
|
||||||
|
EOF
|
||||||
|
|
||||||
cat <<EOF >/opt/dispatcharr/start-gunicorn.sh
|
cat <<EOF >/opt/dispatcharr/start-gunicorn.sh
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
cd /opt/dispatcharr
|
cd /opt/dispatcharr
|
||||||
export POSTGRES_DB=$DB_NAME
|
set -a
|
||||||
export POSTGRES_USER=$DB_USER
|
source .env
|
||||||
export POSTGRES_PASSWORD=$DB_PASS
|
set +a
|
||||||
export POSTGRES_HOST=localhost
|
exec uv run gunicorn \\
|
||||||
uv run --frozen gunicorn \
|
--workers=4 \\
|
||||||
--workers=4 \
|
--worker-class=gevent \\
|
||||||
--worker-class=gevent \
|
--timeout=300 \\
|
||||||
--timeout=300 \
|
--bind 0.0.0.0:5656 \\
|
||||||
--bind 0.0.0.0:5656 \
|
|
||||||
dispatcharr.wsgi:application
|
dispatcharr.wsgi:application
|
||||||
EOF
|
EOF
|
||||||
chmod +x /opt/dispatcharr/start-gunicorn.sh
|
chmod +x /opt/dispatcharr/start-gunicorn.sh
|
||||||
@ -124,35 +146,30 @@ chmod +x /opt/dispatcharr/start-gunicorn.sh
|
|||||||
cat <<EOF >/opt/dispatcharr/start-celery.sh
|
cat <<EOF >/opt/dispatcharr/start-celery.sh
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
cd /opt/dispatcharr
|
cd /opt/dispatcharr
|
||||||
export POSTGRES_DB=$DB_NAME
|
set -a
|
||||||
export POSTGRES_USER=$DB_USER
|
source .env
|
||||||
export POSTGRES_PASSWORD=$DB_PASS
|
set +a
|
||||||
export POSTGRES_HOST=localhost
|
exec uv run celery -A dispatcharr worker -l info -c 4
|
||||||
export CELERY_BROKER_URL=redis://localhost:6379/0
|
|
||||||
uv run --frozen celery -A dispatcharr worker -l info -c 4
|
|
||||||
EOF
|
EOF
|
||||||
chmod +x /opt/dispatcharr/start-celery.sh
|
chmod +x /opt/dispatcharr/start-celery.sh
|
||||||
|
|
||||||
cat <<EOF >/opt/dispatcharr/start-celerybeat.sh
|
cat <<EOF >/opt/dispatcharr/start-celerybeat.sh
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
cd /opt/dispatcharr
|
cd /opt/dispatcharr
|
||||||
export POSTGRES_DB=$DB_NAME
|
set -a
|
||||||
export POSTGRES_USER=$DB_USER
|
source .env
|
||||||
export POSTGRES_PASSWORD=$DB_PASS
|
set +a
|
||||||
export POSTGRES_HOST=localhost
|
exec uv run celery -A dispatcharr beat -l info
|
||||||
export CELERY_BROKER_URL=redis://localhost:6379/0
|
|
||||||
uv run --frozen celery -A dispatcharr beat -l info
|
|
||||||
EOF
|
EOF
|
||||||
chmod +x /opt/dispatcharr/start-celerybeat.sh
|
chmod +x /opt/dispatcharr/start-celerybeat.sh
|
||||||
|
|
||||||
cat <<EOF >/opt/dispatcharr/start-daphne.sh
|
cat <<EOF >/opt/dispatcharr/start-daphne.sh
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
cd /opt/dispatcharr
|
cd /opt/dispatcharr
|
||||||
export POSTGRES_DB=$DB_NAME
|
set -a
|
||||||
export POSTGRES_USER=$DB_USER
|
source .env
|
||||||
export POSTGRES_PASSWORD=$DB_PASS
|
set +a
|
||||||
export POSTGRES_HOST=localhost
|
exec uv run daphne -b 0.0.0.0 -p 8001 dispatcharr.asgi:application
|
||||||
uv run --frozen daphne -b 0.0.0.0 -p 8001 dispatcharr.asgi:application
|
|
||||||
EOF
|
EOF
|
||||||
chmod +x /opt/dispatcharr/start-daphne.sh
|
chmod +x /opt/dispatcharr/start-daphne.sh
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user