Thanks to our first-class GitHub and GitLab Integrations, you can simply push your code to deploy with Vercel. But what if you wanted to create a deployment not based on change of source code, but another external event, such as an update in CMS content?
Starting today, you can deploy based on any event with Deploy Hooks.
An illustration of a Vercel Deploy Hook set on Contentful.
The Deploy Hook ensures a build and deployment each time content is updated.
In order to illustrate Deploy Hooks, we consider the popular pairing of a Gatsby-powered static site, backed by content on Contentful. Let's set it up so that the static site automatically builds and deploys each time content is updated.
1. Set up Boilerplate
Luckily for us, the Contentful community already has a Gatsby + Contentful boilerplate available.
gatsby new contentful-starter https://github.com/contentful-userland/gatsby-contentful-starter
The boilerplate is a beautiful and fast blog demo powered by Gatsby and Contentful.
2. Sign up for Contentful and Obtain Tokens
Once signed up, we run the setup script highlighted on Contentful's onboarding page.
npm run setup takes care of setting up the environment variables that Gatsby needs from Contentful.
We want our Gatsby site to re-build and deploy whenever there is an update in Contentful. Therefore, we create a Deploy Hook pointing to the git master branch, and specify the Deploy Hook as a webhook within Contentful.
It's easy to create a Deploy Hook for any Vercel project — the docs visually explain how.
Once the webhook is created, our setup is complete.