Wagtail Web Deployment

System overview


Dev deployment

database

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

static storage

# settings/dev.py

# where user's static file will be stored
STATICFILES_DIRS = [
    os.path.join(PROJECT_DIR, 'static'),
]

# where collectstatic command output will be stored
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

# relative URL to access static files, ie: http://domain.com/static/app.css
STATIC_URL = '/static/'

media storage

dev tools


Staging deployment

CI/CD pipeline

name: CI/CD

on:
  push:
    branches: [ main, feat/* ]
  pull_request:
    branches: [ main ]
  workflow_dispatch:

jobs:
  deploy:

    runs-on: ubuntu-20.04
    strategy:
      max-parallel: 4
      matrix:
        python-version: [3.9]
        
    steps:
    - name: Checkout repo
      uses: actions/checkout@v2
    - name: Set up Python $
      uses: actions/setup-python@v3
      with:
        python-version: $
    - name: Install Dependencies
      run: |
        python -m pip install --upgrade pip pipenv
        pipenv install --system --dev --ignore-pipfile
    - name: Run Tests
      run: |
        python manage.py test
    - name: Deploy
      uses: akhileshns/heroku-deploy@v3.12.12 # This is the action
      with:
        heroku_api_key: $
        ...
      env:
        HD_DJANGO_SETTINGS_MODULE: "app.settings.staging" # env prefix is HD_ to be recognized by heroku deploy service
        ...
    - name: Slack Notification
      if: always()
      uses: rtCamp/action-slack-notify@v2
      env:
        SLACK_WEBHOOK: $
        ...

hosting

# ./Procfile

web: gunicorn app.wsgi
release: python manage.py migrate
$ python manage.py collectstatic --noinput

database

object storage (media, static files)

# settings/staging.py

INSTALLED_APPS += [
    'django.contrib.staticfiles',
    'cloudinary_storage',
    'cloudinary',
]
CLOUDINARY_STORAGE = {
    'CLOUD_NAME': os.environ.get("CLOUDINARY_NAME", "foo"),
    'API_KEY': os.environ.get("CLOUDINARY_API_KEY", "foo"),
    'API_SECRET': os.environ.get("CLOUDINARY_API_SECRET", "foo"),
    'STATICFILES_MANIFEST_ROOT': os.path.join(BASE_DIR, "static")
}
DEFAULT_FILE_STORAGE = 'cloudinary_storage.storage.MediaCloudinaryStorage'
# settings/staging.py

MIDDLEWARE += [
    "whitenoise.middleware.WhiteNoiseMiddleware",
]
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"

other settings

# settings/staging.py

ALLOWED_HOSTS = ["domain.com"]
# or easier
ALLOWED_HOSTS = ["*"]
Tags: work  web