Make a deployable version

This commit is contained in:
Konstantin 2024-03-12 18:14:57 +01:00
parent 92475c508b
commit 17630e965b
8 changed files with 86 additions and 7 deletions

7
.env.production Normal file
View file

@ -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

View file

@ -2,7 +2,7 @@
FROM python:3.8.1-slim-buster FROM python:3.8.1-slim-buster
# Add user that will be used in the container. # Add user that will be used in the container.
RUN useradd wagtail # RUN useradd wagtail
# Port used by this container to serve HTTP. # Port used by this container to serve HTTP.
EXPOSE 8000 EXPOSE 8000
@ -37,13 +37,13 @@ WORKDIR /app
# Set this directory to be owned by the "wagtail" user. This Wagtail project # 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 # uses SQLite, the folder needs to be owned by the user that
# will be writing to the database file. # 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 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. # Use user "wagtail" to run the build commands below and the server itself.
USER wagtail # USER wagtail
# Collect static files. # Collect static files.
RUN python manage.py collectstatic --noinput --clear RUN python manage.py collectstatic --noinput --clear

10
Makefile Normal file
View file

@ -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

11
README.md Normal file
View file

@ -0,0 +1,11 @@
```shell
caddy reverse-proxy --to :8000
```
Caddyfile
```
iamkonstantin.eu
reverse_proxy :8000
```

View file

@ -2,13 +2,16 @@ version: '3.8'
services: services:
wagtail: wagtail:
image: code.headbright.be/konstantin/iamkonstantin:1.0.0 image: code.headbright.be/konstantin/iamkonstantin:1.0.6
container_name: wagtail container_name: wagtail
restart: always
volumes: volumes:
- ./website/:/usr/src/app/:consistent - ./website/:/usr/src/app/:consistent
- ./database:/data:rw
- /var/uploads:/uploads/media:rw
ports: ports:
- 8000:8000 - 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_file:
- ./.env.production - ./.env.production
networks: networks:

View file

@ -2,6 +2,53 @@ from .base import *
DEBUG = False 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: try:
from .local import * from .local import *
except ImportError: except ImportError:

View file

@ -1,7 +1,7 @@
{% load navigation_tags %} {% load navigation_tags %}
<footer> <footer>
<p>Built with Wagtail</p> <p>Hello 👋</p>
{% with linkedin_url=settings.base.NavigationSettings.linkedin_url github_url=settings.base.NavigationSettings.github_url mastodon_url=settings.base.NavigationSettings.mastodon_url %} {% with linkedin_url=settings.base.NavigationSettings.linkedin_url github_url=settings.base.NavigationSettings.github_url mastodon_url=settings.base.NavigationSettings.mastodon_url %}
{% if linkedin_url or github_url or mastodon_url %} {% if linkedin_url or github_url or mastodon_url %}

View file

@ -1,2 +1,3 @@
Django>=4.2,<5.1 Django>=4.2,<5.1
wagtail>=6.0,<6.1 wagtail>=6.0,<6.1
whitenoise>=6.6,<7.0