diff --git a/.gitignore b/.gitignore index 3060d663..1e6af914 100755 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,7 @@ .DS_Store __pycache__/ **/__pycache__/ -.vscode/launch.json -.vscode/tasks.json +**/.vscode/ *.pyc node_modules/ .history/ diff --git a/docker/docker-compose-aio.yml b/docker/docker-compose-aio.yml new file mode 100644 index 00000000..217005df --- /dev/null +++ b/docker/docker-compose-aio.yml @@ -0,0 +1,24 @@ +services: + dispatcharr: + build: + context: .. + dockerfile: docker/DockerfileAIO + container_name: dispatcharr-dev + restart: unless-stopped + ports: + - 9191:9191 + #- 5432:5432 + environment: + - PUID=1000 + - PGID=1000 + - POSTGRES_HOST=localhost + - POSTGRES_USER=dispatch + - POSTGRES_PASSWORD=secret + - POSTGRES_PORT=5432 + - POSTGRES_DB=dispatcharr + - DJANGO_SUPERUSER_USERNAME=admin + - DJANGO_SUPERUSER_PASSWORD=admin + - DJANGO_SUPERUSER_EMAIL=admin@dispatcharr.local + volumes: + - ./data:/app/data + diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index f91b062d..a928ce69 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -13,9 +13,15 @@ export POSTGRES_USER=${POSTGRES_USER:-dispatch} export POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-secret} export POSTGRES_HOST=${POSTGRES_HOST:-localhost} export POSTGRES_PORT=${POSTGRES_PORT:-5432} +export PUID=${PUID:-1000} +export PGID=${PGID:-1000} +export DJANGO_SUPERUSER_USERNAME=${DEFAULT_USERNAME:-admin} +export DJANGO_SUPERUSER_PASSWORD=${DEFAULT_PASSWORD:-admin} +export DJANGO_SUPERUSER_EMAIL=${DEFAULT_EMAIL:-admin@dispatcharr.local} export PGDATA=${PGDATA:-/app/data/db} export PG_BINDIR="/usr/lib/postgresql/14/bin" + # Echo environment variables for debugging echo_with_timestamp "POSTGRES_DB: $POSTGRES_DB" echo_with_timestamp "POSTGRES_USER: $POSTGRES_USER" @@ -104,17 +110,25 @@ fi # Start Redis echo_with_timestamp "Starting Redis..." -service redis-server start +su - $POSTGRES_USER -c 'redis-server --daemonize yes' # Run Django commands echo_with_timestamp "Running Django commands..." python manage.py collectstatic --noinput || true +python manage.py makemigrations --noinput || true python manage.py migrate --noinput || true +echo_with_timestamp "Checking if Django superuser exists..." +if ! python manage.py shell -c "from django.contrib.auth import get_user_model; exit(0) if get_user_model().objects.filter(username='${DJANGO_SUPERUSER_USERNAME}').exists() else exit(1)"; then + echo_with_timestamp "Superuser does not exist. Creating..." + python manage.py createsuperuser --noinput || true +else + echo_with_timestamp "Superuser already exists. Skipping creation." +fi # Start Celery echo_with_timestamp "Starting Celery..." -celery -A dispatcharr worker --loglevel=info & +su - $POSTGRES_USER -c 'cd /app && celery -A dispatcharr worker --loglevel=info &' # Start Gunicorn echo_with_timestamp "Starting Gunicorn..." -gunicorn --workers=4 --worker-class=gevent --timeout=300 --bind 0.0.0.0:9191 dispatcharr.wsgi:application \ No newline at end of file +su - $POSTGRES_USER -c 'cd /app && gunicorn --workers=4 --worker-class=gevent --timeout=300 --bind 0.0.0.0:9191 dispatcharr.wsgi:application' \ No newline at end of file