|
1 | 1 | ---
|
2 |
| -title: "Tutorial: Publish a Hugo site to App Service Static Apps" |
3 |
| -description: #Required; article description that is displayed in search results. |
4 |
| -services: #Required for articles that deal with a service; service slug assigned to your service by ACOM. |
| 2 | +title: "Tutorial: Publish a Hugo site to Azure Static Web Apps" |
| 3 | +description: Learn how to deploy a Hugo application to Azure Static Web Apps. |
| 4 | +services: static-web-apps |
5 | 5 | author: aaronpowell
|
6 |
| -ms.service: azure-functions |
7 |
| -ms.topic: tutorial |
| 6 | +ms.service: static-web-apps |
| 7 | +ms.topic: tutorial |
8 | 8 | ms.date: 05/08/2020
|
9 | 9 | ms.author: aapowell
|
10 | 10 | ---
|
11 | 11 |
|
12 |
| -<!-- |
13 |
| -Refer to the following guide for more details: |
14 |
| - https://review.docs.microsoft.com/en-us/help/contribute/contribute-how-to-mvc-tutorial?branch=master |
15 |
| ---> |
| 12 | +# Tutorial: Publish a Hugo site to Azure Static Web Apps |
16 | 13 |
|
17 |
| -<!---Recommended: Removal all the comments in this template before you sign-off or merge to master.---> |
| 14 | +This article demonstrates how to create and deploy a [Hugo](https://gohugo.io/) web application to [Azure Azure Static Web Apps](overview.md). The final result is a new Azure Static Web Apps with the associated GitHub Actions that give you control over how the app is built and published. |
18 | 15 |
|
19 |
| -# Tutorial: Publish a Hugo site to App Service Static Apps |
| 16 | +In this tutorial, you learn how to: |
20 | 17 |
|
21 |
| -<!---Required: |
22 |
| -Starts with "Tutorial: " |
23 |
| -Make the first word following "Tutorial:" a verb. |
24 |
| ----> |
| 18 | +> [!div class="checklist"] |
| 19 | +> |
| 20 | +> - Create a Hugo app |
| 21 | +> - Setup an Azure Static Web Apps |
| 22 | +> - Deploy the Hugo app to Azure |
25 | 23 |
|
26 |
| -Introductory paragraph. |
| 24 | +[!INCLUDE [quickstarts-free-trial-note](../../includes/quickstarts-free-trial-note.md)] |
27 | 25 |
|
28 |
| -<!---Required: |
29 |
| -Lead with a light intro that describes, in customer-friendly language, |
30 |
| -what the customer will learn, or do, or accomplish. Answer the |
31 |
| -fundamental "why would I want to do this?" question. |
32 |
| ----> |
| 26 | +## Prerequisites |
33 | 27 |
|
34 |
| -In this tutorial, you learn how to: |
| 28 | +- An Azure account with an active subscription. If you don't have one, you can [create an account for free](https://azure.microsoft.com/free/). |
| 29 | +- A GitHub account. If you don't have one, you can [create an account for free](https://github.com/join). |
35 | 30 |
|
36 |
| -> [!div class="checklist"] |
37 |
| -> * All tutorials include a list summarizing the steps to completion |
38 |
| -> * Each of these bullet points align to a key H2 |
39 |
| -> * Use these green checkboxes in a tutorial |
40 |
| -<!---Required: |
41 |
| -The outline of the tutorial should be included in the beginning and at |
42 |
| -the end of every tutorial. These will align to the **procedural** H2 |
43 |
| -headings for the activity. You do not need to include all H2 headings. |
44 |
| -Leave out the prerequisites, clean-up resources and next steps---> |
45 |
| - |
46 |
| -If you don't have a <service> subscription, create a free trial account... |
47 |
| -<!--- Required, if a free trial account exists |
48 |
| -Because tutorials are intended to help new customers use the product or |
49 |
| -service to complete a top task, include a link to a free trial before the |
50 |
| -first H2, if one exists. You can find listed examples in |
51 |
| -[Write tutorials](contribute-how-to-mvc-tutorial.md) |
52 |
| ----> |
53 |
| - |
54 |
| -<!---Avoid notes, tips, and important boxes. Readers tend to skip over |
55 |
| -them. Better to put that info directly into the article text.---> |
| 31 | +## Create a Hugo App |
56 | 32 |
|
57 |
| -## Prerequisites |
| 33 | +Create a Hugo app using the Hugo Command Line Interface (CLI): |
58 | 34 |
|
59 |
| -- First prerequisite |
60 |
| -- Second prerequisite |
61 |
| -- Third prerequisite |
62 |
| -<!---If you need them, make Prerequisites your first H2 in a tutorial. If |
63 |
| -there's something a customer needs to take care of before they start (for |
64 |
| -example, creating a VM) it's OK to link to that content before they |
65 |
| -begin.---> |
66 |
| - |
67 |
| -## Sign in to <service/product/tool name> |
68 |
| - |
69 |
| -Sign in to the <service> portal. |
70 |
| -<!---If you need to sign in to the portal to do the tutorial, this H2 and |
71 |
| -link are required.---> |
72 |
| - |
73 |
| -## Procedure 1 |
74 |
| - |
75 |
| -<!---Required: |
76 |
| -Tutorials are prescriptive and guide the customer through an end-to-end |
77 |
| -procedure. Make sure to use specific naming for setting up accounts and |
78 |
| -configuring technology. |
79 |
| -Don't link off to other content - include whatever the customer needs to |
80 |
| -complete the scenario in the article. For example, if the customer needs |
81 |
| -to set permissions, include the permissions they need to set, and the |
82 |
| -specific settings in the tutorial procedure. Don't send the customer to |
83 |
| -another article to read about it. |
84 |
| -In a break from tradition, do not link to reference topics in the |
85 |
| -procedural part of the tutorial when using cmdlets or code. Provide customers what they need to know in the tutorial to successfully complete |
86 |
| -the tutorial. |
87 |
| -For portal-based procedures, minimize bullets and numbering. |
88 |
| -For the CLI or PowerShell based procedures, don't use bullets or |
89 |
| -numbering. |
90 |
| ----> |
91 |
| - |
92 |
| -Include a sentence or two to explain only what is needed to complete the |
93 |
| -procedure. |
94 |
| - |
95 |
| -1. Step 1 of the procedure |
96 |
| -1. Step 2 of the procedure |
97 |
| -1. Step 3 of the procedure |
98 |
| - |
99 |
| - <!---Use screenshots but be judicious to maintain a reasonable length. |
100 |
| - Make sure screenshots align to the |
101 |
| - [current standards](https://review.docs.microsoft.com/help/contribute/contribute-how-to-create-screenshot?branch=master). |
102 |
| - If users access your product/service via a web browser the first |
103 |
| - screenshot should always include the full browser window in Chrome or |
104 |
| - Safari. This is to show users that the portal is browser-based - OS |
105 |
| - and browser agnostic.---> |
106 |
| -1. Step 4 of the procedure |
107 |
| - |
108 |
| -## Procedure 2 |
109 |
| - |
110 |
| -Include a sentence or two to explain only what is needed to complete the procedure. |
111 |
| - |
112 |
| -1. Step 1 of the procedure |
113 |
| -1. Step 2 of the procedure |
114 |
| -1. Step 3 of the procedure |
115 |
| - |
116 |
| -## Procedure 3 |
117 |
| - |
118 |
| -Include a sentence or two to explain only what is needed to complete the |
119 |
| -procedure. |
120 |
| -<!---Code requires specific formatting. Here are a few useful examples of |
121 |
| -commonly used code blocks. Make sure to use the interactive functionality |
122 |
| -where possible. |
123 |
| -
|
124 |
| -For the CLI or PowerShell based procedures, don't use bullets or |
125 |
| -numbering. |
126 |
| ----> |
127 |
| - |
128 |
| -Here is an example of a code block for Java: |
129 |
| - |
130 |
| -```java |
131 |
| -cluster = Cluster.build(new File("src/remote.yaml")).create(); |
132 |
| -... |
133 |
| -client = cluster.connect(); |
134 |
| -``` |
135 |
| - |
136 |
| -or a code block for Azure CLI: |
137 |
| - |
138 |
| -```azurecli-interactive |
139 |
| -az vm create --resource-group myResourceGroup --name myVM --image win2016datacenter --admin-username azureuser --admin-password myPassword12 |
140 |
| -``` |
141 |
| - |
142 |
| -or a code block for Azure PowerShell: |
143 |
| - |
144 |
| -```azurepowershell-interactive |
145 |
| -New-AzureRmContainerGroup -ResourceGroupName myResourceGroup -Name mycontainer -Image microsoft/iis:nanoserver -OsType Windows -IpAddressType Public |
146 |
| -``` |
| 35 | +1. Follow the [installation guide](https://gohugo.io/getting-started/installing/) for Hugo on your OS. |
147 | 36 |
|
| 37 | +1. Open a terminal |
148 | 38 |
|
149 |
| -## Clean up resources |
| 39 | +1. Run the Hugo CLI to create a new app. |
150 | 40 |
|
151 |
| -If you're not going to continue to use this application, delete |
152 |
| -<resources> with the following steps: |
| 41 | + ```bash |
| 42 | + hugo new site static-app |
| 43 | + ``` |
153 | 44 |
|
154 |
| -1. From the left-hand menu... |
155 |
| -2. ...click Delete, type...and then click Delete |
| 45 | +1. Navigate to the newly created app. |
156 | 46 |
|
157 |
| -<!---Required: |
158 |
| -To avoid any costs associated with following the tutorial procedure, a |
159 |
| -Clean up resources (H2) should come just before Next steps (H2) |
160 |
| ----> |
| 47 | + ```bash |
| 48 | + cd static-app |
| 49 | + ``` |
161 | 50 |
|
162 |
| -## Next steps |
| 51 | +1. Initialize a git repo. |
| 52 | + |
| 53 | + ```bash |
| 54 | + git init |
| 55 | + ``` |
| 56 | + |
| 57 | +1. Next, add a theme to the site by installing a theme as a git submodule and then specifying it in the Hugo config file. |
| 58 | + |
| 59 | + ```bash |
| 60 | + git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke |
| 61 | + echo 'theme = "ananke"' >> config.toml |
| 62 | + ``` |
| 63 | + |
| 64 | +1. Commit the changes. |
| 65 | + |
| 66 | + ```bash |
| 67 | + git add -A |
| 68 | + git commit -m "initial commit" |
| 69 | + ``` |
| 70 | + |
| 71 | +## Push your application to GitHub |
| 72 | + |
| 73 | +You need a repository on GitHub to connect to Azure Static Web Apps. The following steps show you how to create a repository for your site. |
| 74 | + |
| 75 | +1. Create a blank GitHub repo (don't create a README) from [https://github.com/new](https://github.com/new) named **hugo-static-app**. |
| 76 | + |
| 77 | +1. Add the GitHub repository 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. |
| 78 | + |
| 79 | + ```bash |
| 80 | + git remote add origin https://github.com/<YOUR_USER_NAME>/hugo-static-app |
| 81 | + ``` |
| 82 | + |
| 83 | +1. Push your local repo up to GitHub. |
| 84 | + |
| 85 | + ```bash |
| 86 | + git push --set-upstream origin master |
| 87 | + ``` |
| 88 | + |
| 89 | +## Deploy your web app |
| 90 | + |
| 91 | +The following steps show you how to create a new static site app and deploy it to a production environment. |
| 92 | + |
| 93 | +### Create the application |
| 94 | + |
| 95 | +1. Navigate to the [Azure portal](https://portal.azure.com). |
| 96 | + |
| 97 | +1. Select **Create a Resource** and search for **Static App**. |
| 98 | + |
| 99 | + :::image type="content" source="./media/static-web-apps-publish-hugo/create-in-portal.png" alt-text="Create a Static Apps (Preview) in the portal"::: |
| 100 | + |
| 101 | +1. For **Subscription**, accept the subscription that is listed or select a new one from the drop-down list. |
| 102 | + |
| 103 | +1. In _Resource group_, select **New**. In _New resource group name_, enter **hugo-static-app** and select **OK**. |
| 104 | + |
| 105 | +1. Next, provide a globally unique name for your app in the **Name** box. Valid characters include `a-z`, `A-Z`, `0-9` and `-`. This value is used as the URL prefix for your static app in the format of `https://<APP_NAME>....`. |
| 106 | + |
| 107 | +1. For _Region_, select an available region close to you. |
| 108 | + |
| 109 | +1. For _SKU_, select **Free**. |
| 110 | + |
| 111 | + :::image type="content" source="./media/static-web-apps-publish-hugo/basic-app-details.png" alt-text="Details filled out"::: |
163 | 112 |
|
164 |
| -<!-- Uncomment this block and add the appropriate link |
| 113 | +1. Click the **Sign in with GitHub** button. |
| 114 | + |
| 115 | +1. Select the **Organization** under which you created the repo. |
| 116 | + |
| 117 | +1. Select the **hugo-static-app** as the _Repository_ . |
| 118 | + |
| 119 | +1. For the _Branch_ select **master**. |
| 120 | + |
| 121 | + :::image type="content" source="./media/static-web-apps-publish-hugo/completed-github-info.png" alt-text="Completed GitHub information"::: |
| 122 | + |
| 123 | +### Build |
| 124 | + |
| 125 | +Next, you add configuration settings that the build process uses to build your app. The following settings configure the GitHub Action workflow file. |
| 126 | + |
| 127 | +1. Click the **Next: Build >** button to edit the build configuration |
| 128 | + |
| 129 | +1. Set _App location_ to **/**. |
| 130 | + |
| 131 | +1. Set _App artifact location_ to **public**. |
| 132 | + |
| 133 | + A value for _API location_ isn't necessary as you aren't deploying an API at the moment. |
| 134 | + |
| 135 | + :::image type="content" source="./media/static-web-apps-publish-hugo/build-details.png" alt-text="Build Settings"::: |
| 136 | + |
| 137 | +### Review and create |
| 138 | + |
| 139 | +1. Click the **Review + Create** button to verify the details are all correct. |
| 140 | + |
| 141 | +1. Click **Create** to start the creation of the Azure Static Web Apps and provision a GitHub Action for deployment. |
| 142 | + |
| 143 | +1. Once the deployment completes, navigate to your terminal and pull the commit with the GitHub Action to your machine. |
| 144 | + |
| 145 | + ```bash |
| 146 | + git pull |
| 147 | + ``` |
| 148 | + |
| 149 | +1. Open the Hugo app in a text editor and open the _.github/workflows/azure-pages-<WORKFLOW_NAME>.yml_ file. |
| 150 | + |
| 151 | +1. Replace the line `- uses: actions/checkout@v1` (line 18) with the following, to build the Hugo application. |
| 152 | + |
| 153 | + ```yml |
| 154 | + - uses: actions/checkout@v2 |
| 155 | + with: |
| 156 | + submodules: true |
| 157 | + |
| 158 | + - name: Setup Hugo |
| 159 | + |
| 160 | + with: |
| 161 | + hugo-version: "latest" |
| 162 | + |
| 163 | + - name: Build |
| 164 | + run: hugo |
| 165 | + ``` |
| 166 | +
|
| 167 | +1. Commit the updated workflow and push to GitHub. |
| 168 | +
|
| 169 | + ```bash |
| 170 | + git add -A |
| 171 | + git commit -m "Updating GitHub Actions workflow" |
| 172 | + git push |
| 173 | + ``` |
| 174 | + |
| 175 | +1. Wait for the GitHub Action to complete. |
| 176 | + |
| 177 | +1. In the Azure portal's _Overview_ window of newly created Azure Static Web Apps resource, click the _URL_ link to open your deployed application. |
| 178 | + |
| 179 | + :::image type="content" source="./media/static-web-apps-publish-hugo/deployed-app.png" alt-text="Deployed application"::: |
| 180 | + |
| 181 | +## Clean up resources |
| 182 | + |
| 183 | +[!INCLUDE [static-web-apps-cleanup-resource](../../includes/static-web-apps-cleanup-resource.md)] |
| 184 | + |
| 185 | +## Next steps |
165 | 186 |
|
166 | 187 | > [!div class="nextstepaction"]
|
167 |
| -> [Next steps button](contribute-get-started-mvc.md) |
168 |
| -
|
169 |
| ---> |
170 |
| - |
171 |
| -<!--- Required: |
172 |
| -Tutorials should always have a Next steps H2 that points to the next |
173 |
| -logical tutorial in a series, or, if there are no other tutorials, to |
174 |
| -some other cool thing the customer can do. A single link in the blue box |
175 |
| -format should direct the customer to the next article - and you can |
176 |
| -shorten the title in the boxes if the original one doesn't fit. |
177 |
| -Do not use a "More info section" or a "Resources section" or a "See also |
178 |
| -section". ---> |
| 188 | +> [Add a custom domain](custom-domain.md) |
0 commit comments