Netlify + Gatsby + Cosmic + Automatic builds with Webhooks

Community Articles
Community Articles Netlify + Gatsby + Cosmic + Automatic builds with Webhooks

Gatsby is the new hotness for static sites, and Netlify is an amazing service that helps you deploy static sites with some brilliant automation capabilities.  Combine these with the new Cosmic source plugin for Gatsby and you have a technology stack that scales well and is highly performant.

In this tutorial, I'll show you how to deploy your Gatsby Blog to Netlify and trigger automatic builds on content edits using Cosmic Webhooks.


Install the App

Check out the Gatsby Blog available on Cosmic.  Install the app:
1. Create a new Bucket
2. Choose the option to start with an App
3. Install the Gatsby Blog


Deploy to Netlify

After you install the Gatsby Blog app, install the Deploy to Web Extension.

Find the Netlify option and add the Gatsby Blog GitHub URL:
https://github.com/cosmicjs/gatsby-blog-cosmicjs


Set Environment Variables

In Netlify, go to Your Netlify Site > Settings > Build and Deploy > Build environment variables.  Set a COSMIC_BUCKET environment variable to your Cosmic Bucket slug.  Add your COSMIC_READ_KEY  (Optional) if you've set this in Your Cosmic Bucket > Settings.


Do It Live!

Your site should now be live and look like this:


Set Up Hooks

Now let's make sure to tell Netlify to rebuild our site whenever content is edited in Cosmic.  To do this, first go into Netlify's deploy settings area located in Your Netlify Site > Settings > Build and Deploy > Build Hooks and add a Build Hook:

Save, then copy and paste the generated build hook URL into your Cosmic Bucket > Webhooks

This will trigger a rebuild whenever content is created, edited or deleted in Cosmic.


Now Edit Content!

Now you'll notice whenever you add / edit / remove content in your Cosmic Bucket, a magic message is sent to Netlify to tell it to rebuild your awesome Gatsby site!

In Conclusion

With Gatsby, Netlify and Cosmic, building fast, scalable and highly performant websites has never been easier. With webhooks and Netlify's built-in continuous deployment, you can enjoy an amazing automated developer experience.

Let me know if you have any questions!  Reach out to me on Twitter and message me on Slack.

You may also like


This is a JAMstack app with the power of Cosmic. In JAmstack, Vue.js is used as Javascript part, Cosmic as API and Nuxt.js as Markup.
Our digital world is being built on top of API services. And Webhooks are the operators that enable these API services to communicate with each other.
In this tutorial, we're going to build a digital shrine to the great musical artists of our time and to listening to music by album - the way great artists meant it to be listened to! In the process, you'll learn a little bit about Cosmic, React, CSS Grid, Flexbox, Material UI and Spotify's aweso
Thank you to everyone who joined us for our Halloween edition of our Wednesday Webinar series. In this presentation, we discussed making localization for websites less spooky using Gatsby and Cosmic.
A website boilerplate satisfies some common website requirements including dynamic pages, blog articles, author management, SEO ability, contact form and website search.
Cosmic makes it easy to manage content for your Vue.js applications. In this blog we'll quickstart a Vue.js RPG Adventure Game using the Cosmic CLI. Our game, "Enter The Cosmos", is a turn-based, RPG style game built using Vue.js, Node.js and Cosmic.

Get Started with Cosmic

Build personal projects for free. Add your team at unbeatable prices.
Start Building Talk to Sales