diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..7d47f32 --- /dev/null +++ b/.env.production @@ -0,0 +1,7 @@ +SECRET_KEY=.... +DB_PATH=/data/db.sqlite3 +MEDIA_ROOT=/uploads/media +DJANGO_ALLOWED_HOSTS=* +DJANGO_CSRF_TRUSTED_ORIGINS=http:// +DJANGO_SETTINGS_MODULE=iamkonstantin_web.settings.production +DJANGO_LOG_LEVEL=INFO \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index b52354e..28f5d05 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM python:3.8.1-slim-buster # Add user that will be used in the container. -RUN useradd wagtail +# RUN useradd wagtail # Port used by this container to serve HTTP. EXPOSE 8000 @@ -37,13 +37,13 @@ WORKDIR /app # Set this directory to be owned by the "wagtail" user. This Wagtail project # uses SQLite, the folder needs to be owned by the user that # will be writing to the database file. -RUN chown wagtail:wagtail /app +# RUN chown wagtail:wagtail /app # Copy the source code of the project into the container. -COPY --chown=wagtail:wagtail . . +COPY . . # Use user "wagtail" to run the build commands below and the server itself. -USER wagtail +# USER wagtail # Collect static files. RUN python manage.py collectstatic --noinput --clear diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a37e5dd --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +.PHONY: help build publish + +help: + @perl -nle'print $& if m{^[a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +build: + @docker build -t code.headbright.be/konstantin/iamkonstantin:1.0.6 . + +publish: + @docker push code.headbright.be/konstantin/iamkonstantin:1.0.6 diff --git a/README.md b/README.md new file mode 100644 index 0000000..fb2eb30 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +```shell +caddy reverse-proxy --to :8000 +``` + +Caddyfile + +``` +iamkonstantin.eu + +reverse_proxy :8000 +``` \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index d720a83..ea891ef 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,13 +2,16 @@ version: '3.8' services: wagtail: - image: code.headbright.be/konstantin/iamkonstantin:1.0.0 + image: code.headbright.be/konstantin/iamkonstantin:1.0.6 container_name: wagtail + restart: always volumes: - ./website/:/usr/src/app/:consistent + - ./database:/data:rw + - /var/uploads:/uploads/media:rw ports: - 8000:8000 - command : python manage.py runserver 0.0.0.0:8000 + command : bash -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000" env_file: - ./.env.production networks: diff --git a/iamkonstantin_web/settings/production.py b/iamkonstantin_web/settings/production.py index 9ca4ed7..6e46587 100644 --- a/iamkonstantin_web/settings/production.py +++ b/iamkonstantin_web/settings/production.py @@ -2,6 +2,53 @@ from .base import * DEBUG = False +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": os.environ["DB_PATH"], + } +} + +MEDIA_ROOT = os.environ["MEDIA_ROOT"] + +# WAGTAILDOCS_SERVE_METHOD = 'serve_view' + +print("using database path {}".format(os.environ["DB_PATH"])) +print("using media root path {}".format(os.environ["MEDIA_ROOT"])) + +SECRET_KEY = os.environ["SECRET_KEY"] + +SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") + +SECURE_SSL_REDIRECT = True + +ALLOWED_HOSTS = os.getenv("DJANGO_ALLOWED_HOSTS", "*").split(",") + +CSRF_TRUSTED_ORIGINS = os.getenv("DJANGO_CSRF_TRUSTED_ORIGINS", "").split(",") + +EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" + +MIDDLEWARE.append("whitenoise.middleware.WhiteNoiseMiddleware") +STORAGES["staticfiles"]["BACKEND"] = "whitenoise.storage.CompressedManifestStaticFilesStorage" + +LOGGING = { + "version": 1, + "disable_existing_loggers": False, + "handlers": { + "console": { + "class": "logging.StreamHandler", + }, + }, + "loggers": { + "django": { + "handlers": ["console"], + "level": os.getenv("DJANGO_LOG_LEVEL", "INFO"), + }, + }, +} + +WAGTAIL_REDIRECTS_FILE_STORAGE = "cache" + try: from .local import * except ImportError: diff --git a/iamkonstantin_web/templates/includes/footer.html b/iamkonstantin_web/templates/includes/footer.html index 3f805bc..635fd0e 100644 --- a/iamkonstantin_web/templates/includes/footer.html +++ b/iamkonstantin_web/templates/includes/footer.html @@ -1,7 +1,7 @@ {% load navigation_tags %}