Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker #556

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
FROM python:3.11-bookworm
#LABEL maintainer="[email protected]"

ARG BUILD=prod
ARG uwsgi_uid=700
ARG uwsgi_gid=700

ENV BASEDOMAIN=nsupdate.localdomain
ENV BUILD=$BUILD
ENV DATABASE_URL="sqlite:////config/nsupdate.sqlite"
ENV [email protected]
ENV DJANGO_SETTINGS_MODULE=local_settings
ENV DJANGO_SUPERPASS=S3cr3t
ENV DJANGO_SUPERUSER_EMAIL="[email protected]"
ENV DJANGO_SUPERUSER_PASSWORD="admin"
ENV DJANGO_SUPERUSER_USERNAME="admin"
ENV DOCKER_CONTAINER=1
ENV SECRET_KEY=S3cr3t
ENV [email protected]
ENV UWSGI_INI=/nsupdate/uwsgi.ini
ENV PYTHONPATH="/nsupdate/src"

RUN mkdir /config

# Install python3 and pip
RUN DEBIAN_FRONTEND=noninteractive apt update \
&& apt install -y --no-install-recommends \
git
RUN git clone https://github.com/nsupdate-info/nsupdate.info.git /nsupdate \
&& cd /nsupdate/ \
&& pip install -r requirements.d/prod.txt \
&& pip install -e .

COPY local_settings.py.default /nsupdate/src/local_settings.py
RUN django-admin migrate \
&& django-admin createsuperuser --noinput

RUN rm -rf /tmp/* /var/tmp/* \
&& rm -rf /var/lib/apt/lists/*


EXPOSE 8000

COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh

VOLUME ["/config"]

#ENTRYPOINT ["django-admin", "runserver"]
#ENTRYPOINT ["python3", "/nsupdate/manage.py", "runserver", "0.0.0.0:8000"]
ENTRYPOINT ["/docker-entrypoint.sh"]
#ENTRYPOINT ["tail", "-f", "/dev/null"]
RUN pip install django-xff
RUN pip install whitenoise
RUN django-admin collectstatic --noinput
2 changes: 2 additions & 0 deletions docker/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
To run locally:
`docker compose build && docker compose up`
12 changes: 12 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
nsupdate.info:
build: .
container_name: nsupdate.info
volumes:
- ./config:/config
- ./local_settings.py:/nsupdate/src/local_settings.py
ports:
- 8916:8000
restart: unless-stopped
env_file:
- .env_prod
17 changes: 17 additions & 0 deletions docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# Collect static files
#echo "Collect static files"
#python manage.py collectstatic --noinput

# Apply database migrations
echo "Apply database migrations"
python3 /nsupdate/manage.py migrate
python3 /nsupdate/manage.py createsuperuser --noinput

# Start server
echo "Starting server"
#python3 /nsupdate/manage.py runserver 0.0.0.0:8000
cd /nsupdate/src
#gunicorn --workers=4 --log-level=info --forwarded-allow-ips="$TRUSTED_PROXIES" --bind 0.0.0.0:8000 nsupdate.wsgi
gunicorn --workers=4 --log-level=info --forwarded-allow-ips='*' --bind 0.0.0.0:8000 nsupdate.wsgi
51 changes: 51 additions & 0 deletions docker/local_settings.py.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from nsupdate.settings.prod import *

SECRET_KEY='S3CR3T'

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '/config/nsupdate.sqlite', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': '',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '' # Set to empty string for default.
}
}

TIME_ZONE='Europe/Rome'

BASEDOMAIN='dyn.example.com'
# Create A records for www, ipv4, ipv6 and BASEDOMAIN.
# Also setup SSL certs for these SANs on the reverse proxy.
WWW_HOST = 'www.' + BASEDOMAIN # a host with a ipv4 and a ipv6 address
WWW_IPV4_HOST = 'ipv4.' + BASEDOMAIN # a host with ONLY a ipv4 address
WWW_IPV6_HOST = 'ipv6.' + BASEDOMAIN # a host with ONLY a ipv6 address
ALLOWED_HOSTS = [WWW_HOST, WWW_IPV4_HOST, WWW_IPV6_HOST]

DEBUG=False

MIDDLEWARE = MIDDLEWARE + ('xff.middleware.XForwardedForMiddleware',)
MIDDLEWARE = MIDDLEWARE + ('whitenoise.middleware.WhiteNoiseMiddleware',)

# The WhiteNoise middleware should be placed directly after the Django
# SecurityMiddleware (if you are using it) and before all other middleware
# BUT it WORKS even if it's the last one ...
#MIDDLEWARE = (
# 'django.middleware.security.SecurityMiddleware',
# 'whitenoise.middleware.WhiteNoiseMiddleware',
# 'xff.middleware.XForwardedForMiddleware',
# 'django.middleware.common.CommonMiddleware',
# 'django.contrib.sessions.middleware.SessionMiddleware',
# 'django.middleware.locale.LocaleMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
# 'django_referrer_policy.middleware.ReferrerPolicyMiddleware',
# 'django.contrib.auth.middleware.AuthenticationMiddleware',
# 'django.contrib.messages.middleware.MessageMiddleware',
# 'social_django.middleware.SocialAuthExceptionMiddleware',
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
#)
#
STATIC_ROOT='/nsupdate/static'
XFF_TRUSTED_PROXY_DEPTH=1