building ghost-powered website’s contents in a scalable way
1. what we’re doing
We’re building a custom website for a particular client, and we’ll be using ghost as our cms. This allows us to quickly bootstrap the website, building a theme based on a custom design our client has previously picked.
2. the problem
To put this in a clear way, there’s three parts of the website we’ll deliver to our client:
- ghost, the CMS that will run our site
- a custom theme for our client, which has their colors, fonts, etc.
- the contents for the theme itself. the theme must have some contents in order to be fully displayed
It’s on the third item in the list where our problem lies on. Maybe it has not been paid too much attention, but there has to be a scalable way of handling the “base” or the “default” data the theme features. Some way in which a developer doesn’t see different contents than his partner when building the UI or when structuring the components and the elements for the webpage.
And it goes further than that – we’ll have:
- one development environment per development machine (and there’ll be a couple of persons building it simultaneously)
- a staging environment (or several of them, depending on how big our team) in which will be deployed automatically off from master branch and checked constantly so that we QA this shared env
- a production environment – which won’t be created right away but needs to be easily deployed (and re-built) with the “initial” data once we are ready to deliver
It’s important for our building team to have a similar copy of each one of these. Keeping everybody in the same page will avoid us misunderstandings.
3. why not use DB dumps?
Well, there’s a few reasons. First, each environment must be using a different DB engine. For convenience, development environments will be using sqlite3 which is better for a bootstrap, while production environments will be running PostgreSQL.
4. the solution
The missing piece must be a program which can create (and re-create) in a one-off-run the “initial” data for the database (aka seed the database) in order to allow us to show correctly our theme
5. how to?
We’ve released a gem, which will read fixtures (yml files) for the models that currently make up ghost’s structure and will create the necessary DB records. This way our contents are written in simple text files rather than hardcoded on the theme itself.
This project has some seed fixtures we can take a look as a sample: github.com/prendho/webpage/tree/master/config/seed/fixtures
And this is the ruby gem, I hope we’ll be documenting in the close future: rubygems.org/gems/ghost-seeder
I’ll be writing some more documentation in our GH repo github.com/noggalito/ghost-seeder but basically at the moment we run the task using rake and it creates (or re-creates) the necessary data to make up the website.
$ rake db:seed
We add a ruby gem to our projects, which allows us to run a simple task and based on some “initial” data we deploy the entire website with it’s contents in a few seconds.