Major refactoring of build_deploy action, along with docker building and packaging improvements. Added no_signups and other .env improvements. There is no longer a separate .env.dev, both use .env now.
This commit is contained in:
parent
76b2becc24
commit
6f57699c8d
28 changed files with 795 additions and 328 deletions
13
src/pkmntrade_club/accounts/adapter.py
Normal file
13
src/pkmntrade_club/accounts/adapter.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
from django.conf import settings
|
||||
from allauth.account.adapter import DefaultAccountAdapter
|
||||
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
|
||||
|
||||
|
||||
class NoSignupAccountAdapter(DefaultAccountAdapter):
|
||||
def is_open_for_signup(self, request):
|
||||
return False
|
||||
|
||||
|
||||
class NoSignupSocialAccountAdapter(DefaultSocialAccountAdapter):
|
||||
def is_open_for_signup(self, request):
|
||||
return False
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 5.1 on 2025-05-10 01:22
|
||||
# Generated by Django 5.1 on 2025-05-17 02:07
|
||||
|
||||
import django.contrib.auth.models
|
||||
import django.contrib.auth.validators
|
||||
|
|
@ -14,7 +14,7 @@ class Migration(migrations.Migration):
|
|||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('auth', '0012_alter_user_first_name_max_length'),
|
||||
('auth', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
from django.conf import settings
|
||||
from django.contrib.auth import login
|
||||
import time
|
||||
import logging
|
||||
class LogRequestsMiddleware:
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request):
|
||||
if request.path == "/health/":
|
||||
return self.get_response(request)
|
||||
start = time.perf_counter()
|
||||
response = self.get_response(request)
|
||||
end = time.perf_counter()
|
||||
self.log(request, response, start, end)
|
||||
return response
|
||||
|
||||
def log(self, request, response, start, end):
|
||||
logging.info(f"{request.method} {request.path_info} -> RESP {response.status_code}, took {end - start}s")
|
||||
|
||||
|
|
@ -36,10 +36,19 @@ LOGGING = {
|
|||
'level': 'INFO',
|
||||
'propagate': False,
|
||||
},
|
||||
'granian.access': {
|
||||
'handlers': ['console'],
|
||||
'level': 'INFO',
|
||||
'propagate': False,
|
||||
},
|
||||
'_granian': {
|
||||
'handlers': ['console'],
|
||||
'level': 'INFO',
|
||||
'propagate': False,
|
||||
},
|
||||
'': {
|
||||
'handlers': ['console'],
|
||||
'level': 'INFO',
|
||||
'propagate': True,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -57,8 +66,10 @@ 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')
|
||||
|
||||
# Resend API Key
|
||||
RESEND_API_KEY = env('RESEND_API_KEY')
|
||||
# Scaleway Secret Key
|
||||
SCW_SECRET_KEY = env('SCW_SECRET_KEY')
|
||||
|
||||
DISABLE_SIGNUPS = env('DISABLE_SIGNUPS', default=False)
|
||||
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#debug
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
|
|
@ -67,7 +78,16 @@ DEBUG = env('DEBUG')
|
|||
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
|
||||
ALLOWED_HOSTS = env('ALLOWED_HOSTS').split(',')
|
||||
|
||||
CSRF_TRUSTED_ORIGINS = env('CSRF_TRUSTED_ORIGINS').split(',')
|
||||
try:
|
||||
current_web_worker_hostname = socket.gethostname()
|
||||
ALLOWED_HOSTS.append(current_web_worker_hostname)
|
||||
logging.getLogger(__name__).info(f"Added {current_web_worker_hostname} to allowed hosts.")
|
||||
except Exception:
|
||||
logging.getLogger(__name__).info(f"Error determining server hostname for allowed hosts.")
|
||||
|
||||
PUBLIC_HOST = env('PUBLIC_HOST')
|
||||
|
||||
CSRF_TRUSTED_ORIGINS = [f"https://{PUBLIC_HOST}"]
|
||||
|
||||
FIRST_PARTY_APPS = [
|
||||
'pkmntrade_club.accounts',
|
||||
|
|
@ -101,15 +121,18 @@ INSTALLED_APPS = [
|
|||
] + FIRST_PARTY_APPS
|
||||
|
||||
if DEBUG:
|
||||
INSTALLED_APPS.append("django_browser_reload")
|
||||
INSTALLED_APPS.append("debug_toolbar")
|
||||
INSTALLED_APPS = [
|
||||
*INSTALLED_APPS,
|
||||
"django_browser_reload",
|
||||
"debug_toolbar",
|
||||
]
|
||||
|
||||
TAILWIND_APP_NAME = 'theme'
|
||||
|
||||
META_SITE_NAME = 'PKMN Trade Club'
|
||||
META_SITE_PROTOCOL = 'https'
|
||||
META_USE_SITES = True
|
||||
META_IMAGE_URL = 'https://pkmntrade.club/'
|
||||
META_IMAGE_URL = f'https://{PUBLIC_HOST}/'
|
||||
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#middleware
|
||||
MIDDLEWARE = [
|
||||
|
|
@ -117,18 +140,19 @@ MIDDLEWARE = [
|
|||
"whitenoise.middleware.WhiteNoiseMiddleware", # WhiteNoise
|
||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
"debug_toolbar.middleware.DebugToolbarMiddleware",
|
||||
"django.middleware.csrf.CsrfViewMiddleware",
|
||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||
"django.contrib.messages.middleware.MessageMiddleware",
|
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||
"allauth.account.middleware.AccountMiddleware", # django-allauth
|
||||
"pkmntrade_club.django_project.middleware.LogRequestsMiddleware",
|
||||
]
|
||||
|
||||
if DEBUG:
|
||||
MIDDLEWARE.append(
|
||||
"django_browser_reload.middleware.BrowserReloadMiddleware")
|
||||
MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware")
|
||||
MIDDLEWARE = [
|
||||
*MIDDLEWARE,
|
||||
"django_browser_reload.middleware.BrowserReloadMiddleware",
|
||||
]
|
||||
|
||||
DAISY_SETTINGS = {
|
||||
'SITE_TITLE': 'PKMN Trade Club Admin',
|
||||
|
|
@ -163,7 +187,7 @@ TEMPLATES = [
|
|||
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
|
||||
DATABASES = {
|
||||
'default': env.db(),
|
||||
'default': env.db(var="DJANGO_DATABASE_URL"),
|
||||
}
|
||||
|
||||
# Password validation
|
||||
|
|
@ -211,7 +235,10 @@ STATIC_ROOT = BASE_DIR / "staticfiles"
|
|||
STATIC_URL = "/static/"
|
||||
|
||||
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
|
||||
STATICFILES_DIRS = [BASE_DIR / "static"]
|
||||
STATICFILES_DIRS = [
|
||||
BASE_DIR / "static", # For general static files
|
||||
BASE_DIR / "theme" / "static", # For Tailwind generated CSS
|
||||
]
|
||||
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#media-root
|
||||
MEDIA_ROOT = BASE_DIR / "media"
|
||||
|
|
@ -240,10 +267,15 @@ CRISPY_TEMPLATE_PACK = "tailwind"
|
|||
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
|
||||
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
|
||||
EMAIL_HOST = "smtp.resend.com"
|
||||
# EMAIL_HOST = "smtp.resend.com"
|
||||
# EMAIL_PORT = 587
|
||||
# EMAIL_HOST_USER = "resend"
|
||||
# EMAIL_HOST_PASSWORD = RESEND_API_KEY
|
||||
# EMAIL_USE_TLS = True
|
||||
EMAIL_HOST = "smtp.tem.scaleway.com"
|
||||
EMAIL_PORT = 587
|
||||
EMAIL_HOST_USER = "resend"
|
||||
EMAIL_HOST_PASSWORD = RESEND_API_KEY
|
||||
EMAIL_HOST_USER = "dd2cd354-de6d-4fa4-bfe8-31c961cb4e90"
|
||||
EMAIL_HOST_PASSWORD = SCW_SECRET_KEY
|
||||
EMAIL_USE_TLS = True
|
||||
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#default-from-email
|
||||
|
|
@ -256,11 +288,11 @@ INTERNAL_IPS = [
|
|||
"127.0.0.1",
|
||||
]
|
||||
|
||||
# for docker development
|
||||
# for docker + debug toolbar
|
||||
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
|
||||
for ip in ips:
|
||||
INTERNAL_IPS.append(ip)
|
||||
ALLOWED_HOSTS.append(ip)
|
||||
INTERNAL_IPS.append(".".join(ip.rsplit(".")[:-1])+ ".1")
|
||||
|
||||
# https://docs.djangoproject.com/en/dev/topics/auth/customizing/#substituting-a-custom-user-model
|
||||
AUTH_USER_MODEL = "accounts.CustomUser"
|
||||
|
|
@ -281,22 +313,27 @@ AUTHENTICATION_BACKENDS = (
|
|||
"allauth.account.auth_backends.AuthenticationBackend",
|
||||
)
|
||||
# https://django-allauth.readthedocs.io/en/latest/configuration.html
|
||||
if DISABLE_SIGNUPS:
|
||||
ACCOUNT_ADAPTER = 'pkmntrade_club.accounts.adapter.NoSignupAccountAdapter'
|
||||
SOCIALACCOUNT_ADAPTER = 'pkmntrade_club.accounts.adapter.NoSignupSocialAccountAdapter' # always disable social account signups
|
||||
ACCOUNT_SESSION_REMEMBER = True
|
||||
ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE = True
|
||||
ACCOUNT_AUTHENTICATION_METHOD = "username_email"
|
||||
ACCOUNT_EMAIL_REQUIRED = True
|
||||
ACCOUNT_EMAIL_VERIFICATION = env('ACCOUNT_EMAIL_VERIFICATION')
|
||||
ACCOUNT_EMAIL_NOTIFICATIONS = True
|
||||
ACCOUNT_EMAIL_UNKNOWN_ACCOUNTS = False
|
||||
ACCOUNT_DEFAULT_HTTP_PROTOCOL = "https"
|
||||
ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION = True
|
||||
ACCOUNT_USERNAME_MIN_LENGTH = 3
|
||||
ACCOUNT_USERNAME_MIN_LENGTH = 2
|
||||
ACCOUNT_CHANGE_EMAIL = True
|
||||
ACCOUNT_UNIQUE_EMAIL = True
|
||||
ACCOUNT_LOGIN_BY_CODE_ENABLED = True
|
||||
ACCOUNT_LOGIN_BY_CODE_REQUIRED = False
|
||||
ACCOUNT_SIGNUP_FORM_HONEYPOT_FIELD = "website"
|
||||
ACCOUNT_USERNAME_REQUIRED = True
|
||||
ACCOUNT_FORMS = {
|
||||
"signup": "accounts.forms.CustomUserCreationForm",
|
||||
"signup": "pkmntrade_club.accounts.forms.CustomUserCreationForm",
|
||||
}
|
||||
SOCIALACCOUNT_EMAIL_AUTHENTICATION = False
|
||||
SOCIALACCOUNT_EMAIL_AUTHENTICATION_AUTO_CONNECT = False
|
||||
|
|
@ -304,7 +341,11 @@ SOCIALACCOUNT_ONLY = False
|
|||
|
||||
CACHE_TIMEOUT = 604800 # 1 week
|
||||
|
||||
if DEBUG:
|
||||
DEBUG_TOOLBAR_CONFIG = {"SHOW_TOOLBAR_CALLBACK": lambda request: DEBUG}
|
||||
|
||||
DISABLE_CACHE = env('DISABLE_CACHE', default=DEBUG)
|
||||
|
||||
if DISABLE_CACHE:
|
||||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": "django.core.cache.backends.dummy.DummyCache",
|
||||
|
|
@ -315,6 +356,5 @@ else:
|
|||
"default": {
|
||||
"BACKEND": "django.core.cache.backends.db.DatabaseCache",
|
||||
"LOCATION": "django_cache",
|
||||
"TIMEOUT": 604800, # 1 week
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from django.conf import settings
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
from debug_toolbar.toolbar import debug_toolbar_urls
|
||||
|
||||
urlpatterns = [
|
||||
path("admin/", admin.site.urls),
|
||||
|
|
@ -10,11 +10,4 @@ urlpatterns = [
|
|||
path('account/', include('pkmntrade_club.accounts.urls')),
|
||||
path("trades/", include("pkmntrade_club.trades.urls")),
|
||||
path("__reload__/", include("django_browser_reload.urls")),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
import debug_toolbar
|
||||
|
||||
urlpatterns = [
|
||||
path("__debug__/", include(debug_toolbar.urls)),
|
||||
] + urlpatterns
|
||||
] + debug_toolbar_urls()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue