Skip to main content

Publish a Static Web App on Azure

I had to create a small personal website. As a big fan of the Jamstack, I like to use a static website generator like next.js, gatsby or hugo. Before  I typically deployed this generated website on Azure Blob storage as a really cheap way to host a static website. But with the introduction of Azure Static Web Apps, it is time to give them a try…

Create a Gatsby static website

There is a large list of available website generators, but as I like GraphQL a lot, I decided to use Gatsby.

First install the gatsby cli:

npm install -g gatsby-cli

Now you can  create a new website on your local machine using one of the available themes:

npx gatsby new example-app https://github.com/LekoArts/gatsby-starter-portfolio-cara

Store the website on Github

We need to store the code of our static website somewhere. This could be a Git repo on Azure DevOps, Github or any other Git enabled repository.

We’ll use Github in this example.

Create a new Github repository at https://github.com/new. Choose a repository name but don’t create a README.md or .gitignore file.

Open a command prompt and go to the website folder on your local machine ( example-app in my example).

Add the newly created Github repo as a remote origin:

git remote add origin https://github.com//example-app

Let's push our code to the Github repo

git branch -M main
git push --set-upstream origin main

Create an Azure Static Web App

Almost there! We have finally arrived at the Azure part.

Go to the Azure portal at https://portal.azure.com. Click on ‘Create a resource’ at the top.

In the search field enter ‘Static Web App’ and hit <enter>. You’ll arrive at the following screen:

Click Create. Now you arrive at the creation screen where you have to enter a lot of details. Select a subscription and resource group and enter a name for your static web app. We choose the free tier and a region close to us.

As a last step we choose Github as our source. Now we need to authenticate with Github. Therefore click on Signin with Github to login with our Github credentials. 

Click on Authorize Azure-App-Service-Static-Web-Apps to grant the necessary permissions to Azure to manipulate our Github repo.

Now we need the Github repository and branch that should be used.

As a last step we can select the Gatsby presets from the Build Presets menu. This will create a default Github Actions workflow for us.

Now click on Review+Create and Create to create our Azure Static Web App.

If you browse to the generated website, you will probably see something like this:

This is because Github Actions still need to deploy and generate the static web app.

Once the Github Actions workflow completes, our Gatsby site is there in all it’s glory:

More information: https://docs.microsoft.com/en-us/azure/static-web-apps/

Popular posts from this blog

Azure DevOps/ GitHub emoji

I’m really bad at remembering emoji’s. So here is cheat sheet with all emoji’s that can be used in tools that support the github emoji markdown markup: All credits go to rcaviers who created this list.

Kubernetes–Limit your environmental impact

Reducing the carbon footprint and CO2 emission of our (cloud) workloads, is a responsibility of all of us. If you are running a Kubernetes cluster, have a look at Kube-Green . kube-green is a simple Kubernetes operator that automatically shuts down (some of) your pods when you don't need them. A single pod produces about 11 Kg CO2eq per year( here the calculation). Reason enough to give it a try! Installing kube-green in your cluster The easiest way to install the operator in your cluster is through kubectl. We first need to install a cert-manager: kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.5/cert-manager.yaml Remark: Wait a minute before you continue as it can take some time before the cert-manager is up & running inside your cluster. Now we can install the kube-green operator: kubectl apply -f https://github.com/kube-green/kube-green/releases/latest/download/kube-green.yaml Now in the namespace where we want t

DevToys–A swiss army knife for developers

As a developer there are a lot of small tasks you need to do as part of your coding, debugging and testing activities.  DevToys is an offline windows app that tries to help you with these tasks. Instead of using different websites you get a fully offline experience offering help for a large list of tasks. Many tools are available. Here is the current list: Converters JSON <> YAML Timestamp Number Base Cron Parser Encoders / Decoders HTML URL Base64 Text & Image GZip JWT Decoder Formatters JSON SQL XML Generators Hash (MD5, SHA1, SHA256, SHA512) UUID 1 and 4 Lorem Ipsum Checksum Text Escape / Unescape Inspector & Case Converter Regex Tester Text Comparer XML Validator Markdown Preview Graphic Color B