- Create SSH Key with Read/Write Access for site: ssh-keygen -t rsa -b 4096 -C "deploy@{domain}"
- Choose Location: Add SSH Key to Projects
lib
folder.
- Create Repository
- Copy generated SSH Key from the
lib/id_rsa.pub
key to site/settings/deploy, name itCircleCI Deploy Key
. Allow write access. - Clone repository locally.
- Install Jekyll & Bundler Gems ~
gem install jekyll bundler
- Project Root ~ run
jekyll new .
- Read here on usage of Jekyll - https://jekyllrb.com/docs/quickstart/.
- Add the
jekyll-contentful-data-import
Gem to Project Gemfile Plugins. https://github.com/contentful/jekyll-contentful-data-import
# If you have any plugins, put them here!
group :jekyll_plugins do
gem "jekyll-feed", "~> 0.6"
gem "jekyll-contentful-data-import" # <~ This Gem, remove comment.
end
bundle install
- Adds the
jekyll contentful
to fetch entries for the configured spaces and content types(Which we'll setup later, we'll need to configure the _config.yml file after a few steps).
- Add Project
- Select Project Repository
- Settings: OS - Linux, Language - Ruby
- Create circle.yml file in site root. Populate circle.yml with:
machine:
ruby:
version: 2.3.1
dependencies:
pre:
- gem install bundler
checkout:
post:
- bundle install
- bash lib/automated_build.sh
- Build ~ This generates a generic Read Only Deployment Key to the Projects Github Repo, you may remove because we'll need to use the key that has Read/Write Access to the Projects Repository. Projects -> Settings -> Permissions -> Checkout SSH Key.
- Copy generated SSH Key from the
lib/id_rsa
key to the Projects -> Settings -> Permissions -> SSH Permission, add Hostnamegithub.com
- Create API Token for the Contentful API Webhook, this will be fired when a User Publishes/Unpubishes Entries.
User Settings -> Personal API Token
, nameContentful CMS
. - Create
automated_build.sh
to your lib folder, populate with:
# Copy static site
CWD=`pwd`
# Clone Pages repository
cd /tmp
git clone git@github.com:jasoncomes/contentful-cms.git build
# cd build && git checkout -b YOUR_BRANCH origin/YOUR_BRANCH # If not using master
# Trigger Jekyll rebuild
cd $CWD
bundle exec jekyll contentful
# Jekyll Build ~ Handled through Netlify
# bundle exec jekyll build
# Push newly built repository
cp -r $CWD/_build/* /tmp/build # or $CWD/_build
cd /tmp/build
git config --global user.email "jasonwcomes@gmail.com"
git config --global user.name "Jason Comes"
git add .
git commit -m "Publish/Unpublish of Entry - Automated Rebuild"
git push -f origin master
- Create a new Space(code word for Site).
- Create
Space Settings -> API Keys -> Content Delivery Token
. Trigger this Webook for only Entry: Publish, Unpublish. Everything else, blank on page. Plase below snippet in your Projects_config.yml
file.
# Contentful CMS
contentful:
spaces:
- site:
space: xpv3b4sqgroo # Site Space ID
access_token: e0e7c0049bc4662c6bbd72bc09bb896e050201079b04a15c1ca3c64a9f51b451 # Site Space Access Token
This is the bare bones of it, if you need more customization please refer to this - https://github.com/contentful/jekyll-contentful-data-import#configuration
- Create
Space Settings -> Webhook
. Settings: Name - CircleCI, URL - `https://circleci.com/api/v1/project/HigherEducation/PROJECT_NAME/tree/master?circle-token=CIRCLECI_API_TOKEN - Start with Content Model, this is equal to Custom Post Type Setup. Will give you the ability to add Fields to Content Model Types.
- Sites Github Repository(Master branch) ~ Connect/Authorize with Github, this adds a read only deploy key to site/settings/deploy keys.
- Netlify triggers on commit to Master
- Runs Jekyll Build
- Deploy site