From f7c48ea30f44980a4ebb4abd61b14cbfb096538a Mon Sep 17 00:00:00 2001 From: Flook Date: Sun, 26 Apr 2026 18:42:10 +0700 Subject: [PATCH] fix: include static for font --- .dockerignore | 2 +- .gitignore | 2 +- Dockerfile | 8 ++++---- core/settings.py | 9 ++++++--- docker-compose.yml | 32 ++++++++++++++++++++++++-------- requirements.txt | 2 ++ static/css/unfold_th_font.css | 7 +++++++ 7 files changed, 45 insertions(+), 17 deletions(-) create mode 100644 static/css/unfold_th_font.css diff --git a/.dockerignore b/.dockerignore index f56466a..fb3aebb 100644 --- a/.dockerignore +++ b/.dockerignore @@ -10,7 +10,7 @@ ENV/ # --- Django --- db.sqlite3 db.sqlite3-journal -/static/ +/staticfiles/ # ไม่เก็บไฟล์ที่รวบรวมแล้ว (เพราะเราจะรัน collectstatic ใน Docker) /media/ .env diff --git a/.gitignore b/.gitignore index f56466a..fb3aebb 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ ENV/ # --- Django --- db.sqlite3 db.sqlite3-journal -/static/ +/staticfiles/ # ไม่เก็บไฟล์ที่รวบรวมแล้ว (เพราะเราจะรัน collectstatic ใน Docker) /media/ .env diff --git a/Dockerfile b/Dockerfile index 51448bb..949774e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -47,7 +47,7 @@ EXPOSE 8000 # ========================= # Run Application # ========================= -CMD ["gunicorn", "core.wsgi:application", \ - "--bind", "0.0.0.0:8000", \ - "--workers", "3", \ - "--timeout", "120"] \ No newline at end of file +# ========================= +# Run Application +# ========================= +CMD ["python", "-m", "gunicorn", "core.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "3", "--timeout", "120"] \ No newline at end of file diff --git a/core/settings.py b/core/settings.py index f79a426..65ab666 100644 --- a/core/settings.py +++ b/core/settings.py @@ -22,12 +22,12 @@ BASE_DIR = Path(__file__).resolve().parent.parent # See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'django-insecure-vk@6jztjz7k6hb2%x%toy0*1&##oy%v%%c$o32w*ptq)+-b0$5' +SECRET_KEY = os.environ.get("SECRET_KEY", "unsafe-dev-secret") # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = False -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ["*"] # Application definition INSTALLED_APPS = [ @@ -58,6 +58,7 @@ INSTALLED_APPS = [ MIDDLEWARE = [ 'corsheaders.middleware.CorsMiddleware', # สำคัญมากสำหรับ Frontend 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', @@ -151,6 +152,8 @@ STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') +STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage" + STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static'), ] diff --git a/docker-compose.yml b/docker-compose.yml index e0dd741..830c266 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.8' +version: "3.8" services: db: @@ -6,20 +6,36 @@ services: container_name: postgres-db restart: always environment: - POSTGRES_DB: my_db - POSTGRES_USER: user - POSTGRES_PASSWORD: password # รหัสผ่านสำหรับช่วงพัฒนาเท่านั้น + POSTGRES_DB: lms + POSTGRES_USER: lms + POSTGRES_PASSWORD: lms123 ports: - "5432:5432" volumes: - postgres_data:/var/lib/postgresql/data - # Healthcheck เพื่อให้ backend รอจนกว่า DB จะพร้อม healthcheck: - test: ["CMD-SHELL", "pg_isready -U user -d my_db"] + test: ["CMD-SHELL", "pg_isready -U lms -d lms"] interval: 5s timeout: 5s retries: 5 + backend: + build: . + container_name: lms-backend + restart: always + depends_on: + db: + condition: service_healthy + environment: + DJANGO_SETTINGS_MODULE: core.settings + DEBUG: "false" + DB_HOST: db + DB_PORT: "5432" + DB_NAME: lms + DB_USER: lms + DB_PASSWORD: lms123 + ports: + - "8000:8000" + volumes: - postgres_data: - minio_data: + postgres_data: \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index a011a1d..6fc1b26 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,5 @@ django-allauth==65.16.1 python-dotenv==1.2.2 psycopg[binary]==3.3.3 django-cors-headers==4.9.0 +gunicorn==25.3.0 +whitenoise==6.12.0 \ No newline at end of file diff --git a/static/css/unfold_th_font.css b/static/css/unfold_th_font.css new file mode 100644 index 0000000..83dae90 --- /dev/null +++ b/static/css/unfold_th_font.css @@ -0,0 +1,7 @@ +/* Import ฟอนต์ */ +@import url("https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@400;500;600;700&display=swap"); + +/* บังคับใช้ฟอนต์ทั้งระบบ */ +html, body, select, input, button, .unfold-admin { + font-family: 'Noto Sans Thai', sans-serif !important; +}