Tutorial: Publish a Gatsby site to Azure Static Web Apps Preview
This article demonstrates how to create and deploy a Gatsby web application to Azure Static Web Apps. The final result is a new Static Web Apps site (with the associated GitHub Actions) that give you control over how the app is built and published.
In this tutorial, you learn how to:
- Create a Gatsby app
- Setup an Azure Static Web Apps site
- Deploy the Gatsby app to Azure
- An Azure account with an active subscription. If you don't have one, you can create an account for free.
- A GitHub account. If you don't have one, you can create an account for free.
- Node.js installed.
Create a Gatsby App
Create a Gatsby app using the Gatsby Command Line Interface (CLI):
Open a terminal
Use the npx tool to create a new app with the Gatsby CLI. This may take a few minutes.
npx gatsby new static-web-app
Navigate to the newly created app
Initialize a git repo
git init git add -A git commit -m "initial commit"
Push your application to GitHub
You need to have a repository on GitHub to create a new Azure Static Web Apps resource.
Create a blank GitHub repository (don't create a README) from https://github.com/new named gatsby-static-web-app.
Next, add the GitHub repository you just created as a remote to your local repo. Make sure to add your GitHub username in place of the
<YOUR_USER_NAME>placeholder in the following command.
git remote add origin https://github.com/<YOUR_USER_NAME>/gatsby-static-web-app
Push your local repository up to GitHub.
git push --set-upstream origin master
Deploy your web app
The following steps show you how to create a new static site app and deploy it to a production environment.
Create the application
Navigate to the Azure portal
Click Create a Resource
Search for Static Web Apps
Click Static Web Apps (Preview)
For Subscription, accept the subscription that is listed or select a new one from the drop-down list.
In Resource group, select New. In New resource group name, enter gatsby-static-web-app and select OK.
Next, provide a globally unique name for your app in the Name box. Valid characters include
-. This value is used as the URL prefix for your Static Web App in the format of
For Region, select an available region close to you.
For SKU, select Free.
Click the Sign in with GitHub button.
Select the Organization under which you created the repository.
Select the gatsby-static-web-app as the Repository .
For the Branch select master.
Next, add configuration settings that the build process uses to build your app.
Click the Next: Build > button to edit the build configuration
To configure the settings of the step in GitHub Actions, set the App location to /.
Set App artifact location to public.
A value for API location isn't necessary as you aren't deploying an API at the moment.
Review and create
Click the Review + Create button to verify the details are all correct.
Click Create to start the creation of the App Service Static Web App and provision a GitHub Action for deployment.
Once the deployment completes click, Go to resource.
On the resource screen, click the URL link to open your deployed application. You may need to wait a minute or two for the GitHub Action to complete.
Clean up resources
If you're not going to continue to use this application, you can delete the Azure Static Web App resource through the following steps:
- Open the Azure portal
- In the top search bar, search for your application by the name you provided earlier
- Click on the app
- Click on the Delete button
- Click Yes to confirm the delete action