diff --git a/Dockerfile b/Dockerfile index 77efc84..ef62306 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,8 +13,14 @@ RUN pip install --no-cache-dir -r requirements.txt COPY . . +RUN mkdir -p /app/data + RUN python manage.py collectstatic --noinput 2>/dev/null || true EXPOSE 8000 +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] CMD ["gunicorn", "--bind", "0.0.0.0:8000", "eng_bot_metrics.wsgi:application"] diff --git a/eng_bot_metrics/settings.py b/eng_bot_metrics/settings.py index b5dacb5..ca7f100 100644 --- a/eng_bot_metrics/settings.py +++ b/eng_bot_metrics/settings.py @@ -37,12 +37,15 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'corsheaders', 'metrics', ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', @@ -73,10 +76,14 @@ WSGI_APPLICATION = 'eng_bot_metrics.wsgi.application' # Database # https://docs.djangoproject.com/en/6.0/ref/settings/#databases +import os + +DATA_DIR = Path(os.environ.get('DATA_DIR', BASE_DIR)) + DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', + 'NAME': DATA_DIR / 'db.sqlite3', } } @@ -116,3 +123,23 @@ USE_TZ = True # https://docs.djangoproject.com/en/6.0/howto/static-files/ STATIC_URL = 'static/' +STATIC_ROOT = BASE_DIR / 'staticfiles' +STORAGES = { + "staticfiles": { + "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", + }, + "default": { + "BACKEND": "django.core.files.storage.FileSystemStorage", + }, +} + +# Default primary key field type +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +# CORS settings +CORS_ALLOWED_ORIGINS = [ + 'http://localhost:3000', + 'http://localhost:3001', + 'http://frontend:3000', +] +CORS_ALLOW_CREDENTIALS = True diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..6b550c5 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -e + +python manage.py migrate --noinput + +exec "$@" diff --git a/requirements.txt b/requirements.txt index e4dec2d..01721ce 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,5 @@ Django==6.0 asgiref==3.11.0 sqlparse==0.5.4 gunicorn==23.0.0 +django-cors-headers==4.6.0 +whitenoise==6.7.0