rinogeek commited on
Commit
4430ebb
·
1 Parent(s): 26c0cd1
Files changed (5) hide show
  1. .dockerignore +10 -0
  2. Akompta/settings.py +18 -7
  3. Dockerfile +38 -0
  4. requirements.txt +1 -0
  5. start.sh +18 -0
.dockerignore ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ venv/
2
+ *.pyc
3
+ __pycache__/
4
+ db.sqlite3
5
+ logs/
6
+ media/
7
+ static/
8
+ .env
9
+ .git
10
+ .gitignore
Akompta/settings.py CHANGED
@@ -10,9 +10,10 @@ For the full list of settings and their values, see
10
  https://docs.djangoproject.com/en/5.2/ref/settings/
11
  """
12
 
 
13
  from pathlib import Path
14
  from datetime import timedelta
15
- import os
16
 
17
  # Build paths inside the project like this: BASE_DIR / 'subdir'.
18
  BASE_DIR = Path(__file__).resolve().parent.parent
@@ -22,12 +23,19 @@ BASE_DIR = Path(__file__).resolve().parent.parent
22
  # See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
23
 
24
  # SECURITY WARNING: keep the secret key used in production secret!
25
- SECRET_KEY = 'django-insecure-3m1!a3u-z=5k8x9y#-954&3ree&mr&$o97fuy8ds*8dox!(rvx'
26
 
27
  # SECURITY WARNING: don't run with debug turned on in production!
28
- DEBUG = True
 
 
29
 
30
- ALLOWED_HOSTS = []
 
 
 
 
 
31
 
32
 
33
  # Application definition
@@ -52,6 +60,7 @@ INSTALLED_APPS = [
52
 
53
  MIDDLEWARE = [
54
  'django.middleware.security.SecurityMiddleware',
 
55
  'corsheaders.middleware.CorsMiddleware',
56
  'django.contrib.sessions.middleware.SessionMiddleware',
57
  'django.middleware.common.CommonMiddleware',
@@ -131,6 +140,7 @@ USE_TZ = True
131
 
132
  STATIC_URL = '/static/'
133
  STATIC_ROOT = BASE_DIR / 'static'
 
134
 
135
  MEDIA_URL = '/media/'
136
  MEDIA_ROOT = BASE_DIR / 'media'
@@ -196,10 +206,11 @@ SIMPLE_JWT = {
196
 
197
 
198
  # CORS Configuration
199
- CORS_ALLOWED_ORIGINS = os.environ.get(
200
  'CORS_ALLOWED_ORIGINS',
201
- 'http://localhost:3000,http://localhost:5173,http://127.0.0.1:3000,http://127.0.0.1:5173'
202
- ).split(',')
 
203
 
204
  CORS_ALLOW_CREDENTIALS = True
205
 
 
10
  https://docs.djangoproject.com/en/5.2/ref/settings/
11
  """
12
 
13
+ import os
14
  from pathlib import Path
15
  from datetime import timedelta
16
+ from decouple import config, Csv
17
 
18
  # Build paths inside the project like this: BASE_DIR / 'subdir'.
19
  BASE_DIR = Path(__file__).resolve().parent.parent
 
23
  # See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
24
 
25
  # SECURITY WARNING: keep the secret key used in production secret!
26
+ SECRET_KEY = config('SECRET_KEY', default='django-insecure-3m1!a3u-z=5k8x9y#-954&3ree&mr&$o97fuy8ds*8dox!(rvx')
27
 
28
  # SECURITY WARNING: don't run with debug turned on in production!
29
+ DEBUG = config('DEBUG', default=True, cast=bool)
30
+
31
+ ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='*', cast=Csv())
32
 
33
+ # CSRF Trusted Origins for Hugging Face and Frontend
34
+ CSRF_TRUSTED_ORIGINS = config(
35
+ 'CSRF_TRUSTED_ORIGINS',
36
+ default='https://*.hf.space,https://*.huggingface.co,https://akompta-ai-flame.vercel.app,https://cosmolabhub-akomptabackend.hf.space',
37
+ cast=Csv()
38
+ )
39
 
40
 
41
  # Application definition
 
60
 
61
  MIDDLEWARE = [
62
  'django.middleware.security.SecurityMiddleware',
63
+ 'whitenoise.middleware.WhiteNoiseMiddleware',
64
  'corsheaders.middleware.CorsMiddleware',
65
  'django.contrib.sessions.middleware.SessionMiddleware',
66
  'django.middleware.common.CommonMiddleware',
 
140
 
141
  STATIC_URL = '/static/'
142
  STATIC_ROOT = BASE_DIR / 'static'
143
+ STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
144
 
145
  MEDIA_URL = '/media/'
146
  MEDIA_ROOT = BASE_DIR / 'media'
 
206
 
207
 
208
  # CORS Configuration
209
+ CORS_ALLOWED_ORIGINS = config(
210
  'CORS_ALLOWED_ORIGINS',
211
+ default='http://localhost:3000,http://localhost:5173,http://127.0.0.1:3000,http://127.0.0.1:5173,https://akompta-ai-flame.vercel.app,https://cosmolabhub-akomptabackend.hf.space',
212
+ cast=Csv()
213
+ )
214
 
215
  CORS_ALLOW_CREDENTIALS = True
216
 
Dockerfile ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use an official Python runtime as a parent image
2
+ FROM python:3.11-slim
3
+
4
+ # Set environment variables
5
+ ENV PYTHONDONTWRITEBYTECODE 1
6
+ ENV PYTHONUNBUFFERED 1
7
+ ENV PORT 7860
8
+
9
+ # Set work directory
10
+ WORKDIR /app
11
+
12
+ # Install system dependencies
13
+ RUN apt-get update && apt-get install -y \
14
+ build-essential \
15
+ libpq-dev \
16
+ && rm -rf /var/lib/apt/lists/*
17
+
18
+ # Install Python dependencies
19
+ COPY requirements.txt /app/
20
+ RUN pip install --no-cache-dir -r requirements.txt
21
+
22
+ # Copy project
23
+ COPY . /app/
24
+
25
+ # Create a non-root user and switch to it
26
+ # Hugging Face Spaces uses user 1000
27
+ RUN useradd -m -u 1000 user
28
+ RUN chown -R user:user /app
29
+ USER user
30
+
31
+ # Create necessary directories
32
+ RUN mkdir -p /app/logs /app/media /app/static
33
+
34
+ # Expose the port Hugging Face expects
35
+ EXPOSE 7860
36
+
37
+ # Run the application
38
+ CMD ["./start.sh"]
requirements.txt CHANGED
@@ -34,3 +34,4 @@ typing-inspection==0.4.2
34
  typing_extensions==4.15.0
35
  urllib3==2.5.0
36
  websockets==15.0.1
 
 
34
  typing_extensions==4.15.0
35
  urllib3==2.5.0
36
  websockets==15.0.1
37
+ whitenoise==6.6.0
start.sh ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Exit on error
4
+ set -e
5
+
6
+ echo "Starting Akompta Backend Setup..."
7
+
8
+ # Apply database migrations
9
+ echo "Applying database migrations..."
10
+ python manage.py migrate --noinput
11
+
12
+ # Collect static files
13
+ echo "Collecting static files..."
14
+ python manage.py collectstatic --noinput
15
+
16
+ # Start Gunicorn
17
+ echo "Starting Gunicorn..."
18
+ exec gunicorn --bind 0.0.0.0:7860 --workers 3 --timeout 120 Akompta.wsgi:application