Skip to content

Commit d63f156

Browse files
authored
Merge pull request #153495 from MicrosoftDocs/master
Merge Master to Live, 4 AM
2 parents b055784 + 20e3db7 commit d63f156

File tree

122 files changed

+2083
-650
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+2083
-650
lines changed

.openpublishing.redirection.json

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,11 +2909,6 @@
29092909
"redirect_url": "/azure/app-service/deploy-configure-credentials",
29102910
"redirect_document_id": false
29112911
},
2912-
{
2913-
"source_path_from_root": "/articles/app-service/containers/deploy-container-github-action.md",
2914-
"redirect_url": "/azure/app-service/deploy-container-github-action",
2915-
"redirect_document_id": false
2916-
},
29172912
{
29182913
"source_path_from_root": "/articles/app-service/app-service-deploy-content-sync.md",
29192914
"redirect_url": "/azure/app-service/deploy-content-sync",
@@ -2929,16 +2924,6 @@
29292924
"redirect_url": "/azure/app-service/deploy-continuous-deployment",
29302925
"redirect_document_id": false
29312926
},
2932-
{
2933-
"source_path_from_root": "/articles/app-service/deploy-github-actions.md",
2934-
"redirect_url": "/azure/app-service/deploy-continuous-deployment",
2935-
"redirect_document_id": false
2936-
},
2937-
{
2938-
"source_path_from_root": "/articles/app-service/deploy-container-github-action.md",
2939-
"redirect_url": "/azure/app-service/deploy-ci-cd-custom-container",
2940-
"redirect_document_id": false
2941-
},
29422927
{
29432928
"source_path_from_root": "/articles/app-service-web/app-service-agile-software-development.md",
29442929
"redirect_url": "/azure/app-service/deploy-continuous-deployment",
Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
---
2+
title: Custom container CI/CD from GitHub Actions
3+
description: Learn how to use GitHub Actions to deploy your custom Linux container to App Service from a CI/CD pipeline.
4+
ms.devlang: na
5+
ms.topic: article
6+
ms.date: 12/04/2020
7+
ms.author: jafreebe
8+
ms.reviewer: ushan
9+
ms.custom: github-actions-azure
10+
11+
---
12+
13+
# Deploy a custom container to App Service using GitHub Actions
14+
15+
[GitHub Actions](https://docs.github.com/en/actions) gives you the flexibility to build an automated software development workflow. With the [Azure Web Deploy action](https://github.com/Azure/webapps-deploy), you can automate your workflow to deploy custom containers to [App Service](overview.md) using GitHub Actions.
16+
17+
A workflow is defined by a YAML (.yml) file in the `/.github/workflows/` path in your repository. This definition contains the various steps and parameters that are in the workflow.
18+
19+
For an Azure App Service container workflow, the file has three sections:
20+
21+
|Section |Tasks |
22+
|---------|---------|
23+
|**Authentication** | 1. Retrieve a service principal or publish profile. <br /> 2. Create a GitHub secret. |
24+
|**Build** | 1. Create the environment. <br /> 2. Build the container image. |
25+
|**Deploy** | 1. Deploy the container image. |
26+
27+
## Prerequisites
28+
29+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F)
30+
- A GitHub account. If you don't have one, sign up for [free](https://github.com/join). You need to have code in a GitHub repository to deploy to Azure App Service.
31+
- A working container registry and Azure App Service app for containers. This example uses Azure Container Registry. Make sure to complete the full deployment to Azure App Service for containers. Unlike regular web apps, web apps for containers do not have a default landing page. Publish the container to have a working example.
32+
- [Learn how to create a containerized Node.js application using Docker, push the container image to a registry, and then deploy the image to Azure App Service](/azure/developer/javascript/tutorial-vscode-docker-node-01)
33+
34+
## Generate deployment credentials
35+
36+
The recommended way to authenticate with Azure App Services for GitHub Actions is with a publish profile. You can also authenticate with a service principal but the process requires more steps.
37+
38+
Save your publish profile credential or service principal as a [GitHub secret](https://docs.github.com/en/actions/reference/encrypted-secrets) to authenticate with Azure. You'll access the secret within your workflow.
39+
40+
# [Publish profile](#tab/publish-profile)
41+
42+
A publish profile is an app-level credential. Set up your publish profile as a GitHub secret.
43+
44+
1. Go to your app service in the Azure portal.
45+
46+
1. On the **Overview** page, select **Get Publish profile**.
47+
48+
> [!NOTE]
49+
> As of October 2020, Linux web apps will need the app setting `WEBSITE_WEBDEPLOY_USE_SCM` set to `true` **before downloading the file**. This requirement will be removed in the future. See [Configure an App Service app in the Azure portal](./configure-common.md), to learn how to configure common web app settings.
50+
51+
1. Save the downloaded file. You'll use the contents of the file to create a GitHub secret.
52+
53+
# [Service principal](#tab/service-principal)
54+
55+
You can create a [service principal](../active-directory/develop/app-objects-and-service-principals.md#service-principal-object) with the [az ad sp create-for-rbac](/cli/azure/ad/sp#az-ad-sp-create-for-rbac) command in the [Azure CLI](/cli/azure/). Run this command with [Azure Cloud Shell](https://shell.azure.com/) in the Azure portal or by selecting the **Try it** button.
56+
57+
```azurecli-interactive
58+
az ad sp create-for-rbac --name "myApp" --role contributor \
59+
--scopes /subscriptions/<subscription-id>/resourceGroups/<group-name>/providers/Microsoft.Web/sites/<app-name> \
60+
--sdk-auth
61+
```
62+
63+
In the example, replace the placeholders with your subscription ID, resource group name, and app name. The output is a JSON object with the role assignment credentials that provide access to your App Service app. Copy this JSON object for later.
64+
65+
```output
66+
{
67+
"clientId": "<GUID>",
68+
"clientSecret": "<GUID>",
69+
"subscriptionId": "<GUID>",
70+
"tenantId": "<GUID>",
71+
(...)
72+
}
73+
```
74+
75+
> [!IMPORTANT]
76+
> It is always a good practice to grant minimum access. The scope in the previous example is limited to the specific App Service app and not the entire resource group.
77+
78+
---
79+
## Configure the GitHub secret for authentication
80+
81+
# [Publish profile](#tab/publish-profile)
82+
83+
In [GitHub](https://github.com/), browse your repository, select **Settings > Secrets > Add a new secret**.
84+
85+
To use [app-level credentials](#generate-deployment-credentials), paste the contents of the downloaded publish profile file into the secret's value field. Name the secret `AZURE_WEBAPP_PUBLISH_PROFILE`.
86+
87+
When you configure your GitHub workflow, you use the `AZURE_WEBAPP_PUBLISH_PROFILE` in the deploy Azure Web App action. For example:
88+
89+
```yaml
90+
- uses: azure/webapps-deploy@v2
91+
with:
92+
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
93+
```
94+
95+
# [Service principal](#tab/service-principal)
96+
97+
In [GitHub](https://github.com/), browse your repository, select **Settings > Secrets > Add a new secret**.
98+
99+
To use [user-level credentials](#generate-deployment-credentials), paste the entire JSON output from the Azure CLI command into the secret's value field. Give the secret the name like `AZURE_CREDENTIALS`.
100+
101+
When you configure the workflow file later, you use the secret for the input `creds` of the Azure Login action. For example:
102+
103+
```yaml
104+
- uses: azure/login@v1
105+
with:
106+
creds: ${{ secrets.AZURE_CREDENTIALS }}
107+
```
108+
109+
---
110+
111+
## Configure GitHub secrets for your registry
112+
113+
Define secrets to use with the Docker Login action. The example in this document uses Azure Container Registry for the container registry.
114+
115+
1. Go to your container in the Azure portal or Docker and copy the username and password. You can find the Azure Container Registry username and password in the Azure portal under **Settings** > **Access keys** for your registry.
116+
117+
2. Define a new secret for the registry username named `REGISTRY_USERNAME`.
118+
119+
3. Define a new secret for the registry password named `REGISTRY_PASSWORD`.
120+
121+
## Build the Container image
122+
123+
The following example show part of the workflow that builds a Node.JS Docker image. Use [Docker Login](https://github.com/azure/docker-login) to log into a private container registry. This example uses Azure Container Registry but the same action works for other registries.
124+
125+
126+
```yaml
127+
name: Linux Container Node Workflow
128+
129+
on: [push]
130+
131+
jobs:
132+
build:
133+
runs-on: ubuntu-latest
134+
135+
steps:
136+
- uses: actions/checkout@v2
137+
- uses: azure/docker-login@v1
138+
with:
139+
login-server: mycontainer.azurecr.io
140+
username: ${{ secrets.REGISTRY_USERNAME }}
141+
password: ${{ secrets.REGISTRY_PASSWORD }}
142+
- run: |
143+
docker build . -t mycontainer.azurecr.io/myapp:${{ github.sha }}
144+
docker push mycontainer.azurecr.io/myapp:${{ github.sha }}
145+
```
146+
147+
You can also use [Docker Login](https://github.com/azure/docker-login) to log into multiple container registries at the same time. This example includes two new GitHub secrets for authentication with docker.io. The example assumes that there is a Dockerfile at the root level of the registry.
148+
149+
```yml
150+
name: Linux Container Node Workflow
151+
152+
on: [push]
153+
154+
jobs:
155+
build:
156+
runs-on: ubuntu-latest
157+
158+
steps:
159+
- uses: actions/checkout@v2
160+
- uses: azure/docker-login@v1
161+
with:
162+
login-server: mycontainer.azurecr.io
163+
username: ${{ secrets.REGISTRY_USERNAME }}
164+
password: ${{ secrets.REGISTRY_PASSWORD }}
165+
- uses: azure/docker-login@v1
166+
with:
167+
login-server: index.docker.io
168+
username: ${{ secrets.DOCKERIO_USERNAME }}
169+
password: ${{ secrets.DOCKERIO_PASSWORD }}
170+
- run: |
171+
docker build . -t mycontainer.azurecr.io/myapp:${{ github.sha }}
172+
docker push mycontainer.azurecr.io/myapp:${{ github.sha }}
173+
```
174+
175+
## Deploy to an App Service container
176+
177+
To deploy your image to a custom container in App Service, use the `azure/webapps-deploy@v2` action. This action has seven parameters:
178+
179+
| **Parameter** | **Explanation** |
180+
|---------|---------|
181+
| **app-name** | (Required) Name of the App Service app |
182+
| **publish-profile** | (Optional) Applies to Web Apps(Windows and Linux) and Web App Containers(linux). Multi container scenario not supported. Publish profile (\*.publishsettings) file contents with Web Deploy secrets |
183+
| **slot-name** | (Optional) Enter an existing Slot other than the Production slot |
184+
| **package** | (Optional) Applies to Web App only: Path to package or folder. \*.zip, \*.war, \*.jar or a folder to deploy |
185+
| **images** | (Required) Applies to Web App Containers only: Specify the fully qualified container image(s) name. For example, 'myregistry.azurecr.io/nginx:latest' or 'python:3.7.2-alpine/'. For a multi-container app, multiple container image names can be provided (multi-line separated) |
186+
| **configuration-file** | (Optional) Applies to Web App Containers only: Path of the Docker-Compose file. Should be a fully qualified path or relative to the default working directory. Required for multi-container apps. |
187+
| **startup-command** | (Optional) Enter the start-up command. For ex. dotnet run or dotnet filename.dll |
188+
189+
# [Publish profile](#tab/publish-profile)
190+
191+
```yaml
192+
name: Linux Container Node Workflow
193+
194+
on: [push]
195+
196+
jobs:
197+
build:
198+
runs-on: ubuntu-latest
199+
200+
steps:
201+
- uses: actions/checkout@v2
202+
203+
- uses: azure/docker-login@v1
204+
with:
205+
login-server: mycontainer.azurecr.io
206+
username: ${{ secrets.REGISTRY_USERNAME }}
207+
password: ${{ secrets.REGISTRY_PASSWORD }}
208+
209+
- run: |
210+
docker build . -t mycontainer.azurecr.io/myapp:${{ github.sha }}
211+
docker push mycontainer.azurecr.io/myapp:${{ github.sha }}
212+
213+
- uses: azure/webapps-deploy@v2
214+
with:
215+
app-name: 'myapp'
216+
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
217+
images: 'mycontainer.azurecr.io/myapp:${{ github.sha }}'
218+
```
219+
# [Service principal](#tab/service-principal)
220+
221+
```yaml
222+
on: [push]
223+
224+
name: Linux_Container_Node_Workflow
225+
226+
jobs:
227+
build-and-deploy:
228+
runs-on: ubuntu-latest
229+
steps:
230+
# checkout the repo
231+
- name: 'Checkout GitHub Action'
232+
uses: actions/checkout@main
233+
234+
- name: 'Login via Azure CLI'
235+
uses: azure/login@v1
236+
with:
237+
creds: ${{ secrets.AZURE_CREDENTIALS }}
238+
239+
- uses: azure/docker-login@v1
240+
with:
241+
login-server: mycontainer.azurecr.io
242+
username: ${{ secrets.REGISTRY_USERNAME }}
243+
password: ${{ secrets.REGISTRY_PASSWORD }}
244+
- run: |
245+
docker build . -t mycontainer.azurecr.io/myapp:${{ github.sha }}
246+
docker push mycontainer.azurecr.io/myapp:${{ github.sha }}
247+
248+
- uses: azure/webapps-deploy@v2
249+
with:
250+
app-name: 'myapp'
251+
images: 'mycontainer.azurecr.io/myapp:${{ github.sha }}'
252+
253+
- name: Azure logout
254+
run: |
255+
az logout
256+
```
257+
258+
---
259+
260+
## Next steps
261+
262+
You can find our set of Actions grouped into different repositories on GitHub, each one containing documentation and examples to help you use GitHub for CI/CD and deploy your apps to Azure.
263+
264+
- [Actions workflows to deploy to Azure](https://github.com/Azure/actions-workflow-samples)
265+
266+
- [Azure login](https://github.com/Azure/login)
267+
268+
- [Azure WebApp](https://github.com/Azure/webapps-deploy)
269+
270+
- [Docker login/logout](https://github.com/Azure/docker-login)
271+
272+
- [Events that trigger workflows](https://docs.github.com/en/actions/reference/events-that-trigger-workflows)
273+
274+
- [K8s deploy](https://github.com/Azure/k8s-deploy)
275+
276+
- [Starter Workflows](https://github.com/actions/starter-workflows)

0 commit comments

Comments
 (0)