WARNING: This repo is not production ready and not ready for general consumption. It's provided as is and there's no guarantee of maintenance
The setup scripts have not been thoroughly tested and should be used with caution
The following are the instructions for using this repo, for contributing see CONTRIBUTING.md.
This project aims to plug the gap in Contentful's out of the box offering, that being:
- CMS as code: Contentful provides all the tools needed in SDKs and CLIs to support CMS as code but none of it "just works". This project pulls those pieces together.
- Content promotions between environments: This just doesn't really work out of the box.
To achieve this, we use a web based front end since it's easier than scripts.
(This only needs doing once, if you're reading this from an active project, skip to "Setup the web portal").
- Create all the environments you need. Remember you always need one environment slot free for migrations.
- Install the merge app in all your environments https://www.contentful.com/developers/docs/tutorials/general/merge-app/ (you won't use the UI for it, but the script won't run without it)
- Create a CMA (Content Management aka Access) Token
- Create a CDA token (Content delivery token)
- Your CDA token needs access to all environments (so have a separate one to the one you use for prod)
- Create a new repo to manage your Contentful environment
- Clone this repo as a submodule i.e
git submodule add git@github.com:Apadmi-Engineering/contentful-tools.git - Run the setup script from the root of your new repo:
./contentful-tools/scripts/setup.sh - Fill in the environment variable templates created (.env and .env.local)
- Enable bitbucket pipelines and add your CMA token as a secret with the key CMA_TOKEN.
- Create branches for each of your environments of the form
contentful-environment/<env>. This will be how you track the migrations applied to environments.
Commit and push your changes lowest environment branch up. This should trigger the first migration (created for you) in bitbucket pipelines to set up the tracking.
- Navigate to the submodule
cd contentful-tools; - Run
yarn install. (Installyarnfirst if you need to https://yarnpkg.com/getting-started/install) - Run
yarn devand follow the instructions to launch the Webview. - If everything is set up correctly you should see your Contentful details in the top right.
This project adopts a CMS as code approach for our content model development. This method offers several advantages:
Version Control: Treating CMS configuration as code allows us to use git for tracking changes, collaborating, and easily rolling back to previous versions. This ensures our CMS configuration remains consistent and manageable over time.
Reproducibility: CMS as Code enables us to replicate the CMS configuration across different environments, eliminating discrepancies and maintaining consistency.
Automated Deployment: Integrating CMS configuration into the deployment pipeline automates the deployment process. Changes to the CMS configuration can be automatically deployed to the target environment, saving time and reducing human error.
Infrastructure as Code: CMS as Code aligns with the broader Infrastructure as Code (IaC) concept, where infrastructure components are defined and managed through code.
You should have a branch for each of your main environments in Contentful. So lets say we have the environments
- test
- pre-prod
- production
So to promote the content changes from test to preprod the process is:
- Merge
contentful-environment/testintocontentful-environment/pre-prod - This should trigger a bitbucket pipeline job to update
pre-prodwith all the scripts now in that branch.
See above to launch the web tool and follow the on screen instructions to create a migration. It will
- Create a git branch for your migration
- Create a Contentful environment
- Wait for you to make changes in your test environment
- Create a migration script on disk
- You can the commit and PR that change and merge it into the appropriate environment.
For Content promotions, select the relevant section in the web portal and follow the onscreen instructions.