Netlify

Netlify is a platform that allows deployment of static sites.

  1. Import your website from Git.
  2. In the app settings, go to Buid & Deploy and Environment.
  3. Add an environment variable WAGTAIL_GRAPHQL_ENDPOINT pointing at your website’s GraphQL endpoint.
  4. Trigger the build.

For more information consult GatsbyJS’s guide.

Automatic deployments from Wagtail

Netlify allows creating build hooks. They are URLs that can be used to trigger a new deployment.

To set up a deployment hook on page publish in Wagtail, please add a new signal handler in the project.

# models.py
from django.conf import settings

from wagtail.core.signals import page_published, page_unpublished

import requests


def deploy_to_netlify_on_change(**kwargs):
    try:
       netlify_deploy_hook_url = getattr(settings, 'NETLIFY_DEPLOY_HOOK_URL')
    except KeyError:
       return
    if not netlify_deploy_hook_url:
       return
    r = requests.post(netlify_deploy_hook_url)
    r.raise_for_status()


page_published.connect(deploy_to_netlify_on_change)
page_unpublished.connect(deploy_to_netlify_on_change)

Then add the Netlify deploy hook to your settings.

# settings.py
import os

if 'NETLIFY_DEPLOY_HOOK_URL' in os.environ:
    NETLIFY_DEPLOY_HOOK_URL = os.environ['NETLIFY_DEPLOY_HOOK_URL']
  1. Go to the Netlify app settings, Build & Deploy and Build Hooks. Add a new build hook for the Wagtail CMS.
  2. On the back-end server set the environment variable NETLIFY_DEPLOY_HOOK_URL to the generated hook URL.