pelican cloudflare python

Deploy pelican to cloudflare

Marcelino Veloso III, , last modified on 19 May 2023

Python version

The pyproject.toml should contain the Python version used by Pelican. This will be communicated to Cloudflare on deployment.

python = "^3.10" # note version
pelican = "^4.8"
markdown = "^3.4.3"

The Cloudflare docs default to 3.10.5 under the beta build system version.

Adjustment is possible but the disadvantage is that Cloudflare Pages will have to download and install the adjusted Python version every single deployment. 3.10.5 seems good enough. I employ a .python-version file with a single line (can also specify the PYTHON_VERSION env variable in the dashboard) to explicitly provide:

3.10.5

requirements.txt

Ensure updated requirements.txt via:

poetry export -f requirements.txt \
  --without-hashes \
  --output requirements.txt

Without the requirements.txt, using just poetry fails:

Installing project dependencies: poetry install
... /bin/sh: 1: poetry: not found

publishconf.py

  1. Add SITEURL
  2. Set FEED_DOMAIN = SITEURL
  3. Finalize DIRECT_TEMPLATES

Setup Custom Domain

  1. Add nameservers re: sampledomain.com
  2. Add www record for sampledomain.com
  3. Add page rule to permanently redirect www.sampledomain.com to https://sampledomain.com

Configure

Link repo to Cloudflare modifying:

Configuration option Value
Build command pelican content

To:

Configuration option Value
Build command pelican content -s publishconf.py