Skip to content
A clean Mezzanine CMS install, configured to be deployed to Heroku
CSS HTML JavaScript Python
Branch: master
Clone or download
Latest commit ae6abb0 Apr 28, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
deploy Commit Apr 28, 2019
free_theme_flat Commit Apr 28, 2019
free_theme_moderna Commit Apr 28, 2019
free_theme_nova Commit Apr 28, 2019
free_theme_solid Commit Apr 28, 2019
onlineshop Commit Apr 28, 2019
.gitattributes Commit Apr 28, 2019
.gitignore
Procfile Commit Apr 28, 2019
app.json Commit Apr 28, 2019
fabfile.py Commit Apr 28, 2019
license Commit Apr 28, 2019
local-heroku.procfile Commit Apr 28, 2019
manage.py Commit Apr 28, 2019
readme.md Commit Apr 28, 2019
requirements.txt Commit Apr 28, 2019
runtime.txt Commit Apr 28, 2019

readme.md

Mezzanine on Heroku

A clean install of Mezzanine CMS with the Cartridge e-commerce extension, with an API for connecting iOS and Android apps for example, that integrates with Stripe for payment processing, and that is configured to deploy to Heroku and to use Amazon S3 for media storage.

Do an automated deploy to Heroku and select one of the free themes for Mezzanine, Flat, Moderna, Nova or Solid: Deploy

  1. Build
  2. Deploy
  3. Theme

Build

Install Python and PostgreSQL

Start a Python virtual environment

Clone the repository and run:

virtualenv env
source env/bin/activate
pip3 install -r requirements.txt

Configure the system

In onlineshop/settings.py and onlineshop/heroku_settings.py, set values for the following:

Install a clean database

Create a local PostgreSQL database called onlineshop

Run all migrations:

python3 manage.py makemigrations
python3 manage.py migrate

If the theme is not used and all default settings are restored, no migrations are necessary so just create the database:

python3 manage.py createdb --noinput --nodata

Run the development web server

Collect the static files:

python3 manage.py collectstatic

Run a Django development server:

python3 manage.py runserver

Browse to http://localhost:8000/

Run a Gunicorn web server similar to Heroku:

heroku local -f local-heroku.procfile

Browse to http://localhost:5000/

For managing content with Mezzanine, browse to http://localhost:8000/admin

The default super user is 'admin' and the password is 'default'. You should change this.

To clear the static file cache:

python3 manage.py clear_cache

Work with the API

Add an API key via the admin and note the token and secret key: http://localhost:8000/admin/rest_framework_api_key/apikey/add/

Browse to the API documentation at http://localhost:8000/api/docs, click the Authorize button and enter the token and secret key, and then try out any of the API calls.

Deactivate the virtual environment

If you need to recreate the virtual environment, perhaps to clear any changes you made directly to any of the installed Python packages, deactivate the virtual environment first:

deactivate

Deploy

Download the Heroku CLI

Login:

heroku login

Create an app:

heroku create

Note the Heroku app name, and add the Heroku Git repository as a remote to this Git repository:

heroku git:remote -a [heroku-app-name]

Configure New Relic:

heroku addons:create newrelic:wayne
heroku config:set NEW_RELIC_APP_NAME=[heroku-app-name]

Deploy the code:

git push heroku master

If the Amazon S3 media file storage configuration is removed, then the Mezzanine Media Library in staticfiles/media is included in the Git repo, and can be included in the deploy.

Create a PostgreSQL database for Mezzanine on Heroku

heroku run python manage.py createdb --noinput --nodata --settings=onlineshop.heroku_settings

Production

View production site:

heroku open

Access the production PostgreSQL database:

heroku pg:psql [heroku-database-name] --app [heroku-app-name]

Put Heroku app in maintenance mode to display a user friendly offline page:

heroku maintenance:on

Run a Mezzanine/Django Python shell on Heroku, for example, create a super user:

heroku run python manage.py shell --settings=onlineshop.heroku_settings`
from django.contrib.auth.models import User
user=User.objects.create_user('foo', password='bar')
user.is_superuser=True
user.is_staff=True
user.save()

Content publication workflow

Create a local Mezzanine PostgreSQL database backup:

pgpassword=[db-password] pg_dump -Fc --no-acl --no-owner -h localhost -U [postgres-user] [db-name] > mydb.dump

Generate a signed URL for a database backup that was uploaded to Amazon S3 storage:

aws s3 presign s3://[s3-bucket-name]/mydb.dump

Restore a Mezzanine PostgreSQL database backup to Heroku from Amazon S3, using a signed URL:

heroku pg:backups:restore [aws-s3-signed-url] [heroku-db-name] --confirm [heroku-appname]

If only database structural changes were made and no actual data changed, then Heroku could be updated with Django migrations:

heroku run "python manage.py makemigrations [django-appname] --settings=onlineshop.heroku_settings && python manage.py migrate [django-appname] --settings=onlineshop.heroku_settings"

Theme

For an excellent article on creating a theme, see this Bit of Pixels article.

You can’t perform that action at this time.