From 3b38c9fdec62e8565c4e04812321d34efe20aa59 Mon Sep 17 00:00:00 2001 From: Flo Ha Date: Fri, 20 May 2022 22:32:32 +0200 Subject: [PATCH] =?UTF-8?q?create=20basic=20django=20app=20serving=20the?= =?UTF-8?q?=20G=C3=A4hsnitz=20website?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 6 ++ .gitignore | 4 ++ Dockerfile | 7 +++ docker-compose.yml | 9 +++ entrypoint.sh | 12 ++++ gaehsnitz/__init__.py | 0 gaehsnitz/apps.py | 6 ++ gaehsnitz/static/gaehsnitz/style.css | 79 ++++++++++++++++++++++++ gaehsnitz/templates/gaehsnitz/base.html | 30 +++++++++ gaehsnitz/templates/gaehsnitz/index.html | 9 +++ gaehsnitz/urls.py | 7 +++ gaehsnitz/views.py | 5 ++ gaehsnitzproject/__init__.py | 0 gaehsnitzproject/settings.py | 77 +++++++++++++++++++++++ gaehsnitzproject/urls.py | 5 ++ gaehsnitzproject/wsgi.py | 7 +++ manage.py | 21 +++++++ requirements.txt | 2 + 18 files changed, 286 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100755 entrypoint.sh create mode 100644 gaehsnitz/__init__.py create mode 100644 gaehsnitz/apps.py create mode 100644 gaehsnitz/static/gaehsnitz/style.css create mode 100644 gaehsnitz/templates/gaehsnitz/base.html create mode 100644 gaehsnitz/templates/gaehsnitz/index.html create mode 100644 gaehsnitz/urls.py create mode 100644 gaehsnitz/views.py create mode 100644 gaehsnitzproject/__init__.py create mode 100644 gaehsnitzproject/settings.py create mode 100644 gaehsnitzproject/urls.py create mode 100644 gaehsnitzproject/wsgi.py create mode 100755 manage.py create mode 100644 requirements.txt diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6f6c3c9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.dockerignore +.gitignore +.venv +docker-compose.yml +Dockerfile +volumes diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..453f6aa --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.idea/ +.venv/ +**/__pycache__/ +volumes/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d70bcc8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.10 +ENV PYTHONUNBUFFERED=1 +WORKDIR /code/ +COPY requirements.txt . +RUN pip install --no-cache-dir --requirement requirements.txt +COPY . . +ENTRYPOINT ["./entrypoint.sh"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..484bc0f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +services: + + web: + build: + context: . + ports: + - "80:8000" + volumes: + - .:/code:r diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..7e955ac --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -e + +if [ "$DJANGO_PRODUCTION_MODE" == "true" ]; then + echo "starting production server ..." + gunicorn --bind=0.0.0.0:8000 --workers=2 gaehsnitzproject.wsgi + +else + echo "starting development server ..." + python manage.py runserver 0.0.0.0:8000 + +fi diff --git a/gaehsnitz/__init__.py b/gaehsnitz/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/gaehsnitz/apps.py b/gaehsnitz/apps.py new file mode 100644 index 0000000..a23c3c0 --- /dev/null +++ b/gaehsnitz/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class GaehsnitzConfig(AppConfig): + name = "gaehsnitz" + verbose_name = "Gähsnitz Open Air" diff --git a/gaehsnitz/static/gaehsnitz/style.css b/gaehsnitz/static/gaehsnitz/style.css new file mode 100644 index 0000000..f5d349a --- /dev/null +++ b/gaehsnitz/static/gaehsnitz/style.css @@ -0,0 +1,79 @@ +html, body, div, +h1, h2, h3, h4, h5, h6, +a, p, b, i, +form, label, input, +table, thead, tbody, tr, td { + margin: 0; + border: none; + padding: 0; +} + +html, body { + width: 100%; + height: 100%; + font-size: 14px; +} + +@media only screen and (min-width: 600px) and (max-width: 899px) { + html, body { + font-size: 16px; + } +} + +@media only screen and (min-width: 900px) { + html, body { + font-size: 18px; + } +} + +body { + display: flex; + flex-direction: column; + align-items: center; + background-color: #111111; + color: #EEEEEE; +} + +#title, #navi, #content { + flex: 0 1 auto; + width: 95%; + max-width: 1200px; + margin: 8px; +} + +#title { + margin-top: 16px; + font-size: 1.6rem; + text-align: center; + color: #EE9933; + text-shadow: 0 0 16px #EE9933; +} + +#navi { + border-top: 1px solid #663322; + border-bottom: 1px solid #663322; + color: #663322; + padding: 8px 0; + text-align: center; +} + +a { + text-decoration: none; + color: #EE9933; + transition: color 100ms; +} + +a:hover, a:focus { + color: #EEEEEE; +} + +h1 { + margin: 0 0 12px; + font-size: 1.3rem; + font-weight: bold; + color: #EECC66; +} + +p { + margin: 6px 0 10px; +} diff --git a/gaehsnitz/templates/gaehsnitz/base.html b/gaehsnitz/templates/gaehsnitz/base.html new file mode 100644 index 0000000..badc154 --- /dev/null +++ b/gaehsnitz/templates/gaehsnitz/base.html @@ -0,0 +1,30 @@ +{% load static %} + + + + + + + Gähsnitz Open Air + + + + +
+ Gähsnitz Open Air 2022 +
+ + + +
+ {% block content %}{% endblock %} +
+ + + diff --git a/gaehsnitz/templates/gaehsnitz/index.html b/gaehsnitz/templates/gaehsnitz/index.html new file mode 100644 index 0000000..794d092 --- /dev/null +++ b/gaehsnitz/templates/gaehsnitz/index.html @@ -0,0 +1,9 @@ +{% extends "gaehsnitz/base.html" %} + +{% block content %} + +

Bald, dooo!

+ +

Das bisschen Website macht sich von allein, nimmt man an.

+ +{% endblock %} diff --git a/gaehsnitz/urls.py b/gaehsnitz/urls.py new file mode 100644 index 0000000..4870f46 --- /dev/null +++ b/gaehsnitz/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from gaehsnitz.views import IndexView + +urlpatterns = [ + path("", IndexView.as_view(), name="index"), +] diff --git a/gaehsnitz/views.py b/gaehsnitz/views.py new file mode 100644 index 0000000..9a0e789 --- /dev/null +++ b/gaehsnitz/views.py @@ -0,0 +1,5 @@ +from django.views.generic import TemplateView + + +class IndexView(TemplateView): + template_name = "gaehsnitz/index.html" diff --git a/gaehsnitzproject/__init__.py b/gaehsnitzproject/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/gaehsnitzproject/settings.py b/gaehsnitzproject/settings.py new file mode 100644 index 0000000..66855e9 --- /dev/null +++ b/gaehsnitzproject/settings.py @@ -0,0 +1,77 @@ +import os + + +def _get_env_production_mode(): + env_var = os.environ.get("DJANGO_PRODUCTION_MODE", "false") + return env_var.lower() == "true" + + +def _get_env_secret_key(): + env_var = os.environ.get("DJANGO_SECRET_KEY") + assert env_var is not None, "DJANGO_SECRET_KEY environment variable must be set when using production mode" + return env_var + + +def _get_env_allowed_hosts(): + env_var = os.environ.get("DJANGO_ALLOWED_HOSTS") + assert env_var is not None, "DJANGO_ALLOWED_HOSTS environment variable must be set when using production mode" + return [host.strip() for host in env_var.split(",")] + + +def _get_env_static_root(): + env_var = os.environ.get("DJANGO_STATIC_ROOT") + assert env_var is not None, "DJANGO_STATIC_ROOT environment variable must be set when using production mode" + return env_var + + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +PRODUCTION = _get_env_production_mode() + +if PRODUCTION: + SECRET_KEY = _get_env_secret_key() + DEBUG = False + ALLOWED_HOSTS = _get_env_allowed_hosts() + STATIC_ROOT = _get_env_static_root() +else: + SECRET_KEY = "LqKSgoFtED4IFYxf01lBi5MEI4ExSayCakwLjyuzytDJ7vuMq9" + DEBUG = True + ALLOWED_HOSTS = ["*"] + +INSTALLED_APPS = [ + "gaehsnitz", + "django.contrib.contenttypes", + "django.contrib.staticfiles", +] + +MIDDLEWARE = [ + "django.middleware.security.SecurityMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", +] + +ROOT_URLCONF = "gaehsnitzproject.urls" + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + ], + }, + }, +] + +WSGI_APPLICATION = "gaehsnitzproject.wsgi.application" + +TIME_ZONE = "Europe/Berlin" +USE_I18N = False +USE_L10N = False +USE_TZ = True + +STATIC_URL = "/static/" diff --git a/gaehsnitzproject/urls.py b/gaehsnitzproject/urls.py new file mode 100644 index 0000000..5ca4192 --- /dev/null +++ b/gaehsnitzproject/urls.py @@ -0,0 +1,5 @@ +from django.urls import path, include + +urlpatterns = [ + path("", include(("gaehsnitz.urls", "gaehsnitz"))), +] diff --git a/gaehsnitzproject/wsgi.py b/gaehsnitzproject/wsgi.py new file mode 100644 index 0000000..d717378 --- /dev/null +++ b/gaehsnitzproject/wsgi.py @@ -0,0 +1,7 @@ +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gaehsnitzproject.settings') + +application = get_wsgi_application() diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..2b4499f --- /dev/null +++ b/manage.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gaehsnitzproject.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ad8bae3 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +django==4.0.4 +gunicorn==20.1.0