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/app-service/deploy-best-practices.md
+45-39Lines changed: 45 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,61 +3,61 @@ title: Deployment best practices
3
3
description: Learn about the key mechanisms of deploying to Azure App Service. Find language-specific recommendations and other caveats.
4
4
keywords: azure app service, web app, deploy, deployment, pipelines, build
5
5
ms.assetid: bb51e565-e462-4c60-929a-2ff90121f41d
6
-
ms.topic: article
7
-
ms.date: 07/31/2019
6
+
ms.topic: best-practice
7
+
ms.date: 01/17/2025
8
8
ms.custom: UpdateFrequency3
9
9
author: cephalin
10
10
ms.author: cephalin
11
-
#customer intent
11
+
#customer intent: As a build developer, I want to understand the components of deploying to Azure App Service to design the best build solution for the technologies we use in our project.
Every development team has unique requirements that can make implementing an efficient deployment pipeline difficult on any cloud service. This article introduces the three main components of deploying to Azure App Service: deployment sources, build pipelines, and deployment mechanisms. This article also covers some best practices and tips for specific language stacks.
18
+
Every development team has unique requirements that can make implementing an efficient deployment pipeline difficult on any cloud service. This article introduces the three main components of deploying to Azure App Service: *deployment sources*, *build pipelines*, and *deployment mechanisms*. This article also covers some best practices and tips for specific language stacks.
19
19
20
-
## Deployment Components
20
+
## Deployment components
21
21
22
22
This section describes the three main components for deploying to App Service.
23
23
24
-
### Deployment Source
24
+
### Deployment source
25
25
26
-
A deployment source is the location of your application code. For production apps, the deployment source is usually a repository hosted by version control software such as [GitHub, BitBucket, or Azure Repos](deploy-continuous-deployment.md). For development and test scenarios, the deployment source might be [a project on your local machine](deploy-local-git.md).
26
+
A *deployment source* is the location of your application code. For production apps, the deployment source is usually a repository hosted by version control software such as [GitHub, BitBucket, or Azure Repos](deploy-continuous-deployment.md). For development and test scenarios, the deployment source might be [a project on your local machine](deploy-local-git.md).
27
27
28
-
### Build Pipeline
28
+
### Build pipeline
29
29
30
-
After you decide on a deployment source, your next step is to choose a build pipeline. A build pipeline reads your source code from the deployment source and runs a series of steps to get the application in a runnable state. Steps can include as compiling code, minifying HTML and JavaScript, running tests, and packaging components. The specific commands executed by the build pipeline depend on your language stack. These operations can be executed on a build server such as Azure Pipelines, or executed locally.
30
+
After you decide on a deployment source, your next step is to choose a *build pipeline*. A build pipeline reads your source code from the deployment source and runs a series of steps to get the application in a runnable state. Steps can include as compiling code, minifying HTML and JavaScript, running tests, and packaging components. The specific commands run by the build pipeline depend on your language stack. You can run these operations on a build server, such as Azure Pipelines, or locally.
31
31
32
-
### Deployment Mechanism
32
+
### Deployment mechanism
33
33
34
-
The deployment mechanism is the action used to put your built application into the */home/site/wwwroot* directory of your web app. The */wwwroot* directory is a mounted storage location shared by all instances of your web app. When the deployment mechanism puts your application in this directory, your instances receive a notification to sync the new files. App Service supports the following deployment mechanisms:
34
+
The *deployment mechanism* is the action used to put your built application into the */home/site/wwwroot* directory of your web app. The */wwwroot* directory is a mounted storage location shared by all instances of your web app. When the deployment mechanism puts your application in this directory, your instances receive a notification to sync the new files. App Service supports the following deployment mechanisms:
35
35
36
-
- Kudu endpoints: [Kudu](https://github.com/projectkudu/kudu/wiki) is the open-source developer productivity tool that runs as a separate process in Windows App Service, and as a second container in Linux App Service. Kudu handles continuous deployments and provides HTTP endpoints for deployment, such as [zipdeploy/](deploy-zip.md).
36
+
- Kudu endpoints: [Kudu](https://github.com/projectkudu/kudu/wiki) is the open-source developer productivity tool that runs as a separate process in Windows App Service. It runs as a second container in Linux App Service. Kudu handles continuous deployments and provides HTTP endpoints for deployment, such as [zipdeploy/](deploy-zip.md).
37
37
- FTP and WebDeploy: Using your [site or user credentials](deploy-configure-credentials.md), you can upload files [via FTP](deploy-ftp.md) or WebDeploy. These mechanisms don't go through Kudu.
38
38
39
39
Deployment tools such as Azure Pipelines, Jenkins, and editor plugins use one of these deployment mechanisms.
40
40
41
41
## Use deployment slots
42
42
43
-
Whenever possible, use [deployment slots](deploy-staging-slots.md) when deploying a new production build. When using a Standard App Service Plan tier or better, you can deploy your app to a staging environment, validate your changes, and do smoke tests. When you're ready, you can swap your staging and production slots. The swap operation warms up the necessary worker instances to match your production scale, thus eliminating downtime.
43
+
Whenever possible, use [deployment slots](deploy-staging-slots.md) when you deploy a new production build. When using a Standard App Service Plan tier or better, you can deploy your app to a staging environment, validate your changes, and do smoke tests. When you're ready, swap your staging and production slots. The swap operation warms up the necessary worker instances to match your production scale, which eliminates downtime.
44
44
45
45
### Continuously deploy code
46
46
47
-
If your project has branches designated for testing, QA, and staging, then each of those branches should be continuously deployed to a staging slot. This approach is known as the [Gitflow design](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow). This design allows your stakeholders to easily assess and test the deployed branch.
47
+
If your project has branches designated for testing, QA, and staging, each of those branches should be continuously deployed to a staging slot. This approach is known as the [Gitflow design](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow). This design allows your stakeholders to easily assess and test the deployed branch.
48
48
49
-
Continuous deployment should never be enabled for your production slot. Instead, your production branch (often main) should be deployed onto a nonproduction slot. When you're ready to release the base branch, swap it into the production slot. Swapping into production—instead of deploying to production—prevents downtime and allows you to roll back the changes by swapping again.
49
+
Continuous deployment should never be enabled for your production slot. Instead, your production branch (often main) should be deployed onto a nonproduction slot. When you're ready to release the base branch, swap it into the production slot. Swapping into production, instead of deploying to production, prevents downtime and allows you to roll back the changes by swapping again.
50
50
51
-
:::image type="content" source="media/app-service-deploy-best-practices/slot_flow_code_diagam.png" alt-text="Diagram that shows the flow between the Dev, Staging, and Main branches and the slots they are deployed to.":::
51
+
:::image type="content" source="media/app-service-deploy-best-practices/slot_flow_code_diagam.png" alt-text="Diagram that shows the flow between the Dev, Staging, and Main branches and the slots they're deployed to.":::
52
52
53
53
### Continuously deploy containers
54
54
55
55
For custom containers from Docker or other container registries, deploy the image into a staging slot and swap into production to prevent downtime. The automation is more complex than code deployment because you must push the image to a container registry and update the image tag on the webapp.
56
56
57
57
For each branch you want to deploy to a slot, set up automation to do these tasks on each commit to the branch.
58
58
59
-
1.**Build and tag the image**. As part of the build pipeline, tag the image with the git commit ID, timestamp, or other identifiable information. It's best not to use the default *latest* tag. Otherwise, it's difficult to trace back what code is currently deployed, which makes debugging far more difficult.
60
-
1.**Push the tagged image**. Once the image is built and tagged, the pipeline pushes the image to our container registry. In the next step, the deployment slot will pull the tagged image from the container registry.
59
+
1.**Build and tag the image**. As part of the build pipeline, tag the image with the git commit ID, timestamp, or other identifiable information. It's best not to use the default *latest* tag. Otherwise, it's difficult to trace back what code is currently deployed, which makes debugging more difficult.
60
+
1.**Push the tagged image**. After the image is built and tagged, the pipeline pushes the image to the container registry. In the next step, the deployment slot pulls the tagged image from the container registry.
61
61
1.**Update the deployment slot with the new image tag**. When this property is updated, the site automatically restarts and pulls the new container image.
62
62
63
63
:::image type="content" source="media/app-service-deploy-best-practices/slot_flow_container_diagram.png" alt-text="Diagram shows slot usage visual representing Web App, Container Registry, and repository branches.":::
@@ -70,7 +70,7 @@ App Service has [built-in continuous delivery](deploy-continuous-deployment.md)
70
70
71
71
### Use GitHub Actions
72
72
73
-
You can also automate your container deployment [with GitHub Actions](https://github.com/Azure/webapps-deploy). The workflow file builds and tags the container with the commit ID, push it to a container registry, and update the specified web app with the new image tag.
73
+
You can also automate your container deployment [with GitHub Actions](https://github.com/Azure/webapps-deploy). The workflow file builds and tags the container with the commit ID, pushes it to a container registry, and updates the specified web app with the new image tag.
74
74
75
75
```yaml
76
76
on:
@@ -115,45 +115,51 @@ az ad sp create-for-rbac --name "myServicePrincipal" --role contributor \
115
115
--sdk-auth
116
116
```
117
117
118
-
In your script, sign in using `az login --service-principal`, providing the principal’s information. You can then use `az webapp config container set` to set the container name, tag, registry URL, and registry password. Here's a link for you to construct your container CI process.
118
+
In your script, sign in using `az login --service-principal`, providing the principal information. You can then use `az webapp config container set` to set the container name, tag, registry URL, and registry password. For more information, see [How to sign in to the Azure CLI on Circle CI](https://circleci.com/orbs/registry/orb/circleci/azure-cli).
119
119
120
-
-[How to sign in to the Azure CLI on Circle CI](https://circleci.com/orbs/registry/orb/circleci/azure-cli)
120
+
## Language-specific considerations
121
121
122
-
## Language-Specific Considerations
122
+
Keep in mind the following considerations for Java, Node, and .NET implementations.
123
123
124
124
### Java
125
125
126
-
Use the Kudu [zipdeploy/](deploy-zip.md) API for deploying JAR applications, and[wardeploy/](deploy-zip.md#deploy-warjarear-packages) for WAR apps. If you're using Jenkins, you can use those APIs directly in your deployment phase. For more information, see [this article](/azure/developer/jenkins/deploy-to-azure-app-service-using-azure-cli).
126
+
Use the Kudu [zipdeploy/](deploy-zip.md) API for deploying JAR applications. Use[wardeploy/](deploy-zip.md#deploy-warjarear-packages) for WAR apps. If you're using Jenkins, you can use those APIs directly in your deployment phase. For more information, see [Deploy to Azure App Service with Jenkins](/azure/developer/jenkins/deploy-to-azure-app-service-using-azure-cli).
127
127
128
128
### Node
129
129
130
-
By default, Kudu executes the build steps for your Node application (`npm install`). If you're using a build service such as Azure DevOps, then the Kudu build is unnecessary. To disable the Kudu build, create an app setting, `SCM_DO_BUILD_DURING_DEPLOYMENT`, with a value of `false`.
130
+
By default, Kudu runs the build steps for your Node application (`npm install`). If you're using a build service such as Azure DevOps, the Kudu build is unnecessary. To disable the Kudu build, create an app setting, `SCM_DO_BUILD_DURING_DEPLOYMENT`, with a value of `false`.
131
131
132
-
### .NET
132
+
### .NET
133
133
134
-
By default, Kudu executes the build steps for your .NET application (`dotnet build`). If you're using a build service such as Azure DevOps, then the Kudu build is unnecessary. To disable the Kudu build, create an app setting, `SCM_DO_BUILD_DURING_DEPLOYMENT`, with a value of `false`.
134
+
By default, Kudu runs the build steps for your .NET application (`dotnet build`). If you're using a build service such as Azure DevOps, the Kudu build is unnecessary. To disable the Kudu build, create an app setting, `SCM_DO_BUILD_DURING_DEPLOYMENT`, with a value of `false`.
135
135
136
-
## Other Deployment Considerations
136
+
## Other deployment considerations
137
137
138
-
### Local Cache
138
+
Other considerations include local cache and high CPU or memory.
139
139
140
-
Azure App Service content is stored on Azure Storage and is surfaced up in a durable manner as a content share. However, some apps just need a high-performance, read-only content store that they can run with high availability. These apps can benefit from using [local cache](overview-local-cache.md). Local cache isn't recommended for content management sites such as WordPress.
140
+
### Local cache
141
141
142
-
To prevent downtime, always use local cache with [deployment slots](deploy-staging-slots.md). See [this section](overview-local-cache.md#best-practices-for-using-app-service-local-cache) for information on using these features together.
142
+
Azure App Service content is stored on Azure Storage and is surfaced up in a durable manner as a content share. However, some apps just need a high-performance, read-only content store that they can run with high availability. These apps can benefit from using*localcache*. For more information, see [Azure App Service Local Cache overview](overview-local-cache.md).
143
143
144
-
### High CPU or Memory
144
+
> [!NOTE]
145
+
> Local cache isn't recommended for content management sites such as WordPress.
146
+
147
+
To prevent downtime, always use local cache with [deployment slots](deploy-staging-slots.md). For information on using these features together, see [Best practices](overview-local-cache.md#best-practices-for-using-app-service-local-cache).
148
+
149
+
### High CPU or memory
145
150
146
151
If your App Service Plan is using over 90% of available CPU or memory, the underlying virtual machine might have trouble processing your deployment. When this situation happens, temporarily scale up your instance count to perform the deployment. After the deployment finishes, you can return the instance count to its previous value.
147
152
148
-
For more information on best practices, visit [App Service Diagnostics](./overview-diagnostics.md) to find out actionable best practices specific to your resource.
153
+
For more information, visit [App Service Diagnostics](./overview-diagnostics.md) to find out actionable best practices specific to your resource.
154
+
155
+
1. Navigate to your Web App in the [Azure portal](https://portal.azure.com).
156
+
1. Select **Diagnose and solve problems** in the left navigation, which opens App Service Diagnostics.
157
+
1. Choose **Availability and Performance** or explore other options, such as **High CPU Analysis**.
149
158
150
-
- Navigate to your Web App in the [Azure portal](https://portal.azure.com).
151
-
- Select on **Diagnose and solve problems** in the left navigation, which opens App Service Diagnostics.
152
-
- Choose **Best Practices** homepage tile.
153
-
- Select **Best Practices for Availability & Performance** or **Best Practices for Optimal Configuration** to view the current state of your app in regards to these best practices.
159
+
View the current state of your app in regards to these best practices.
154
160
155
161
You can also use this link to directly open App Service Diagnostics for your resource: `https://portal.azure.com/?websitesextension_ext=asd.featurePath%3Ddetectors%2FParentAvailabilityAndPerformance#@microsoft.onmicrosoft.com/resource/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{siteName}/troubleshoot`.
156
162
157
-
## More resources
163
+
## Related content
158
164
159
-
[Environment variables and app settings reference](reference-app-settings.md)
165
+
-[Environment variables and app settings reference](reference-app-settings.md)
0 commit comments