DatoCMS is a headless CMS that content editors can use to edit and publish content. Gatsby Cloud allows you to integrate your site with DatoCMS in order to run performant builds and preview content changes made in the CMS before publishing.
First, you’ll need a Gatsby site with a
gatsby-source-datocms source plugin pulling data from DatoCMS. If you haven’t set that up yet, you can quickly create a new project by selecting one of the DatoCMS templates on the Gatsby Cloud get started page.
Sign in with GitHub. You’ll be asked to authorize the Gatsby Cloud app with your GitHub account. If you need to request access to one or more repositories, you can click “request access” here or later, when creating an instance.
Once signed in, configuring Gatsby Cloud with DatoCMS requires several steps that are walked through below.
Once you’ve authenticated with Cloud and GitHub, you can create an instance from the “Create a new Gatsby Cloud site” page.
Use the “I already have a Gatsby site” flow to manually integrate your site.
Pick your Gatsby site from the list of GitHub repositories. You can use the search input to narrow down the list.
If you don’t see your site, it might be because it belongs to a GitHub organization, rather than your personal account. You can connect a new GitHub Organization.
Note: Repositories must contain one Gatsby project configured at their root to be enabled. Gatsby Cloud works best with Gatsby version 2.19.25 and higher.
You’ll need to select a branch and then indicate the publish directory where the
gatsby-config.js lives. If you leave the field blank, it defaults to the root of the site.
Once the branch and base directory are correct, select “Next.”
If you have already configured an instance of DatoCMS or if you don’t see DatoCMS in the “Automatic Provisioning” list, skip to Manual Integration.
If you do see DatoCMS in the “Automatic Integrations” section, consider using the “Automatic Integration” flow and Gatsby Cloud will set-up your CMS for you!
Find DatoCMS in the automatic integrations section, press “Connect” and follow the set-up instructions to link DatoCMS with Gatsby Cloud.
As an example, consider the following screenshot using Contentful:
Once you’ve authorized DatoCMS and selected the appropriate organization, press “Create site” which will create your instance.
First, click “Skip this step” to configure DatoCMS manually.
Gatsby Cloud will automatically try and detect environment variables necessary in your
gatsby-config.js. However — consider adding any additional variables that automatic detection may have missed. See “Setting up Environment Variables” for more info.
Note that you will be able to add, delete, or update these later on in “Site Settings”.
Once you’ve added the necessary environment variables, you can press “Create site” which will create your instance in Gatsby Cloud!
After following the “Automatic Integration” or “Manual Integration” flow you now have an instance of Gatsby Cloud configured with environment variables and a provided Gatsby Preview instance you can share with your team. Woo-hoo!
An environment variable references a value that can affect how running processes will behave on a computer, for example in staging and production environments. You must save environment variables in Gatsby Cloud to authorize your instance to pull source data from Sanity.
You will need to add into Gatsby Cloud any environment variable required for your app to run, such as deployment or test environment configuration settings.
You will also need to add in the following Gatsby Cloud-specific environment variables:
You need a read-only access token from your DatoCMS project. In Gatsby Cloud, create an environment variable called
DATO_API_TOKEN and enter the value of a read-only API token you generate from your DatoCMS project (Settings > API Tokens > Read-only API Token). You can double check
gatsby-config.js and the plugin entry for
gatsby-source-datocms for the variable name in case it is different from
Click “Next” and wait for the first cloud instance to be generated. Now, when you change any copy or content in the CMS, Gatsby Cloud should be up to date with your changes.