From 14bbd86391d98ab76a20ea797da8dcff18029e4e Mon Sep 17 00:00:00 2001 From: Niko Abeler Date: Tue, 13 Jun 2023 20:35:41 +0200 Subject: [PATCH] release/deploy setup --- Dockerfile | 9 ++++++ guild_journal/settings/__init__.py | 8 +++++ .../{settings.py => settings/default.py} | 31 +++++-------------- guild_journal/settings/development.py | 22 +++++++++++++ guild_journal/settings/production.py | 22 +++++++++++++ release.sh | 2 ++ requirements.txt | 13 ++++++++ 7 files changed, 83 insertions(+), 24 deletions(-) create mode 100644 Dockerfile create mode 100644 guild_journal/settings/__init__.py rename guild_journal/{settings.py => settings/default.py} (83%) create mode 100644 guild_journal/settings/development.py create mode 100644 guild_journal/settings/production.py create mode 100644 release.sh create mode 100644 requirements.txt diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..43fbea9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.11-alpine + +WORKDIR /app + +COPY requirements.txt . +RUN pip install -r requirements.txt +COPY . . + +CMD ["gunicorn", "-b", "0.0.0.0:8000", "guild_journal.wsgi"] \ No newline at end of file diff --git a/guild_journal/settings/__init__.py b/guild_journal/settings/__init__.py new file mode 100644 index 0000000..ae2eacf --- /dev/null +++ b/guild_journal/settings/__init__.py @@ -0,0 +1,8 @@ +import os +from .default import * + + +if os.environ.get("GUILD_JOURNAL_ENV") == "production": + from .production import * +else: + from .development import * diff --git a/guild_journal/settings.py b/guild_journal/settings/default.py similarity index 83% rename from guild_journal/settings.py rename to guild_journal/settings/default.py index 4cc404a..bb66f29 100644 --- a/guild_journal/settings.py +++ b/guild_journal/settings/default.py @@ -13,20 +13,12 @@ https://docs.djangoproject.com/en/4.2/ref/settings/ from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. -BASE_DIR = Path(__file__).resolve().parent.parent +BASE_DIR = Path(__file__).resolve().parent.parent.parent # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "django-insecure-e*p%e)pwf+-ntt4wpn-^^7-0yq)!cjo*om18vy77-=*c0jjfqa" - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = [] - # Application definition @@ -42,6 +34,7 @@ INSTALLED_APPS = [ MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", + "whitenoise.middleware.WhiteNoiseMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.common.CommonMiddleware", "django.middleware.csrf.CsrfViewMiddleware", @@ -72,18 +65,6 @@ TEMPLATES = [ WSGI_APPLICATION = "guild_journal.wsgi.application" - -# Database -# https://docs.djangoproject.com/en/4.2/ref/settings/#databases - -DATABASES = { - "default": { - "ENGINE": "django.db.backends.sqlite3", - "NAME": BASE_DIR / "db.sqlite3", - } -} - - # Password validation # https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators @@ -118,11 +99,13 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.2/howto/static-files/ +STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage" + STATIC_URL = "static/" -STATICFILES_DIRS = [ - BASE_DIR / "static", -] +STATIC_ROOT = BASE_DIR / "static" + +STATICFILES_DIRS = [] # Default primary key field type # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field diff --git a/guild_journal/settings/development.py b/guild_journal/settings/development.py new file mode 100644 index 0000000..fc6adeb --- /dev/null +++ b/guild_journal/settings/development.py @@ -0,0 +1,22 @@ +from pathlib import Path + +BASE_DIR = Path(__file__).resolve().parent.parent.parent + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = "django-insecure-e*p%e)pwf+-ntt4wpn-^^7-0yq)!cjo*om18vy77-=*c0jjfqa" + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": BASE_DIR / "db.sqlite3", + } +} diff --git a/guild_journal/settings/production.py b/guild_journal/settings/production.py new file mode 100644 index 0000000..6a82ed6 --- /dev/null +++ b/guild_journal/settings/production.py @@ -0,0 +1,22 @@ +from pathlib import Path + +BASE_DIR = Path(__file__).resolve().parent.parent.parent + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = "django-insecure-e*p%e)pwf+-ntt4wpn-^^7-0yq)!cjo*om18vy77-=*c0jjfqa" + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = False + +ALLOWED_HOSTS = ["*"] + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": "/data/db.sqlite3", + } +} diff --git a/release.sh b/release.sh new file mode 100644 index 0000000..8234213 --- /dev/null +++ b/release.sh @@ -0,0 +1,2 @@ +docker build . -t git.libove.org/h4kor/guild-journal:$1 +docker push git.libove.org/h4kor/guild-journal:$1 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4597f2e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,13 @@ +asgiref==3.6.0 +black==23.3.0 +click==8.1.3 +Django==4.2.1 +gunicorn==20.1.0 +Markdown==3.4.3 +mypy-extensions==1.0.0 +packaging==23.1 +pathspec==0.11.1 +platformdirs==3.5.3 +ruff==0.0.272 +sqlparse==0.4.4 +tomli==2.0.1