fix docker-django/cron problem
This commit is contained in:
		| @@ -21,7 +21,7 @@ COPY . /app | |||||||
|  |  | ||||||
| # Optional non-root user (not used as default to allow cron) | # Optional non-root user (not used as default to allow cron) | ||||||
| RUN useradd -ms /bin/bash app && chown -R app:app /app | RUN useradd -ms /bin/bash app && chown -R app:app /app | ||||||
| # USER app  # keep running as root to manage cron | # USER app | ||||||
|  |  | ||||||
| # Runtime env defaults | # Runtime env defaults | ||||||
| ENV DJANGO_DEBUG=true \ | ENV DJANGO_DEBUG=true \ | ||||||
|   | |||||||
| @@ -1,8 +1,6 @@ | |||||||
| #!/usr/bin/env bash | #!/usr/bin/env bash | ||||||
| set -euo pipefail | set -euo pipefail | ||||||
|  |  | ||||||
| # Wait for potential dependencies (none for sqlite) |  | ||||||
|  |  | ||||||
| # Apply migrations | # Apply migrations | ||||||
| python manage.py migrate --noinput | python manage.py migrate --noinput | ||||||
|  |  | ||||||
| @@ -20,19 +18,11 @@ username = os.environ['ADMIN_USERNAME'] | |||||||
| password = os.environ['ADMIN_PASSWORD'] | password = os.environ['ADMIN_PASSWORD'] | ||||||
| email = os.environ.get('ADMIN_EMAIL') or f"{username}@local" | email = os.environ.get('ADMIN_EMAIL') or f"{username}@local" | ||||||
| user, created = User.objects.get_or_create(username=username, defaults={'email': email}) | user, created = User.objects.get_or_create(username=username, defaults={'email': email}) | ||||||
| if created: | user.set_password(password) | ||||||
|     user.set_password(password) | user.is_superuser = True | ||||||
|     user.is_superuser = True | user.is_staff = True | ||||||
|     user.is_staff = True | user.is_admin = True | ||||||
|     user.is_admin = True | user.save() | ||||||
|     user.save() |  | ||||||
| else: |  | ||||||
|     # update password if user exists |  | ||||||
|     user.set_password(password) |  | ||||||
|     user.is_superuser = True |  | ||||||
|     user.is_staff = True |  | ||||||
|     user.is_admin = True |  | ||||||
|     user.save() |  | ||||||
| print("Admin ready") | print("Admin ready") | ||||||
| PY | PY | ||||||
| fi | fi | ||||||
| @@ -75,14 +65,14 @@ s.save() | |||||||
| print("AppSettings seeded from environment (if provided)") | print("AppSettings seeded from environment (if provided)") | ||||||
| PY | PY | ||||||
|  |  | ||||||
| # Start cron for periodic job if schedule is set | # Setup cron if schedule provided | ||||||
| if [[ -n "${CRON_SCHEDULE:-}" ]]; then | if [[ -n "${CRON_SCHEDULE:-}" ]]; then | ||||||
|   echo "Setting cron schedule: ${CRON_SCHEDULE}" |   echo "Configuring cron: ${CRON_SCHEDULE}" | ||||||
|   # write cronjob to user crontab |   echo "${CRON_SCHEDULE} cd /app && /usr/local/bin/python manage.py check_new_media >> /app/cron.log 2>&1" > /etc/cron.d/subscribarr | ||||||
|   CRONLINE="${CRON_SCHEDULE} cd /app && /usr/local/bin/python manage.py check_new_media >> /app/cron.log 2>&1" |   chmod 0644 /etc/cron.d/subscribarr | ||||||
|   (crontab -l 2>/dev/null; echo "$CRONLINE") | crontab - |   crontab /etc/cron.d/subscribarr | ||||||
|   crond |   /usr/sbin/cron | ||||||
| fi | fi | ||||||
|  |  | ||||||
| # Start server | # Run server | ||||||
| exec python manage.py runserver 0.0.0.0:8000 | exec python manage.py runserver 0.0.0.0:8000 | ||||||
|   | |||||||
| @@ -120,7 +120,7 @@ USE_TZ = True | |||||||
| # Static files (CSS, JavaScript, Images) | # Static files (CSS, JavaScript, Images) | ||||||
| # https://docs.djangoproject.com/en/5.2/howto/static-files/ | # https://docs.djangoproject.com/en/5.2/howto/static-files/ | ||||||
|  |  | ||||||
| STATIC_URL = 'static/' | STATIC_URL = '/static/' | ||||||
| STATICFILES_DIRS = [BASE_DIR / 'static'] | STATICFILES_DIRS = [BASE_DIR / 'static'] | ||||||
| # STATIC_ROOT could be set for collectstatic in production | # STATIC_ROOT could be set for collectstatic in production | ||||||
| # STATIC_ROOT = BASE_DIR / 'staticfiles' | # STATIC_ROOT = BASE_DIR / 'staticfiles' | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user