From c31143302a8129298d0f0ee281793946bb57c6b6 2024-03-05 22:12:33 From: Branko Majic Date: 2024-03-05 22:12:33 Subject: [PATCH] MAR-192: Update deployment instructions and configuration for Django Wiki in usage instructions: - Bring the package and its dependencies to latest possible (LTS) version. --- diff --git a/docs/usage.rst b/docs/usage.rst index 81f819803bd73af605db411d485de3aea0ca4161..d8825e8a866747b34ab20e2c0b07cdb936a7e3c4 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -1874,6 +1874,7 @@ on the safe side: - libpng-dev - libmariadb-dev - libmariadb-dev-compat + - pkg-config # Here we specify that anything accessing our website with "/static/" # URL should be treated as request to a static file, to be served # directly by Nginx instead of the WSGI server. @@ -1886,8 +1887,8 @@ on the safe side: # These are additional packages that should be installed in the # virtual environment. virtualenv_packages: - - django~=2.2.0 - - wiki~=0.5.0 + - django~=4.2.0 + - wiki~=0.10.0 - mysqlclient # This is the name of the WSGI application to # serve. wiki_example_com.wsgi will be the Python "module" that is @@ -1897,7 +1898,8 @@ on the safe side: wsgi_application: wiki_example_com.wsgi:application # Specify explicitly requirements for installing Gunicorn. wsgi_requirements: - - gunicorn==20.0.4 + - gunicorn==21.2.0 + - packaging==23.2 wsgi_requirements_in: - gunicorn - role: database @@ -1942,7 +1944,7 @@ on the safe side: mode: 02750 - name: Start Django project for the Wiki website - command: "/var/www/wiki.example.com/virtualenv/bin/exec django-admin.py startproject wiki_example_com /var/www/wiki.example.com/code" + command: "/var/www/wiki.example.com/virtualenv/bin/exec django-admin startproject wiki_example_com /var/www/wiki.example.com/code" args: chdir: "/var/www/wiki.example.com" creates: "/var/www/wiki.example.com/code/wiki_example_com" @@ -1954,7 +1956,7 @@ on the safe side: src: "{{ item }}" dest: "/var/www/wiki.example.com/code/wiki_example_com/{{ item }}" mode: 0640 - owner: admin + owner: admin-wiki_example_com group: web-wiki_example_com with_items: - settings.py @@ -1973,16 +1975,16 @@ on the safe side: - migrate - collectstatic - - name: Deploy the superadmin creation script + - name: Deploy the superuser creation script copy: - src: "create_superadmin.py" - dest: "/var/www/wiki.example.com/code/create_superadmin.py" + src: "create_superuser.py" + dest: "/var/www/wiki.example.com/code/create_superuser.py" owner: admin-wiki_example_com group: web-wiki_example_com mode: 0750 - name: Create initial superuser - command: "/var/www/wiki.example.com/virtualenv/bin/exec ./create_superadmin.py" + command: "/var/www/wiki.example.com/virtualenv/bin/exec ./create_superuser.py" args: chdir: "/var/www/wiki.example.com/code/" become: yes @@ -2009,32 +2011,34 @@ on the safe side: """ Django settings for wiki_example_com project. + Generated by 'django-admin startproject' using Django 4.2.11. + For more information on this file, see - https://docs.djangoproject.com/en/2.2/topics/settings/ + https://docs.djangoproject.com/en/4.2/topics/settings/ For the full list of settings and their values, see - https://docs.djangoproject.com/en/2.2/ref/settings/ + https://docs.djangoproject.com/en/4.2/ref/settings/ """ - import os + from pathlib import Path from django.urls import reverse_lazy - # Build paths inside the project like this: os.path.join(BASE_DIR, ...) - BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + # Build paths inside the project like this: BASE_DIR / 'subdir'. + BASE_DIR = Path(__file__).resolve().parent.parent + # Quick-start development settings - unsuitable for production - # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ + # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! - SECRET_KEY = '8rok13az%bqtb=ya&s9sia_x*@@rhd9a%g=!6nh4tb!g14rlt^' + SECRET_KEY = 'django-insecure-*!yz4t12j5&x%-p%dd$uw!$-7(8vm)r%(87iz65-7t_7uh8j)0' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = False ALLOWED_HOSTS = ["wiki.example.com", "localhost"] - # Application definition INSTALLED_APPS = [ @@ -2044,17 +2048,21 @@ on the safe side: 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'django.contrib.sites.apps.SitesConfig', - 'django.contrib.humanize.apps.HumanizeConfig', + 'django.contrib.sites', + 'django.contrib.humanize', 'django_nyt.apps.DjangoNytConfig', 'mptt', 'sekizai', 'sorl.thumbnail', 'wiki.apps.WikiConfig', 'wiki.plugins.attachments.apps.AttachmentsConfig', - 'wiki.plugins.notifications.apps.NotificationsConfig', + 'wiki.plugins.editsection.apps.EditSectionConfig', + 'wiki.plugins.globalhistory.apps.GlobalHistoryConfig', + 'wiki.plugins.help.apps.HelpConfig', 'wiki.plugins.images.apps.ImagesConfig', + 'wiki.plugins.links.apps.LinksConfig', 'wiki.plugins.macros.apps.MacrosConfig', + 'wiki.plugins.notifications.apps.NotificationsConfig', ] MIDDLEWARE = [ @@ -2076,15 +2084,15 @@ on the safe side: 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ - 'django.contrib.auth.context_processors.auth', 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', 'django.template.context_processors.i18n', 'django.template.context_processors.media', - 'django.template.context_processors.request', 'django.template.context_processors.static', 'django.template.context_processors.tz', - 'django.contrib.messages.context_processors.messages', - "sekizai.context_processors.sekizai", + 'sekizai.context_processors.sekizai', ], }, }, @@ -2094,7 +2102,7 @@ on the safe side: # Database - # https://docs.djangoproject.com/en/2.2/ref/settings/#databases + # https://docs.djangoproject.com/en/4.2/ref/settings/#databases DATABASES = { 'default': { @@ -2108,7 +2116,7 @@ on the safe side: } # Password validation - # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators + # https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { @@ -2127,7 +2135,7 @@ on the safe side: # Internationalization - # https://docs.djangoproject.com/en/2.2/topics/i18n/ + # https://docs.djangoproject.com/en/4.2/topics/i18n/ LANGUAGE_CODE = 'en-us' @@ -2135,17 +2143,20 @@ on the safe side: USE_I18N = True - USE_L10N = True - USE_TZ = True # Static files (CSS, JavaScript, Images) - # https://docs.djangoproject.com/en/2.2/howto/static-files/ + # https://docs.djangoproject.com/en/4.2/howto/static-files/ - STATIC_URL = '/static/' + STATIC_URL = 'static/' STATIC_ROOT = '/var/www/wiki.example.com/htdocs/static' + # Default primary key field type + # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field + + DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + SITE_ID = 1 LOGIN_REDIRECT_URL = reverse_lazy('wiki:get', kwargs={'path': ''}) @@ -2153,17 +2164,33 @@ on the safe side: :file:`~/mysite/roles/wiki/files/urls.py` :: + """ + URL configuration for wiki_example_com project. + + The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.2/topics/http/urls/ + Examples: + Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') + Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') + Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) + """ + from django.contrib import admin - from django.urls import path, include + from django.urls import include, path urlpatterns = [ path('admin/', admin.site.urls), path('notifications/', include('django_nyt.urls')), - path('', include('wiki.urls')) + path('', include('wiki.urls')), ] - - :file:`~/mysite/roles/wiki/files/create_superadmin.py` + :file:`~/mysite/roles/wiki/files/create_superuser.py` :: #!/usr/bin/env python