You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/static-web-apps/publish-bicep.md
+51-32Lines changed: 51 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,30 +12,25 @@ ms.author: cshoe
12
12
13
13
# Deploy Azure Static Web Apps with Bicep
14
14
15
-
Use a Bicep file to create your Azure Static Web app to Azure. Bicep is a domain-specific language (DSL) that uses declarative syntax to define and create Azure resources repeatedly in a consistent manner.
15
+
Use a Bicep file to create your Azure Static Web app to Azure. Bicep provides a declarative syntax to define and create Azure resources repeatedly in a consistent manner, which can be automated and repeated.
16
+
17
+
Your creation process should include all the resources in your application. This article details how to create the resource group that holds all the resources for your application, the Azure Static Web Apps resource, which contains your statically generated client application such as React, Vue, or Svelte, and the linked Azure Functions backend.
16
18
17
-
To deploy your static web app, you need to:
18
-
* Create resources with Bicep
19
-
* Deploy your source code. Use one of the following tools to deploy your app:
Bicep is one of several types of resource creation. These types include:
27
22
28
-
*[Azure Resource Management](/azure/azure-resource-manager/) (ARM): implement infrastructure as code for your Azure solutions, use Azure Resource Manager templates (ARM templates). The template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. This older style is still in use but generally updated to Bicep or Azure Verified Modules.
23
+
*[Azure Resource Management](/azure/azure-resource-manager/) (ARM): implement infrastructure as code for your Azure solutions, use Azure Resource Manager templates (ARM templates). The template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. This older style is still in use but updated to Bicep or Azure Verified Modules.
29
24
*[Bicep](/azure/azure-resource-manager/Bicep/): Bicep is a domain-specific language (DSL) that uses declarative syntax to deploy Azure resources. In a Bicep file, you define the infrastructure you want to deploy to Azure, and then use that file throughout the development lifecycle to repeatedly deploy your infrastructure. Your resources are deployed in a consistent manner.
30
25
*[Azure verified modules (AVM)](https://azure.github.io/Azure-Verified-Modules): These modules represent the only standard from Microsoft for Bicep modules in the [Bicep Public Registry](https://github.com/Azure/bicep-registry-modules/tree/main/avm). Use AVM when possible because it consolidates and set the standards for what a good Infrastructure-as-Code module looks like.
31
-
*[Azure CLI](/cli/azure/)/[PowerShell](/powershell): These command line apps allow you to create resources. They have generally been superceded by Bicep and AVM but are still used for minor or quick fixes while the larger Bicep update may be more time-consuming.
26
+
*[Azure CLI](/cli/azure/)/[PowerShell](/powershell): These command line apps allow you to create resources. They have generally been superseded by Bicep and AVM but are still used for minor or quick fixes while the larger Bicep update may be more time-consuming. Learn to [create resources with the Azure CLI and a Bicep file](/azure/azure-resource-manager/bicep/deploy-cli#deploy-local-bicep-file).
32
27
*[Azure portal](https://portal.azure.com/): Azure portal is a web-based visual interface for resource creation and configuration.
33
28
34
29
Creation and configuration can be done across all the tools listed above.
35
30
36
31
## Bicep by example
37
32
38
-
The Bicep examples in this article use [Azure Verified Modules (AVM)](https://azure.github.io/Azure-Verified-Modules/) when possible and [Bicep](/azure/azure-resource-manager/Bicep/) when AVM isn't available. You'll be able to recognize AVM because the referenced module includes `avm/res` such as `br/public:avm/res/web/static-site:0.3.0`.
33
+
The bicep examples in this article use [Azure Verified Modules (AVM)](https://azure.github.io/Azure-Verified-Modules/) when possible and [bicep](/azure/azure-resource-manager/bicep/) when AVM isn't available. AVM modules are recognizable because they reference modules that include `avm/res`, such as `br/public:avm/res/web/static-site:0.3.0`.
AVM allows you to adopt Bicep code, which has been built and is maintained by professional engineers fluent in Bicep. These modules aren't only supported and maintained, they're opinionated about what proper Bicep files look like.
48
+
AVM allows you to use managed Bicep code, which has been built and is maintained by professional engineers fluent in Bicep. These modules aren't only supported and maintained, they're opinionated about what proper Bicep files look like.
54
49
55
50
Due to the work involved in owning and maintaining the AVM files, it takes time to specify the module, determine best practices, and find the appropriate owner/maintainer. For this reason, the module you need may not be available at this time.
-Optional, [Visual Studio Code extension for Bicep](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-Bicep). This extension is used to immediately run your Bicep file, which creates your resources.
-[Visual Studio Code extension for Bicep](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-bicep): An optional extension that creates resources for you by running your Bicep file.
61
56
62
57
## Create a static web app resource
63
58
64
-
Create a `main.Bicep` file with the Bicep code below to:
59
+
Create a file named `main.bicep` file and paste in the following code:
65
60
66
-
* Create a unique string, `resourceToken`.
67
-
* Create tags for the resources. Tags are filterable in the Azure portal.
Save the values of the output variables. You'll need these to configure the resources.
95
+
This file creates the following resources for you:
96
+
* An application name as the `resourceToken` value
97
+
* Tags associated with your app to help you find and filter resources in the Azure portal
98
+
* A resource group for this application
99
+
* A static web app
110
100
111
-
## Create a static web app with a linked backend function app
101
+
Save the values of the output variables to a text editor. You'll need these to configure the resources. The next step is to include a linked backend Azure Functions app in the next section.
112
102
113
-
To create a static web app with a linked backend function app, you need to use a standard plan for your static web app and complete the following steps.
103
+
## Link a Functions app
114
104
115
-
*[Create the Azure Function app](/azure/azure-functions/functions-create-first-function-Bicep). You need the `resourceId` for the Function app, which looks like: `/subscriptions/<SUBSCRIPTION-ID>/resourcegroups/<RESOURCE-GROUP-NAME>/providers/Microsoft.Web/sites/<FUNCTION-APP-NAME>`.
116
-
* Create the static web app using the [Bicep in the previous section](#create-a-static-web-app-resource).
117
-
* Link the static web app to the function app.
105
+
To link a Functions app for your backend, use the Static Web Apps standard plan for your web app and complete the following steps.
118
106
119
-
Create a `config.Bicep` file to link the static web app to the function app.
107
+
To create the Azure Function app, follow the instructions provided in the Create the Azure Function app guide. You'll need the resourceId for the Function app, which looks like: /subscriptions/<SUBSCRIPTION-ID>/resourcegroups/<RESOURCE-GROUP-NAME>/providers/Microsoft.Web/sites/<FUNCTION-APP-NAME>.
108
+
109
+
Next, create the static web app using the Bicep template provided in the previous section. This sets up the necessary resources for your static web app. Finally, link the static web app to the function app to enable seamless integration between your front-end and back-end services.
110
+
111
+
Create a file named `config.bicep` file and paste in the following code:
* Creates variables to use in resource configuration.
152
+
* Create a reference to the existing static web app.
153
+
* Create a reference string for the existing functions app.
154
+
* Configure the static web app to link to the functions app.
155
+
157
156
## Deployment
158
157
159
-
After your resources are created, you can deploy your application to the hosting environment. The following descriptions show you how to work both locally and deploy though GitHub Actions:
158
+
Deploy your source code with one of the following tools to deploy your app:
***Local development environment**: Use [Azure Developer CLI](/azure/developer/azure-developer-cli) to deploy from your local machine. When running locally, you define your deployment in an `azure.yml` file. This file includes hooks that plug into the resource creation process at any point to help you during deployment, especially when different parts of your app need to know about each other at build time.
162
165
163
166
***Production environment**: The ability to deploy from a GitHub Actions workflow file is a built-in feature when you create your static web app. Once the file is in your repository, you can edit the file as needed. Deployment from [other source code providers](external-providers.md) is also supported.
164
167
165
168
To learn more from a full end-to-end application that includes resource creation and application deployment, see [Serverless AI Chat with RAG using LangChain.js](https://github.com/Azure-Samples/serverless-chat-langchainjs).
166
169
170
+
## Speeding up deployments with Azure Developer CLI
171
+
172
+
Azure Developer CLI (`azd`) uses Bicep files along with deployment configurations to create and provision your application. Since version 1.4, azd checks the Bicep against cloud resources to understand if the underlying infrastructure as code (IaC) state requires updates. If the state hasn't changed, creation and configuration is skipped. Learn more about this [performance improvement](
0 commit comments