Merge branch 'main' into fix_sqlite-url

This commit is contained in:
Abhilash Raj
2024-06-08 06:29:18 +05:30
committed by GitHub
27 changed files with 262 additions and 147 deletions

View File

@@ -1,42 +1,44 @@
# syntax = docker/dockerfile:1.3
FROM alpine:3.12
FROM alpine:3.20.0
# Add needed files for uwsgi server + settings for django
COPY mailman-web /opt/mailman-web
# Add startup script to container
COPY docker-entrypoint.sh /usr/local/bin/
# Add requirements file.
COPY requirements.txt /tmp/
# Install packages and dependencies for postorius and hyperkitty Add user for
# executing apps, change ownership for uwsgi+django files and set execution
# rights for management script
RUN --mount=type=cache,target=/root/.cache \
set -ex \
&& apk add --no-cache --virtual .build-deps gcc libc-dev linux-headers \
&& apk add --no-cache --virtual .build-deps gcc libc-dev linux-headers libldap \
postgresql-dev mariadb-dev mariadb-connector-c python3-dev libffi-dev openldap-dev cargo rust \
&& apk add --no-cache --virtual .mailman-rundeps bash sassc \
&& apk add --no-cache --virtual .mailman-rundeps bash sassc tzdata \
postgresql-client mysql-client py3-mysqlclient curl mailcap gettext \
python3 py3-pip xapian-core xapian-bindings-python3 libffi pcre-dev py-cryptography \
&& python3 -m pip install -U 'Django<3.2' pip setuptools wheel \
&& pip install mailmanclient==3.3.3 \
postorius==1.3.6 \
hyperkitty==1.3.5 \
django-mailman3==1.3.7 \
mistune==2.0.0rc1 \
&& python3 -m pip install --break-system-packages -U 'Django<4.3' pip setuptools wheel \
&& pip install --break-system-packages -r /tmp/requirements.txt \
whoosh \
uwsgi \
'psycopg2<2.9' \
psycopg2 \
dj-database-url \
mysqlclient \
typing \
xapian-haystack \
django-auth-ldap \
python-memcached \
pymemcache \
diskcache \
django-utils-six \
tzdata \
'django-allauth[socialaccount,openid]' \
&& apk del .build-deps \
&& addgroup -S mailman \
&& adduser -S -G mailman mailman \
&& chown -R mailman /opt/mailman-web/ \
&& adduser -S -G mailman mailman
# Add needed files for uwsgi server + settings for django
COPY mailman-web /opt/mailman-web
# Add startup script to container
COPY docker-entrypoint.sh /usr/local/bin/
RUN chown -R mailman /opt/mailman-web/ \
&& chmod u+x /opt/mailman-web/manage.py
WORKDIR /opt/mailman-web

View File

@@ -1,10 +1,5 @@
# syntax = docker/dockerfile:1.3
FROM alpine:3.12
# Add needed files for uwsgi server + settings for django
COPY mailman-web /opt/mailman-web
# Add startup script to container
COPY docker-entrypoint.sh /usr/local/bin/
FROM alpine:3.20.0
ARG POSTORIUS_REF
ARG HYPERKITTY_REF
@@ -16,34 +11,42 @@ ARG CLIENT_REF
# rights for management script
RUN --mount=type=cache,target=/root/.cache \
set -ex \
&& apk add --no-cache --virtual .build-deps gcc libc-dev linux-headers git \
&& apk add --no-cache --virtual .build-deps gcc libc-dev linux-headers git libldap \
postgresql-dev mariadb-dev mariadb-connector-c python3-dev libffi-dev openldap-dev cargo rust \
&& apk add --no-cache --virtual .mailman-rundeps bash sassc pcre-dev \
&& apk add --no-cache --virtual .mailman-rundeps bash sassc pcre-dev tzdata \
python3 py3-pip postgresql-client mysql-client py3-mysqlclient \
curl mailcap xapian-core xapian-bindings-python3 libffi gettext py-cryptography \
&& python3 -m pip install -U pip setuptools wheel \
&& python3 -m pip install -U \
&& python3 -m pip install --break-system-packages -U pip setuptools wheel \
&& python3 -m pip install --break-system-packages -U \
git+https://gitlab.com/mailman/mailmanclient \
git+https://gitlab.com/mailman/postorius \
git+https://gitlab.com/mailman/hyperkitty \
whoosh \
uwsgi \
'psycopg2<2.9' \
psycopg2 \
dj-database-url \
mysqlclient \
xapian-haystack \
django-auth-ldap \
python-memcached \
pymemcache \
tzdata \
diskcache \
django-utils-six \
&& python3 -m pip install -U 'Django<3.2' \
&& python3 -m pip install -U \
'django-allauth[socialaccount,openid]' \
&& python3 -m pip install --break-system-packages -U 'Django<4.3' \
&& python3 -m pip install --break-system-packages -U \
git+https://gitlab.com/mailman/django-mailman3 \
&& apk del .build-deps \
&& addgroup -S mailman \
&& adduser -S -G mailman mailman \
&& chown -R mailman /opt/mailman-web/ \
&& chmod u+x /opt/mailman-web/manage.py
&& adduser -S -G mailman mailman
# Add needed files for uwsgi server + settings for django
COPY mailman-web /opt/mailman-web
# Add startup script to container
COPY docker-entrypoint.sh /usr/local/bin/
RUN chown -R mailman /opt/mailman-web/ \
&& chmod u+x /opt/mailman-web/manage.py
WORKDIR /opt/mailman-web

