diff --git a/.gitignore b/.gitignore index 08ee92f..64ab79e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ venv **/__pycache__ -db.sqlite3 \ No newline at end of file +db.sqlite3 +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..79c083a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM python:3.12-alpine + +WORKDIR /app + +EXPOSE 8000 + +COPY requirements.txt /app + +RUN pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple + +RUN pip install --no-cache-dir -r requirements.txt + +COPY . /app + +RUN chmod +x /app/entrypoint.sh + +ENTRYPOINT [ "/app/entrypoint.sh" ] \ No newline at end of file diff --git a/api/settings.py b/api/settings.py index d68808b..41ae2b4 100644 --- a/api/settings.py +++ b/api/settings.py @@ -10,6 +10,7 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/5.1/ref/settings/ """ +import os from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. @@ -20,12 +21,12 @@ BASE_DIR = Path(__file__).resolve().parent.parent # See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "django-insecure-hh=iag^*2+(qj04_)9sup5v9nf$n5=ezs02zgcd3yh4n2u_1qd" +SECRET_KEY = os.getenv("SECRET_KEY") # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = False -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ["web.xuyue.cc", "localhost", "127.0.0.1"] # Application definition @@ -129,5 +130,5 @@ DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" AUTH_USER_MODEL = "account.User" -CORS_ALLOWED_ORIGINS = ["http://localhost:3000", "https://web.xuyue.cc"] +CORS_ALLOWED_ORIGINS = ["http://localhost:8098", "https://web.xuyue.cc"] CORS_ALLOW_CREDENTIALS = True diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..a7d9019 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +python manage.py migrate --noinput +exec gunicorn --bind 0.0.0.0:8000 api.asgi:application -k uvicorn.workers.UvicornWorker \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index f4ded95..0ad3953 100644 Binary files a/requirements.txt and b/requirements.txt differ