Start some settings work

pull/2/head
Andrew Godwin 2022-11-12 22:10:06 -07:00
rodzic 878f56b411
commit 143a4a6e8c
17 zmienionych plików z 75 dodań i 32 usunięć

4
Makefile 100644
Wyświetl plik

@ -0,0 +1,4 @@
.PHONY: clean
image:
docker build -t takahe -f docker/Dockerfile .

Wyświetl plik

@ -1,3 +1,20 @@
class Config:
import pydantic
pass
class Config(pydantic.BaseModel):
# Basic configuration options
site_name: str = "takahē"
identity_max_age: int = 24 * 60 * 60
# Cached ORM object storage
__singleton__ = None
class Config:
env_prefix = "takahe_"
@classmethod
def load(cls) -> "Config":
if cls.__singleton__ is None:
cls.__singleton__ = cls()
return cls.__singleton__

Wyświetl plik

@ -1,7 +1,7 @@
from django.conf import settings
from core.config import Config
def config_context(request):
return {
"config": {"site_name": settings.SITE_NAME},
"config": Config.load(),
}

Wyświetl plik

@ -1,4 +1,6 @@
FROM python:3.9-bullseye as builder
# Build stage
FROM python:3.11.0-buster as builder
RUN mkdir -p /takahe
RUN python -m venv /takahe/.venv
@ -12,8 +14,9 @@ RUN . /takahe/.venv/bin/activate \
&& pip install --upgrade pip \
&& pip install --upgrade -r requirements.txt
# Final image stage
FROM python:3.9-slim-bullseye
FROM python:3.11.0-slim-buster
RUN apt-get update && apt-get install -y libpq5
@ -23,4 +26,4 @@ COPY . /takahe
WORKDIR /takahe
EXPOSE 8000
CMD ["/takahe/scripts/start.sh"]
CMD ["/takahe/docker/start.sh"]

Wyświetl plik

@ -19,7 +19,7 @@ services:
build: .
image: tahake:latest
environment:
- "DJANGO_SETTINGS_MODULE=takahe.settings"
- "DJANGO_SETTINGS_MODULE=takahe.settings.production"
- "SECRET_KEY=insecure_secret"
- "POSTGRES_HOST=db"
- "POSTGRES_DB=tahake"

Wyświetl plik

@ -6,7 +6,7 @@ import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "takahe.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "takahe.settings.production")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:

Wyświetl plik

@ -12,3 +12,4 @@ psycopg2~=2.9.5
bleach~=5.0.1
pytest-django~=4.5.2
pytest-httpx~=0.21
pydantic~=1.10.2

Wyświetl plik

@ -9,7 +9,7 @@ multi_line_output = 3
[tool:pytest]
addopts = --tb=short
DJANGO_SETTINGS_MODULE = takahe.settings
DJANGO_SETTINGS_MODULE = takahe.settings.testing
filterwarnings =
ignore:There is no current event loop

Wyświetl plik

@ -11,6 +11,6 @@ import os
from django.core.asgi import get_asgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "takahe.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "takahe.settings.production")
application = get_asgi_application()

Wyświetl plik

Wyświetl plik

@ -1,17 +1,7 @@
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get("SECRET_KEY", "insecure_secret")
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ["*"]
CSRF_TRUSTED_ORIGINS = ["http://*", "https://*"]
BASE_DIR = Path(__file__).resolve().parent.parent.parent
# Application definition
@ -30,7 +20,6 @@ INSTALLED_APPS = [
]
MIDDLEWARE = [
"core.middleware.AlwaysSecureMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
@ -115,9 +104,4 @@ STATICFILES_DIRS = [
BASE_DIR / "static",
]
CRISPY_FAIL_SILENTLY = not DEBUG
SITE_NAME = "takahē"
DEFAULT_DOMAIN = "feditest.aeracode.org"
ALLOWED_DOMAINS = ["feditest.aeracode.org"]
IDENTITY_MAX_AGE = 24 * 60 * 60
ALLOWED_HOSTS = ["*"]

Wyświetl plik

@ -0,0 +1,13 @@
import os
from .base import * # noqa
# Load secret key from environment with a fallback
SECRET_KEY = os.environ.get("TAKAHE_SECRET_KEY", "insecure_secret")
# Disable the CRSF origin protection
MIDDLEWARE.insert(0, "core.middleware.AlwaysSecureMiddleware")
# Ensure debug features are on
DEBUG = True
CRISPY_FAIL_SILENTLY = False

Wyświetl plik

@ -0,0 +1,17 @@
import os
from .base import * # noqa
# Load secret key from environment
try:
SECRET_KEY = os.environ["TAKAHE_SECRET_KEY"]
except KeyError:
print("You must specify the TAKAHE_SECRET_KEY environment variable!")
os._exit(1)
# Ensure debug features are off
DEBUG = False
CRISPY_FAIL_SILENTLY = True
# TODO: Allow better setting of allowed_hosts, if we need to
ALLOWED_HOSTS = ["*"]

Wyświetl plik

@ -0,0 +1,4 @@
from .base import * # noqa
# Fixed secret key
SECRET_KEY = "testing_secret"

Wyświetl plik

@ -11,6 +11,6 @@ import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "takahe.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "takahe.settings.production")
application = get_wsgi_application()

Wyświetl plik

@ -1,13 +1,13 @@
import string
from django import forms
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.http import Http404
from django.shortcuts import redirect
from django.utils.decorators import method_decorator
from django.views.generic import FormView, TemplateView, View
from core.config import Config
from core.forms import FormHelper
from users.decorators import identity_required
from users.models import Domain, Follow, Identity, IdentityStates
@ -26,7 +26,7 @@ class ViewIdentity(TemplateView):
fetch=True,
)
posts = identity.posts.all()[:100]
if identity.data_age > settings.IDENTITY_MAX_AGE:
if identity.data_age > Config.load().IDENTITY_MAX_AGE:
identity.transition_perform(IdentityStates.outdated)
return {
"identity": identity,