View File

@@ -56,16 +56,16 @@ change them unless you know what you want.
- `SMTP_HOST_PASSWORD`: Default is an empty string.
- `SMTP_USE_TLS`: Specifies wheather the SMTP connection is encrypted
via TLS. Default is `False`.
via TLS. Default is `False`. (`EMAIL_USE_TLS`/`EMAIL_USE_SSL` are mutually exclusive, so only set one of those settings.)
- `SMTP_USE_SSL`: Specifies wheather the SMTP connection is encrypted
via SSL. Default is `False`.
via SSL. Default is `False`. (EMAIL_USE_TLS/EMAIL_USE_SSL are mutually exclusive, so only set one of those settings.)
- `DJANGO_LOG_URL`: Path to the django's log file. Defaults to
`/opt/mailman-web-data/logs/mailmanweb.log`.
- `DJANGO_ALLOWED_HOSTS`: Entry to add to ALLOWED_HOSTS in Django
configuration. This is a separate configuration from`SERVE_FROM_DOMAIN` as
configuration. Format as comma-separated list (no whitespace). This is a separate configuration from`SERVE_FROM_DOMAIN` as
latter is used for other purposes too.
- `POSTORIUS_TEMPLATE_BASE_URL`: The base url at which the `mailman-web`

View File

@@ -7,7 +7,7 @@ function wait_for_postgres () {
# moving forward.
# TODO: Use python's psycopg2 module to do this in python instead of
# installing postgres-client in the image.
until psql $DATABASE_URL -c '\l'; do
until psql -P pager=off $DATABASE_URL -c '\l'; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
@@ -118,12 +118,12 @@ echo "Compiling locale files in $SITE_DIR"
cd $SITE_DIR && /opt/mailman-web/manage.py compilemessages && cd -
# Compress static files.
python3 manage.py compress --force
python3 /opt/mailman-web/manage.py compress --force
# Migrate all the data to the database if this is a new installation, otherwise
# this command will upgrade the database.
python3 manage.py migrate
python3 /opt/mailman-web/manage.py migrate
# If MAILMAN_ADMIN_USER and MAILMAN_ADMIN_EMAIL is defined create a new
# superuser for Django. There is no password setup so it can't login yet unless
@@ -131,7 +131,7 @@ python3 manage.py migrate
if [[ -v MAILMAN_ADMIN_USER ]] && [[ -v MAILMAN_ADMIN_EMAIL ]];
then
echo "Creating admin user $MAILMAN_ADMIN_USER ..."
python3 manage.py createsuperuser --noinput --username "$MAILMAN_ADMIN_USER"\
python3 /opt/mailman-web/manage.py createsuperuser --noinput --username "$MAILMAN_ADMIN_USER"\
--email "$MAILMAN_ADMIN_EMAIL" 2> /dev/null || \
echo "Superuser $MAILMAN_ADMIN_USER already exists"
fi
@@ -141,7 +141,7 @@ fi
if [[ -v SERVE_FROM_DOMAIN ]];
then
echo "Setting $SERVE_FROM_DOMAIN as the default domain ..."
python3 manage.py shell -c \
python3 /opt/mailman-web/manage.py shell -c \
"from django.contrib.sites.models import Site; Site.objects.filter(domain='example.com').update(domain='$SERVE_FROM_DOMAIN', name='$SERVE_FROM_DOMAIN')"
fi

View File

@@ -29,7 +29,7 @@ https://docs.djangoproject.com/en/1.8/ref/settings/
import os
import dj_database_url
import sys
from socket import gethostbyname
from socket import gethostbyname, gaierror
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -49,14 +49,17 @@ SITE_ID = 1
# See https://docs.djangoproject.com/en/3.1/ref/settings/#allowed-hosts
ALLOWED_HOSTS = [
"localhost", # Archiving API from Mailman, keep it.
# "lists.your-domain.org",
# Add here all production URLs you may have.
"mailman-web",
gethostbyname("mailman-web"),
os.environ.get('SERVE_FROM_DOMAIN'),
os.environ.get('DJANGO_ALLOWED_HOSTS'),
]
try:
ALLOWED_HOSTS.append(gethostbyname("mailman-web")) # only add if this resolves
except gaierror:
pass
ALLOWED_HOSTS.extend(os.getenv("DJANGO_ALLOWED_HOSTS", "").split(","))
# Mailman API credentials
MAILMAN_REST_API_URL = os.environ.get('MAILMAN_REST_URL', 'http://mailman-core:8001')
MAILMAN_REST_API_USER = os.environ.get('MAILMAN_REST_USER', 'restadmin')
@@ -81,6 +84,7 @@ DEFAULT_APPS = [
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'rest_framework',
'django_gravatar',
'compressor',
@@ -109,6 +113,7 @@ MIDDLEWARE = (
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'allauth.account.middleware.AccountMiddleware',
'django_mailman3.middleware.TimezoneMiddleware',
'postorius.middleware.PostoriusMiddleware',
)
@@ -151,6 +156,11 @@ DATABASES = {
'default': dj_database_url.config(conn_max_age=600)
}
# Avoid Django 3.2+ warning
# https://github.com/maxking/docker-mailman/issues/595
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
# If you're behind a proxy, use the X-Forwarded-Host header
# See https://docs.djangoproject.com/en/1.8/ref/settings/#use-x-forwarded-host
USE_X_FORWARDED_HOST = True
@@ -178,7 +188,7 @@ AUTH_PASSWORD_VALIDATORS = [
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
TIME_ZONE = os.environ.get('TZ', 'UTC')
USE_I18N = True

View File

@@ -16,20 +16,19 @@
# You should have received a copy of the GNU General Public License along with
# Postorius. If not, see <http://www.gnu.org/licenses/>.
from django.conf.urls import include, url
from django.conf.urls import include
from django.contrib import admin
from django.urls import reverse_lazy
from django.urls import path, reverse_lazy
from django.views.generic import RedirectView
urlpatterns = [
url(r'^$', RedirectView.as_view(
path(r'', RedirectView.as_view(
url=reverse_lazy('list_index'),
permanent=True)),
url(r'^postorius/', include('postorius.urls')),
url(r'^hyperkitty/', include('hyperkitty.urls')),
url(r'', include('django_mailman3.urls')),
url(r'^accounts/', include('allauth.urls')),
path(r'postorius/', include('postorius.urls')),
path(r'hyperkitty/', include('hyperkitty.urls')),
path(r'', include('django_mailman3.urls')),
path(r'accounts/', include('allauth.urls')),
# Django admin
url(r'^admin/', admin.site.urls),
path(r'admin/', admin.site.urls),
]

View File

@@ -3,10 +3,13 @@
uwsgi-socket = 0.0.0.0:8080
http-socket = 0.0.0.0:8000
#Enable threading for python
# Enable threading for python
enable-threads = true
# Move to the directory wher the django files are.
# Setting uwsgi buffer size to what Apache2 supports.
buffer-size = 8190
# Move to the directory where the django files are.
chdir = /opt/mailman-web
# Use the wsgi file provided with the django project.
@@ -17,7 +20,7 @@ master = true
processes = 2
threads = 2
# Drop privielges and don't run as root.
# Drop privileges and don't run as root.
uid = mailman
gid = mailman

4
web/requirements.txt Normal file
View File

@@ -0,0 +1,4 @@
mailmanclient==3.3.5
postorius==1.3.10
hyperkitty==1.3.9
django-mailman3==1.3.11