Deploying your Gatsby Drupal Site to Netlify
Share with Others
In this episode, you will learn how to take your previously created Gatsby site with Drupal content and deploy it to Netlify. Netlify is a great hosting service that allows you to get started hosting your Gatsby site for free. It also provides automated build tools that will build a production version of your Gatsby site from a Git repository.
Start by going to your Gatsby site on the command line and committing all your changes to the Git repo. If you are using command line git, the following commands should get you where you need to be:
git add .
git commit -m “Create base site that pulls content from Drupal”
Now head on over to Github (you could also use Gitlab or Bitbucket), log in, and create a new repository. You will want to add this new repo as an origin for your local Git repository. Something like the following command (replace the Git repo URL with your correct URL).
git remote add origin firstname.lastname@example.org:smthomas/gatsby-tutorial.git
git push -u origin master
Now head over to Netlify.com and create an account if you don’t already have one. You will need to use your Github, Gitlab, or Bitbucket account so it can pull in your Git repository you just created.
Once you are logged in, click the New site from Git button.
Select your Git provider
Select the team and branch you want to deploy to Netlify. The basic build settings should be able to be left at the default. You can use the Advanced build settings section to create environment variables. An example of this would be to pass in the Drupal username and password that can be used to authenticate with your Drupal site (this would require changes to your gatsby-cofig.js file). Once you are ready, click the Deploy site button.
By default it will give your site an interesting and occasionally funny name. This name will be part of the domain name your site will be accessible at. Don’t worry, you can use your own custom domain if you want. It will take a few minutes for your site to build. This will depend on the size of your site.
Note: You will need to make sure your Drupal site is publicly available in order for your website to build. If you wanted to use a local copy of your Drupal site then using the Git deployment method will not work.
You can now follow the steps to set up a custom domain or click the created url to view your new live Gatsby site!