diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4d3bc13 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +data +k8s +3.12 +.github +README.md diff --git a/.gitignore b/.gitignore index 7649f68..8691934 100644 --- a/.gitignore +++ b/.gitignore @@ -67,3 +67,4 @@ coverage.xml # Tailwind CSS /static/css/dist/ node_modules/ +/data diff --git a/3.12/bin/gunicorn b/3.12/bin/gunicorn new file mode 100755 index 0000000..5c80025 --- /dev/null +++ b/3.12/bin/gunicorn @@ -0,0 +1,8 @@ +#!/Users/junv/code/links/3.12/bin/python3.12 +# -*- coding: utf-8 -*- +import re +import sys +from gunicorn.app.wsgiapp import run +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(run()) diff --git a/Dockerfile b/Dockerfile index b821713..ecdb6f0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,8 +39,9 @@ RUN python manage.py compilemessages --locale=zh_Hans # Create data directory for SQLite database RUN mkdir -p /app/data && chmod 777 /app/data +ENV PYTHONPATH=/app # Expose port 8000 EXPOSE 8000 # Run the application -CMD ["gunicorn", "url_manager.wsgi:application", "--bind", "0.0.0.0:8000"] +CMD ["gunicorn", "--chdir", "/app", "url_manager.wsgi:application", "--bind", "0.0.0.0:8000"] diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml index b7b239d..6e268af 100644 --- a/k8s/deployment.yaml +++ b/k8s/deployment.yaml @@ -5,7 +5,6 @@ metadata: labels: tags.datadoghq.com/env: "prod" tags.datadoghq.com/service: "links" - tags.datadoghq.com/version: "{{IMAGE_VERSION}}" spec: selector: matchLabels: @@ -17,8 +16,12 @@ spec: app: links tags.datadoghq.com/env: "prod" tags.datadoghq.com/service: "links" - tags.datadoghq.com/version: "{{IMAGE_VERSION}}" spec: + initContainers: + - name: run-migrations + image: "ghcr.io/wahyd4/links:main" + command: ['python', 'manage.py', 'migrate'] + containers: - name: links image: "ghcr.io/wahyd4/links:main" diff --git a/requirements.txt b/requirements.txt index 17768e3..7ed7d2b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,5 @@ django-tailwind==3.8.0 # chart.js==3.7.0 # Add this line to your requirements.txt file fontawesome-free==5.15.3 +gunicorn==20.1.0 +whitenoise==5.3.0 diff --git a/url_manager/settings.py b/url_manager/settings.py index 98a2344..719b2d3 100644 --- a/url_manager/settings.py +++ b/url_manager/settings.py @@ -11,17 +11,18 @@ INSTALLED_APPS = [ 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', - 'django.contrib.staticfiles', - 'widget_tweaks', # 确保这行在这里 + 'django.contrib.staticfiles', # Make sure this is here only once + 'widget_tweaks', 'links', 'tailwind', - 'new_theme', # Add 'theme' back here + 'new_theme', ] ROOT_URLCONF = 'url_manager.urls' MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', # Add this line 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', # Make sure this is here 'django.middleware.common.CommonMiddleware', @@ -66,6 +67,10 @@ DATABASES = { # 静态文件设置 STATIC_URL = '/static/' STATIC_ROOT = BASE_DIR / 'staticfiles' +STATICFILES_DIRS = [ + BASE_DIR / "static", + BASE_DIR / "theme" / "static", +] # 默认自动字段类型 DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' @@ -98,3 +103,6 @@ TAILWIND_APP_NAME = 'new_theme' INTERNAL_IPS = [ "127.0.0.1", ] + +# Add this at the end of the file +STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' diff --git a/url_manager/wsgi.py b/url_manager/wsgi.py new file mode 100644 index 0000000..2800bf9 --- /dev/null +++ b/url_manager/wsgi.py @@ -0,0 +1,6 @@ +import os +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'url_manager.settings') + +application = get_wsgi_application()