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
+87-5Lines changed: 87 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,6 +33,92 @@ The deployment mechanism is the action used to put your built application into t
33
33
34
34
Deployment tools such as Azure Pipelines, Jenkins, and editor plugins use one of these deployment mechanisms.
35
35
36
+
## Use deployment slots
37
+
38
+
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 are 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.
39
+
40
+
### Continuously deploy code
41
+
42
+
If your project has designated branches for testing, QA, and staging, then each of those branches should be continuously deployed to a staging slot. (This is known as the [Gitflow design](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow).) This allows your stakeholders to easily assess and test the deployed the branch.
43
+
44
+
Continuous deployment should never be enabled for your production slot. Instead, your production branch (often master) should be deployed onto a non-production slot. When you are 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.
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.
51
+
52
+
For each branch you want to deploy to a slot, set up automation to do the following on each commit to the branch.
53
+
54
+
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.
55
+
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.
56
+
1.**Update the deployment slot with the new image tag**. When this property is updated, the site will automatically restart and pull the new container image.
There are examples below for common automation frameworks.
61
+
62
+
### Use Azure DevOps
63
+
64
+
App Service has [built-in continuous delivery](deploy-continuous-deployment.md) for containers through the Deployment Center. Navigate to your app in the [Azure portal](https://portal.azure.com/) and select **Deployment Center** under **Deployment**. Follow the instructions to select your repository and branch. This will configure a DevOps build and release pipeline to automatically build, tag, and deploy your container when new commits are pushed to your selected branch.
65
+
66
+
### Use GitHub Actions
67
+
68
+
You can also automate your container deployment [with GitHub Actions](containers/deploy-container-github-action.md). The workflow file below will build and tag the container with the commit ID, push it to a container registry, and update the specified site slot with the new image tag.
69
+
70
+
```yaml
71
+
name: Build and deploy a container image to Azure Web Apps
72
+
73
+
on:
74
+
push:
75
+
branches:
76
+
- <your-branch-name>
77
+
78
+
jobs:
79
+
build-and-deploy:
80
+
runs-on: ubuntu-latest
81
+
82
+
steps:
83
+
- uses: actions/checkout@master
84
+
85
+
-name: Authenticate using a Service Principal
86
+
uses: azure/actions/login@v1
87
+
with:
88
+
creds: ${{ secrets.AZURE_SP }}
89
+
90
+
- uses: azure/container-actions/docker-login@v1
91
+
with:
92
+
username: ${{ secrets.DOCKER_USERNAME }}
93
+
password: ${{ secrets.DOCKER_PASSWORD }}
94
+
95
+
- name: Build and push the image tagged with the git commit hash
96
+
run: |
97
+
docker build . -t contoso/demo:${{ github.sha }}
98
+
docker push contoso/demo:${{ github.sha }}
99
+
100
+
- name: Update image tag on the Azure Web App
101
+
uses: azure/webapps-container-deploy@v1
102
+
with:
103
+
app-name: '<your-webapp-name>'
104
+
slot-name: '<your-slot-name>'
105
+
images: 'contoso/demo:${{ github.sha }}'
106
+
```
107
+
108
+
### Use other automation providers
109
+
110
+
The steps listed earlier apply to other automation utilities such as CircleCI or Travis CI. However, you need to use the Azure CLI to update the deployment slots with new image tags in the final step. To use the Azure CLI in your automation script, generate a Service Principal using the following command.
111
+
112
+
```shell
113
+
az ad sp create-for-rbac --name "myServicePrincipal" --role contributor \
In your script, log 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. Below are some helpful links for you to construct your container CI process.
119
+
120
+
-[How to log into the Azure CLI on Circle CI](https://circleci.com/orbs/registry/orb/circleci/azure-cli)
121
+
36
122
## Language-Specific Considerations
37
123
38
124
### Java
@@ -45,14 +131,10 @@ By default, Kudu executes the build steps for your Node application (`npm instal
45
131
46
132
### .NET
47
133
48
-
By default, Kudu executes the build steps for your .Net application (`dotnet build`). If you are 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 executes the build steps for your .NET application (`dotnet build`). If you are 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`.
49
135
50
136
## Other Deployment Considerations
51
137
52
-
### Use deployment slots
53
-
54
-
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 are 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.
55
-
56
138
### Local Cache
57
139
58
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 is not recommended for content management sites such as WordPress.
0 commit comments