diff --git a/.vs/DjangoProject/v17/.wsuo b/.vs/DjangoProject/v17/.wsuo new file mode 100644 index 0000000..252c014 Binary files /dev/null and b/.vs/DjangoProject/v17/.wsuo differ diff --git a/.vs/DjangoProject/v17/DocumentLayout.backup.json b/.vs/DjangoProject/v17/DocumentLayout.backup.json new file mode 100644 index 0000000..84371fa --- /dev/null +++ b/.vs/DjangoProject/v17/DocumentLayout.backup.json @@ -0,0 +1,27 @@ +{ + "Version": 1, + "WorkspaceRootPath": "D:\\DjangoProject\\", + "Documents": [], + "DocumentGroupContainers": [ + { + "Orientation": 0, + "VerticalTabListWidth": 256, + "DocumentGroups": [ + { + "DockedWidth": 200, + "SelectedChildIndex": -1, + "Children": [ + { + "$type": "Bookmark", + "Name": "ST:0:0:{aa2115a1-9712-457b-9047-dbb71ca2cdd2}" + }, + { + "$type": "Bookmark", + "Name": "ST:0:0:{1c4feeaa-4718-4aa9-859d-94ce25d182ba}" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/.vs/DjangoProject/v17/DocumentLayout.json b/.vs/DjangoProject/v17/DocumentLayout.json new file mode 100644 index 0000000..4bf8700 --- /dev/null +++ b/.vs/DjangoProject/v17/DocumentLayout.json @@ -0,0 +1,96 @@ +{ + "Version": 1, + "WorkspaceRootPath": "D:\\DjangoProject\\", + "Documents": [ + { + "AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|D:\\DjangoProject\\nginx\\nginx.conf||{3B902123-F8A7-4915-9F01-361F908088D0}", + "RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:nginx\\nginx.conf||{3B902123-F8A7-4915-9F01-361F908088D0}" + }, + { + "AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|D:\\DjangoProject\\docker-compose.yml||{8B382828-6202-11D1-8870-0000F87579D2}", + "RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:docker-compose.yml||{8B382828-6202-11D1-8870-0000F87579D2}" + }, + { + "AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|D:\\DjangoProject\\Dockerfile||{8B382828-6202-11D1-8870-0000F87579D2}", + "RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:Dockerfile||{8B382828-6202-11D1-8870-0000F87579D2}" + }, + { + "AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|D:\\DjangoProject\\app\\config\\settings.py||{8B382828-6202-11D1-8870-0000F87579D2}", + "RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:app\\config\\settings.py||{8B382828-6202-11D1-8870-0000F87579D2}" + } + ], + "DocumentGroupContainers": [ + { + "Orientation": 0, + "VerticalTabListWidth": 256, + "DocumentGroups": [ + { + "DockedWidth": 200, + "SelectedChildIndex": 5, + "Children": [ + { + "$type": "Bookmark", + "Name": "ST:0:0:{aa2115a1-9712-457b-9047-dbb71ca2cdd2}" + }, + { + "$type": "Bookmark", + "Name": "ST:0:0:{1c4feeaa-4718-4aa9-859d-94ce25d182ba}" + }, + { + "$type": "Document", + "DocumentIndex": 3, + "Title": "settings.py", + "DocumentMoniker": "D:\\DjangoProject\\app\\config\\settings.py", + "RelativeDocumentMoniker": "app\\config\\settings.py", + "ToolTip": "D:\\DjangoProject\\app\\config\\settings.py", + "RelativeToolTip": "app\\config\\settings.py", + "ViewState": "AgIAAAAAAAAAAAAAAAAAAAcAAAABAAAAAAAAAA==", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.002457|", + "WhenOpened": "2025-10-24T18:10:58.354Z", + "EditorCaption": "" + }, + { + "$type": "Document", + "DocumentIndex": 1, + "Title": "docker-compose.yml", + "DocumentMoniker": "D:\\DjangoProject\\docker-compose.yml", + "RelativeDocumentMoniker": "docker-compose.yml", + "ToolTip": "D:\\DjangoProject\\docker-compose.yml", + "RelativeToolTip": "docker-compose.yml", + "ViewState": "AgIAAE4AAAAAAAAAAAAQwGgAAAAAAAAAAAAAAA==", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.003775|", + "WhenOpened": "2025-10-24T16:23:53.685Z", + "EditorCaption": "" + }, + { + "$type": "Document", + "DocumentIndex": 2, + "Title": "Dockerfile", + "DocumentMoniker": "D:\\DjangoProject\\Dockerfile", + "RelativeDocumentMoniker": "Dockerfile", + "ToolTip": "D:\\DjangoProject\\Dockerfile", + "RelativeToolTip": "Dockerfile", + "ViewState": "AgIAAAAAAAAAAAAAAAAAABkAAAAAAAAAAAAAAA==", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.001001|", + "WhenOpened": "2025-10-24T16:23:07.815Z", + "EditorCaption": "" + }, + { + "$type": "Document", + "DocumentIndex": 0, + "Title": "nginx.conf", + "DocumentMoniker": "D:\\DjangoProject\\nginx\\nginx.conf", + "RelativeDocumentMoniker": "nginx\\nginx.conf", + "ToolTip": "D:\\DjangoProject\\nginx\\nginx.conf", + "RelativeToolTip": "nginx\\nginx.conf", + "ViewState": "AgIAAAAAAAAAAAAAAAAAABcAAAAAAAAAAAAAAA==", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.001001|", + "WhenOpened": "2025-10-24T16:24:14.433Z", + "EditorCaption": "" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/.vs/ProjectSettings.json b/.vs/ProjectSettings.json new file mode 100644 index 0000000..f8b4888 --- /dev/null +++ b/.vs/ProjectSettings.json @@ -0,0 +1,3 @@ +{ + "CurrentProjectSetting": null +} \ No newline at end of file diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json new file mode 100644 index 0000000..0ab96e5 --- /dev/null +++ b/.vs/VSWorkspaceState.json @@ -0,0 +1,13 @@ +{ + "ExpandedNodes": [ + "", + "\\app", + "\\app\\config", + "\\app\\core", + "\\app\\core\\migrations", + "\\app\\templates", + "\\nginx" + ], + "SelectedNode": "\\app\\config\\settings.py", + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite new file mode 100644 index 0000000..9129872 Binary files /dev/null and b/.vs/slnx.sqlite differ diff --git a/Dockerfile b/Dockerfile index 26a8f8a..0a0fb5a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1 +1,27 @@ -# ADD DOCKERFILE CONTENT HERE \ No newline at end of file +# Use Python slim image as base +FROM python:3.11-slim-bullseye + +# Set working directory +WORKDIR /app + +# Copy dependency list first to leverage caching +COPY requirements.txt . + +# Install Python dependencies +RUN pip install --no-cache-dir --upgrade pip && \ + pip install --no-cache-dir -r requirements.txt + +# Copy project files +COPY . . + +# Move into Django app directory +WORKDIR /app/app + +# Collect static files (for WhiteNoise + Nginx) +RUN python manage.py collectstatic --noinput + +# Expose Gunicorn port +EXPOSE 8000 + +# Start Gunicorn server +CMD ["gunicorn", "config.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "3", "--log-level", "info"] diff --git a/Screenshot 2025-10-24 233422.png b/Screenshot 2025-10-24 233422.png new file mode 100644 index 0000000..8432926 Binary files /dev/null and b/Screenshot 2025-10-24 233422.png differ diff --git a/Screenshot 2025-10-24 233455.png b/Screenshot 2025-10-24 233455.png new file mode 100644 index 0000000..e61a056 Binary files /dev/null and b/Screenshot 2025-10-24 233455.png differ diff --git a/app/config/settings.py b/app/config/settings.py index 77ada4c..d812501 100644 --- a/app/config/settings.py +++ b/app/config/settings.py @@ -1,140 +1,140 @@ -import os -from pathlib import Path -import environ - -# Initialize environment variables -env = environ.Env( - DEBUG=(bool, False) -) - -# Build paths inside the project -BASE_DIR = Path(__file__).resolve().parent.parent - -# Read .env file if exists -environ.Env.read_env(os.path.join(BASE_DIR, '.env')) - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = env('SECRET_KEY', default='django-insecure-change-this-key') - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = env('DEBUG') - -ALLOWED_HOSTS = env.list('ALLOWED_HOSTS', default=['localhost', '127.0.0.1']) - -# Application definition -INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - - # Third party apps - - # Local apps - 'core', -] - -MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'whitenoise.middleware.WhiteNoiseMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', -] - -ROOT_URLCONF = 'config.urls' - -TEMPLATES = [ - { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [BASE_DIR / 'templates'], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', - ], - }, - }, -] - -WSGI_APPLICATION = 'config.wsgi.application' - -# Database -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql', - 'NAME': env('POSTGRES_DB', default='djangodb'), - 'USER': env('POSTGRES_USER', default='djangouser'), - 'PASSWORD': env('POSTGRES_PASSWORD', default='djangopass'), - 'HOST': env('POSTGRES_HOST', default='db'), - 'PORT': env('POSTGRES_PORT', default='5432'), - } -} - -# Redis Cache Configuration -CACHES = { - 'default': { - 'BACKEND': 'django_redis.cache.RedisCache', - 'LOCATION': env('REDIS_URL', default='redis://redis:6379/0'), - 'OPTIONS': { - 'CLIENT_CLASS': 'django_redis.client.DefaultClient', - } - } -} - -# Session Configuration -SESSION_ENGINE = 'django.contrib.sessions.backends.cache' -SESSION_CACHE_ALIAS = 'default' - -# Celery Configuration -CELERY_BROKER_URL = env('REDIS_URL', default='redis://redis:6379/0') -CELERY_RESULT_BACKEND = env('REDIS_URL', default='redis://redis:6379/0') -CELERY_ACCEPT_CONTENT = ['json'] -CELERY_TASK_SERIALIZER = 'json' -CELERY_RESULT_SERIALIZER = 'json' -CELERY_TIMEZONE = 'UTC' - -# Password validation -AUTH_PASSWORD_VALIDATORS = [ - { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', - }, -] - -# Internationalization -LANGUAGE_CODE = 'en-us' -TIME_ZONE = 'UTC' -USE_I18N = True -USE_TZ = True - -# Static files (CSS, JavaScript, Images) -STATIC_URL = '/static/' -STATIC_ROOT = BASE_DIR / 'staticfiles' -STATICFILES_DIRS = [BASE_DIR / 'static'] - -# Media files -MEDIA_URL = '/media/' -MEDIA_ROOT = BASE_DIR / 'media' - -# WhiteNoise configuration -STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' - -# Default primary key field type +import os +from pathlib import Path +import environ + +# Initialize environment variables +env = environ.Env( + DEBUG=(bool, False) +) + +# Build paths inside the project +BASE_DIR = Path(__file__).resolve().parent.parent + +# Read .env file if exists +environ.Env.read_env(os.path.join(BASE_DIR, '.env')) + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = env('SECRET_KEY', default='django-insecure-change-this-key') + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = env('DEBUG') + +ALLOWED_HOSTS = env.list('ALLOWED_HOSTS', default=['localhost', '127.0.0.1']) + +# Application definition +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + + # Third party apps + + # Local apps + 'core', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'config.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [BASE_DIR / 'templates'], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'config.wsgi.application' + +# Database +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': env('POSTGRES_DB', default='djangodb'), + 'USER': env('POSTGRES_USER', default='djangouser'), + 'PASSWORD': env('POSTGRES_PASSWORD', default='djangopass'), + 'HOST': env('POSTGRES_HOST', default='db'), + 'PORT': env('POSTGRES_PORT', default='5432'), + } +} + +# Redis Cache Configuration +CACHES = { + 'default': { + 'BACKEND': 'django_redis.cache.RedisCache', + 'LOCATION': env('REDIS_URL', default='redis://redis:6379/0'), + 'OPTIONS': { + 'CLIENT_CLASS': 'django_redis.client.DefaultClient', + } + } +} + +# Session Configuration +SESSION_ENGINE = 'django.contrib.sessions.backends.cache' +SESSION_CACHE_ALIAS = 'default' + +# Celery Configuration +CELERY_BROKER_URL = env('REDIS_URL', default='redis://redis:6379/0') +CELERY_RESULT_BACKEND = env('REDIS_URL', default='redis://redis:6379/0') +CELERY_ACCEPT_CONTENT = ['json'] +CELERY_TASK_SERIALIZER = 'json' +CELERY_RESULT_SERIALIZER = 'json' +CELERY_TIMEZONE = 'UTC' + +# Password validation +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + +# Internationalization +LANGUAGE_CODE = 'en-us' +TIME_ZONE = 'UTC' +USE_I18N = True +USE_TZ = True + +# Static files (CSS, JavaScript, Images) +STATIC_URL = '/static/' +STATIC_ROOT = BASE_DIR / 'staticfiles' +STATICFILES_DIRS = [BASE_DIR / 'static'] + +# Media files +MEDIA_URL = '/media/' +MEDIA_ROOT = BASE_DIR / 'media' + +# WhiteNoise configuration +STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' + +# Default primary key field type DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index a3437d1..601bd09 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1 +1,65 @@ -# ADD Docker Compose CONTENT HERE \ No newline at end of file +version: "3.9" + +services: + postgres: + image: postgres:15-alpine + container_name: postgres_db + environment: + - POSTGRES_DB=${POSTGRES_DB} + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + volumes: + - postgres_data:/var/lib/postgresql/data + networks: + - backend + + redis: + image: redis:7-alpine + container_name: redis_cache + networks: + - backend + + django: + build: + context: . + dockerfile: Dockerfile + container_name: django_app + working_dir: /app/app + command: > + gunicorn config.wsgi:application + --bind 0.0.0.0:8000 + --workers 3 + --log-level info + volumes: + - .:/app + - static_volume:/app/staticfiles + - media_volume:/app/media + env_file: + - .env + depends_on: + - postgres + - redis + networks: + - backend + + nginx: + image: nginx:1.25-alpine + container_name: nginx_gateway + ports: + - "8080:80" + volumes: + - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro + - static_volume:/app/staticfiles + - media_volume:/app/media + depends_on: + - django + networks: + - backend + +volumes: + postgres_data: + static_volume: + media_volume: + +networks: + backend: diff --git a/nginx/nginx.conf b/nginx/nginx.conf index ed468cf..e151e3c 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -1 +1,27 @@ -# ADD NGINX CONTENT HERE \ No newline at end of file +server { + listen 80; + server_name _; + + # Serve static assets directly + location /static/ { + root /app; + expires 7d; + add_header Cache-Control "public, must-revalidate"; + } + + # Serve media uploads + location /media/ { + root /app; + expires 7d; + add_header Cache-Control "public, must-revalidate"; + } + + # Forward everything else to Django + location / { + proxy_pass http://web:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +}