Changeset - c31143302a81
[Not reviewed]
0 1 0
Branko Majic (branko) - 2 months ago 2024-03-05 22:12:33
branko@majic.rs
MAR-192: Update deployment instructions and configuration for Django Wiki in usage instructions:

- Bring the package and its dependencies to latest possible (LTS)
version.
1 file changed with 62 insertions and 35 deletions:
0 comments (0 inline, 0 general)
docs/usage.rst
Show inline comments
 
@@ -1871,36 +1871,38 @@ on the safe side:
 
            - libjpeg62-turbo
 
            - libjpeg-dev
 
            - libpng16-16
 
            - 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.
 
          static_locations:
 
            - /static/
 
          # Again, not mandatory, but it is good to have some sort of policy
 
          # for assigning UIDs.
 
          uid: 2001
 
          admin_uid: 3001
 
          # 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
 
          # accesed, while application is the object instantiated within it (the
 
          # application itself). The module is referenced relative to the code
 
          # directory (in our case /var/www/wiki.example.com/code/).
 
          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
 
          db_name: wiki
 
          db_password: wiki
 

	
 
@@ -1939,25 +1941,25 @@ on the safe side:
 
          state: directory
 
          owner: admin-wiki_example_com
 
          group: web-wiki_example_com
 
          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"
 
        become: yes
 
        become_user: admin-wiki_example_com
 

	
 
      - name: Deploy settings for wiki website
 
        copy:
 
          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
 
          - urls.py
 
        notify:
 
          - Restart wiki
 
@@ -1970,22 +1972,22 @@ on the safe side:
 
        become: yes
 
        become_user: admin-wiki_example_com
 
        with_items:
 
          - 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
 
        become_user: admin-wiki_example_com
 
        register: wiki_superuser
 
        changed_when: "wiki_superuser.stdout ==  'Created superuser.'"
 
@@ -2006,58 +2008,64 @@ on the safe side:
 
   :file:`~/mysite/roles/wiki/files/settings.py`
 
   ::
 

	
 
      """
 
      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 = [
 
          'django.contrib.admin',
 
          'django.contrib.auth',
 
          'django.contrib.contenttypes',
 
          '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 = [
 
          'django.middleware.security.SecurityMiddleware',
 
          'django.contrib.sessions.middleware.SessionMiddleware',
 
          'django.middleware.common.CommonMiddleware',
 
@@ -2073,31 +2081,31 @@ on the safe side:
 
          {
 
              'BACKEND': 'django.template.backends.django.DjangoTemplates',
 
              'DIRS': [],
 
              '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',
 
                  ],
 
              },
 
          },
 
      ]
 

	
 
      WSGI_APPLICATION = 'wiki_example_com.wsgi.application'
 

	
 

	
 
      # Database
 
      # https://docs.djangoproject.com/en/2.2/ref/settings/#databases
 
      # https://docs.djangoproject.com/en/4.2/ref/settings/#databases
 

	
 
      DATABASES = {
 
          'default': {
 
              'ENGINE': 'django.db.backends.mysql',
 
              'NAME': 'wiki',
 
              'USER': 'wiki',
 
@@ -2105,13 +2113,13 @@ on the safe side:
 
              'HOST': '127.0.0.1',
 
              'PORT': '3306',
 
          }
 
      }
 

	
 
      # 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 = [
 
          {
 
              'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
 
          },
 
          {
 
@@ -2124,49 +2132,68 @@ on the safe side:
 
              'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
 
          },
 
      ]
 

	
 

	
 
      # Internationalization
 
      # https://docs.djangoproject.com/en/2.2/topics/i18n/
 
      # https://docs.djangoproject.com/en/4.2/topics/i18n/
 

	
 
      LANGUAGE_CODE = 'en-us'
 

	
 
      TIME_ZONE = 'Europe/Stockholm'
 

	
 
      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': ''})
 

	
 
   :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
 

	
 
      import os
 
      from django import setup
0 comments (0 inline, 0 general)