mirror of
https://github.com/Steffo99/sophon.git
synced 2024-12-21 22:34:21 +00:00
✨ Make static work
This commit is contained in:
parent
8e4baf9e6d
commit
0d9e84a87c
5 changed files with 34 additions and 15 deletions
|
@ -24,14 +24,13 @@ RUN poetry install
|
|||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
# Tell Django where the settings module is
|
||||
# I have no idea why this is needed
|
||||
ENV DJANGO_SETTINGS_MODULE="sophon.settings"
|
||||
|
||||
# Store the DBM file in a nice place
|
||||
ENV APACHE_PROXY_EXPRESS_DBM="/run/sophon/proxy/proxy.dbm"
|
||||
ENV DJANGO_PROXY_FILE="/run/sophon/proxy/proxy.dbm"
|
||||
|
||||
# Set the static files directory
|
||||
ENV STATIC_ROOT="/usr/src/app/static"
|
||||
ENV DJANGO_STATIC_ROOT="/run/sophon/static"
|
||||
|
||||
# Start the uvicorn server
|
||||
ENTRYPOINT ["bash", "./docker_start.sh"]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
poetry run python ./manage.py migrate --no-input
|
||||
poetry run python ./manage.py collectstatic --no-input
|
||||
poetry run python ./manage.py initsuperuser
|
||||
poetry run gunicorn sophon.asgi:application -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000
|
||||
poetry run python -O ./manage.py migrate --no-input
|
||||
poetry run python -O ./manage.py collectstatic --no-input
|
||||
poetry run python -O ./manage.py initsuperuser
|
||||
poetry run python -O -m gunicorn sophon.asgi:application -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000
|
||||
|
|
|
@ -167,7 +167,7 @@ except KeyError:
|
|||
# noinspection PyUnresolvedReferences
|
||||
STATIC_ROOT = ".\\static"
|
||||
else:
|
||||
log.warning("DJANGO_STATIC_ROOT was not set, defaulting to `/run/sophon/static/`")
|
||||
log.warning("DJANGO_STATIC_ROOT was not set, defaulting to `/run/sophon/static`")
|
||||
# I have no idea of why IDEA is trying to resolve this
|
||||
# noinspection PyUnresolvedReferences
|
||||
STATIC_ROOT = "/run/sophon/static"
|
||||
|
@ -245,14 +245,14 @@ log.debug(f"{DOCKER_HOST = }")
|
|||
try:
|
||||
DOCKER_TLS_VERIFY = os.environ["DJANGO_DOCKER_TLS_VERIFY"]
|
||||
except KeyError:
|
||||
log.warning("DOCKER_TLS_VERIFY was not set, defaulting to none (may cause problems)")
|
||||
log.warning("DJANGO_DOCKER_TLS_VERIFY was not set, defaulting to none (may cause problems)")
|
||||
DOCKER_TLS_VERIFY = None
|
||||
log.debug(f"{DOCKER_TLS_VERIFY = }")
|
||||
|
||||
try:
|
||||
DOCKER_CERT_PATH = os.environ["DJANGO_DOCKER_CERT_PATH"]
|
||||
except KeyError:
|
||||
log.warning("DOCKER_CERT_PATH was not set, defaulting to none (may cause problems)")
|
||||
log.warning("DJANGO_DOCKER_CERT_PATH was not set, defaulting to none (may cause problems)")
|
||||
DOCKER_CERT_PATH = None
|
||||
log.debug(f"{DOCKER_CERT_PATH = }")
|
||||
|
||||
|
|
|
@ -35,14 +35,17 @@ services:
|
|||
image: steffo45/sophon-backend
|
||||
environment:
|
||||
# TODO: Set a random secret key!
|
||||
- DJANGO_SECRET_KEY=change-me-in-production
|
||||
# TODO: Configure your allowed origins! (* doesn't work)
|
||||
- DJANGO_CORS_ALLOWED_ORIGINS=http://dev.sophon.steffo.eu
|
||||
- DJANGO_SECRET_KEY=change-me!!!
|
||||
# TODO: Configure your allowed hosts!
|
||||
- DJANGO_ALLOWED_HOSTS=api.dev.sophon.steffo.eu
|
||||
# TODO: Configure your allowed origins! (* doesn't work)
|
||||
- DJANGO_ALLOWED_ORIGINS=http://dev.sophon.steffo.eu
|
||||
# TODO: Configure your proxy details!
|
||||
- APACHE_PROXY_BASE_DOMAIN=dev.sophon.steffo.eu
|
||||
- APACHE_PROXY_HTTP_PROTOCOL=http
|
||||
- DJANGO_PROXY_BASE_DOMAIN=dev.sophon.steffo.eu
|
||||
- DJANGO_PROXY_PROTOCOL=http
|
||||
- DJANGO_PROXY_CONTAINER_NAME=proxy
|
||||
# TODO: Configure your static url!
|
||||
- DJANGO_STATIC_URL=http://static.dev.sophon.steffo.eu/@django-static/
|
||||
# TODO: Set your language!
|
||||
- DJANGO_LANGUAGE_CODE=en-us
|
||||
# TODO: Set your timezone!
|
||||
|
@ -52,10 +55,18 @@ services:
|
|||
- DJANGO_SU_EMAIL=root@example.org
|
||||
- DJANGO_SU_PASSWORD=square
|
||||
# Don't change these.
|
||||
- DJANGO_DATABASE_ENGINE=django.db.backends.postgresql
|
||||
- DJANGO_DATABASE_HOST=db
|
||||
- DJANGO_DATABASE_USER=sophon
|
||||
- DJANGO_DATABASE_PASSWORD=sophonity
|
||||
- DJANGO_DATABASE_NAME=sophon
|
||||
- DJANGO_AUTHENTICATION_BACKEND=django.contrib.auth.backends.ModelBackend
|
||||
- DJANGO_DOCKER_CONTAINER_PREFIX=sophon-container
|
||||
- DJANGO_DOCKER_VOLUME_PREFIX=sophon-volume
|
||||
- DJANGO_DOCKER_NETWORK_PREFIX=sophon-network
|
||||
- DJANGO_DOCKER_HOST=/var/run/docker.sock
|
||||
- DJANGO_DOCKER_TLS_VERIFY=
|
||||
- DJANGO_DOCKER_CERT_PATH=
|
||||
volumes:
|
||||
- proxy-data:/run/sophon/proxy
|
||||
- static-data:/run/sophon/static
|
||||
|
@ -77,6 +88,7 @@ services:
|
|||
- SOPHON_FRONTEND_NAME=frontend:5000
|
||||
volumes:
|
||||
- proxy-data:/run/sophon/proxy
|
||||
- static-data:/usr/local/apache2/htdocs/django-static
|
||||
depends_on:
|
||||
- backend
|
||||
- frontend
|
||||
|
|
|
@ -563,16 +563,24 @@ ProxyPreserveHost on
|
|||
|
||||
# Proxy regular requests to the frontend
|
||||
# sophon.steffo.eu → frontend
|
||||
RewriteCond "%{ENV:matched}" "! -eq 1" [NC] # If the url hasn't been matched by the previous rules
|
||||
RewriteCond "%{ENV:APACHE_PROXY_BASE_DOMAIN} %{HTTP_HOST}" "^([^ ]+) \1$" [NC] # If ENV:APACHE_PROXY_BASE_DOMAIN equals HTTP_HOST
|
||||
RewriteCond "%{ENV:SOPHON_FRONTEND_NAME}" "^(.+)$" [NC] # Capture ENV:SOPHON_FRONTEND_NAME for substitution in the rewriterule
|
||||
RewriteRule "/(.*)" "http://%1/$1" [P,L,E=matched:1] # Rewrite and set the matched flag
|
||||
|
||||
# Proxy api requests to the backend
|
||||
# api.sophon.steffo.eu → backend
|
||||
RewriteCond "%{ENV:matched}" "! -eq 1" [NC] # If the url hasn't been matched by the previous rules
|
||||
RewriteCond "api.%{ENV:APACHE_PROXY_BASE_DOMAIN} %{HTTP_HOST}" "^([^ ]+) \1$" [NC] # If api. prefixed to ENV:APACHE_PROXY_BASE_DOMAIN equals HTTP_HOST
|
||||
RewriteCond "%{ENV:SOPHON_BACKEND_NAME}" "^(.+)$" [NC] # Capture ENV:SOPHON_BACKEND_NAME for substitution in the rewriterule
|
||||
RewriteRule "/(.*)" "http://%1/$1" [P,L,E=matched:1] # Rewrite and set the matched flag
|
||||
|
||||
# Proxy static requests to the static files
|
||||
# static.sophon.steffo.eu → static
|
||||
RewriteCond "%{ENV:matched}" "! -eq 1" [NC] # If the url hasn't been matched by the previous rules
|
||||
RewriteCond "static.%{ENV:APACHE_PROXY_BASE_DOMAIN} %{HTTP_HOST}" "^([^ ]+) \1$" [NC] # If static. prefixed to ENV:APACHE_PROXY_BASE_DOMAIN equals HTTP_HOST
|
||||
RewriteRule "/@django-static/(.*)" "/django-static/$1" [P,L,E=matched:1] # Rewrite and set the matched flag
|
||||
|
||||
# Create a map between the proxy file generated by Sophon and Apache
|
||||
RewriteMap "sophonproxy" "dbm=gdbm:/run/sophon/proxy/proxy.dbm"
|
||||
|
||||
|
|
Loading…
Reference in a new issue