Skip to main content

Infrastructure as Code

Learn what Infrastructure as Code means, and how you can use code to standardize and automate your Gatsby site.

What is Infrastructure as Code?

Infrastructure as Code, or IaC, is the practice of managing your development, testing, and production environments using configuration files or scripts. Provisioning and configuring environments individually can introduce errors or inconsistencies. You may, for example, find yourself running different versions of Node.js on your laptop and your production servers. Infrastructure as Code minimizes this kind of drift and lets you automate the process of provisioning environments.

Your configuration file describes what resources your project requires. If you’re building an API, for example, you might create a configuration file that says, “Please install Node.js 12.16.2, npm 6.14.4, Express 4.17.1, and PostgreSQL 12.2 for Ubuntu Linux.” For a Gatsby project, your configuration file may add plugins and themes.

Configuration files, like other code files, are text. That means you can use version control software to store them and track changes to the environment. In short, IaC:

  • Creates consistent environments.
  • Saves time that would otherwise be spent setting up environments.
  • Reduces the risk of errors caused by mismatched environments.
  • Lays the groundwork for automation.

Automating Gatsby site development with Gatsby Recipes

Gatsby Recipes applies the infrastructure as code concept to front-end development. With Gatsby Recipes, you can automate common site building tasks, such as adding a plugin or test suite.

To get started with Gatsby Recipes, upgrade to the latest version of Gatsby and the Gatsby CLI.

You can see the list of available recipes by using gatsby recipes. Use your up or down arrow keys to select a recipe, and press the Enter or Return key to run it.

partial list of available Gatsby recipes

Gatsby Recipes use MDX. They’re a readable mix of Markdown and React. MDX is an extension of Markdown that lets you use JSX in Markdown-formatted documents. As an example, check out the Styled Components recipe.

You can also write and run your own recipes, or run recipes that were created by and shared with the community. Pass the path or URL of the recipe as an argument. For example, to run a local Gatsby recipe, use gatsby recipes ./name-of-your-recipe.mdx. To run a remote recipe, use gatsby recipes

Gatsby Recipes help you save time and reduce configuration errors by automating the set up process.

Learn more

Edit this page on GitHub