Skip to content

Commit 3359a2b

Browse files
committed
Updates to GitHub action for container deployments
1 parent b0c62c0 commit 3359a2b

File tree

3 files changed

+112
-41
lines changed

3 files changed

+112
-41
lines changed

articles/azure-functions/functions-continuous-deployment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ If you want to use a different deployment source or build provider for continuou
182182

183183
## Enable basic authentication for deployments
184184

185-
By default, your function app is created with basic authentication access to the `scm` endpoint disabled. This blocks publishing by all methods that can't use managed identities to access the `scm` endpoint. The publishing impacts of having the `scm` endpoint disabled are detailed in [Deployment without basic authentication](../app-service/configure-basic-auth-disable.md#deployment-without-basic-authentication).
185+
In some cases, your function app is created with basic authentication access to the `scm` endpoint disabled. This blocks publishing by all methods that can't use managed identities to access the `scm` endpoint. The publishing impacts of having the `scm` endpoint disabled are detailed in [Deployment without basic authentication](../app-service/configure-basic-auth-disable.md#deployment-without-basic-authentication).
186186

187187
> [!IMPORTANT]
188188
> When you use basic authenication, credentials are sent in clear text. To protect these credentials, you must only access the `scm` endpoint over an encrypted connection (HTTPS) when using basic authentication. For more information, see [Secure deployment](security-concepts.md#secure-deployment).

articles/azure-functions/functions-how-to-github-actions.md

Lines changed: 106 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,14 @@ zone_pivot_groups: github-actions-deployment-options
99

1010
# Continuous delivery by using GitHub Actions
1111

12-
You can use a [GitHub Actions workflow](https://docs.github.com/actions/learn-github-actions/introduction-to-github-actions#the-components-of-github-actions) to define a workflow to automatically build and deploy code to your function app in Azure Functions. This article supports both code deployments to Azure Functions (using the `Azure/functions-action` action) and image deployments to a container registry (using `Azure/functions-container-action`).
12+
You can use a [GitHub Actions workflow](https://docs.github.com/actions/learn-github-actions/introduction-to-github-actions#the-components-of-github-actions) to automatically build and deploy your function code to Azure. This article supports these GitHub Actions-based deployment methods:
1313

14-
A YAML file (.yml) that defines the workflow configuration is maintained in the `/.github/workflows/` path in your repository. This definition contains the actions and parameters that make up the workflow, which is specific to the development language of your functions.
15-
16-
### [Code deployment](#tab/code-only)
17-
18-
A GitHub Actions workflow for Functions performs the following tasks, regardless of language:
19-
20-
1. Set up the environment.
21-
1. Build the code project.
22-
1. Deploy the package to a function app in Azure.
23-
24-
The Azure Functions action handles the deployment to an existing function app in Azure.
25-
26-
### [Container deployment](#tab/container2)
14+
| Method | Action | Tasks |
15+
| ---- | ---- | ---- |
16+
| Code-only | `Azure/functions-action` | 1. Set up the environment.<br/>2. Build the code project.<br/>3. Deploy the package to a function app in Azure. |
17+
| Container | `Azure/functions-container-action` | 1. Set up the environment.<br/>2. Build the Docker container.<br/>3. Push the image to the container registry.<br/>4. Deploy the container to Azure. |
2718

28-
A GitHub Actions workflow for containerized function apps performs the following tasks:
29-
30-
1. Set up the environment.
31-
1. Build the Docker container.
32-
1. Push the image to the registry.
33-
1. Deploy the container to Azure
34-
35-
The Azure Functions container action handles the deployment from an existing container registry to Azure.
36-
37-
---
19+
A YAML file (.yml) that defines the workflow configuration is maintained in the `/.github/workflows/` path in your repository. This definition contains the actions and parameters that make up the workflow, which is specific to the development language of your functions.
3820

3921
You can create a workflow configuration file for your deployment manually. You can also generate the file from a set of language-specific templates in one of these ways:
4022

@@ -62,26 +44,62 @@ If you don't want to create your YAML file by hand, select a different method at
6244
::: zone-end
6345
::: zone pivot="method-manual,method-template"
6446

65-
## Generate deployment credentials
47+
## Choose deployment credentials
6648

67-
Since GitHub Actions requires credentials to be able to access your function app (code deployment) your container registry (container deployment), you first need to get the credentials you need from your Azure service and store them securely as [GitHub secrets](https://docs.github.com/en/actions/reference/encrypted-secrets).
49+
Since GitHub Actions requires credentials to be able to access Azure resources, you first need to get the credentials you need from Azure and store them securely in your repository as [GitHub secrets](https://docs.github.com/en/actions/reference/encrypted-secrets).
6850

69-
### Get the service access credentals
51+
There are several supported authentication credentials you can use when deploying your code to Azure using GitHub Actions. This article supports these credentials:
52+
53+
| Credential | Set in... | Deployment type | Usage |
54+
| ---- | ---- | --- | --- |
55+
| Publish profile | [`Azure/functions-action`](https://github.com/marketplace/actions/azure-functions-action) | Code-only | Use the basic authentication credentials in the publish profile to connect to the `scm` deployment endpoint. |
56+
| Service principal secret |[`Azure/login`](https://github.com/Azure/login) | Code-only<br/>Containers | Using the [credentials of an Azure service principal](https://github.com/marketplace/actions/azure-login?version=v1.6.1#login-with-a-service-principal-secret) to perform identity-based authentication during deployment. |
57+
| Docker credentials | [`docker/login-action`](https://github.com/marketplace/actions/docker-login) | Container | When accessing a private Docker container registry. For an Azure Container Registry, you can also use an Azure service principal secret. |
58+
59+
You must securely store the required credentials in GitHub secrets for use by GitHub Actions during deployment.
60+
61+
## Get the service access credentals
7062

7163
>[!IMPORTANT]
72-
>In this section you are working with valuable credentials that allow access to Azure resources. Make sure you always transport and store credentials securely. In GitHub, these credentials must only be stored as GitHub secrets.
64+
>In this section you are working with valuable credentials that allow access to Azure resources. Make sure you always transport and store credentials securely. In GitHub, these credentials **must** only be stored as GitHub secrets.
7365
74-
### [Code deployment](#tab/code-only)
66+
### [Publish profile](#tab/publish-profile)
67+
68+
Publish profile is an XML-formated object that contains basic authentication credentials used to access the `scm` deployment endpoint. These credentials are used by tools like Visual Studio and Azure Functions Core Tools to deploy code to your function app. Publish profiles require you to [enable basic authentication](./functions-continuous-deployment.md#enable-basic-authentication-for-deployments) on the `scm` management endoint.
7569

7670
[!INCLUDE [functions-download-publish-profile](../../includes/functions-download-publish-profile.md)]
7771

78-
### [Container deployment](#tab/container2)
72+
### [Service principal secret](#tab/service-principal)
73+
74+
You can use the identity of a service principal in Azure when connecting to your app's `scm` deployment endpoint. This is also the recommended way to connect to an Azure Container Registry from your GitHub account. You use Azure role-based access control (Azure RBAC) to limit access only to the Azure resources required for publishing.
75+
76+
1. Use this [az ad sp create-for-rbac](/cli/azure/ad/sp#az-ad-sp-create-for-rbac) command to create a service principal and get its credential:
77+
78+
```azurecli
79+
az ad sp create-for-rbac --name "<APP_NAME>_deployment" --role contributor --scopes /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.Web/sites/<APP_NAME> --sdk-auth
80+
```
81+
82+
Replace `<SUBSCRIPTION_ID>`, `<RESOURCE_GROUP>`, and `<APP_NAME>` with the names of your subscription, resource group, and function app.
83+
84+
The output from this command is a JSON object that is the credential that GitHub Actions uses to connect to your app.You need to securely retain this output until you can add as a GitHub secret.
7985
80-
The most secure way to access Azure Container Registry from your GitHub account is by using Azure role-based access control (Azure RBAC). Use these steps to create the
86+
1. (Optional) To deploy a containerized function app from Azure Container Registry, use this [az role assignment create](/cli/azure/role/assignment#az-role-assignment-create) command to add the `acrpull` role to the new service principal:
87+
88+
```azurecli
89+
az role assignment create --assignee <SERVICE_PRINCIPAL_ID> --scope /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.ContainerRegistry/registries/<REGISTRY_NAME> --role acrpull
90+
```
91+
92+
Replace `<SUBSCRIPTION_ID>`, `<RESOURCE_GROUP>`, and `<REGISTRY_NAME>` with the names of your subscription, resource group, and registry.Replace `<SERVICE_PRINCIPAL_ID>` with the `clientID` from the credentials you obtained in the previous step. The role you added is scoped to your specific Azure Container Registry instance.
93+
94+
### [Docker credentials](#tab/docker-credentials)
95+
96+
You need to use registry-specific credentials when deploying a container from a private container registry. For Azure Container Registry (ACR), you can also use the service principal credential.
97+
98+
The way that you obtain this credential depends on the container registry. For more information, see [Docker Login Action](https://github.com/marketplace/actions/docker-login#usage).
8199
82100
---
83101
84-
### Add the GitHub secret
102+
## Add credentials to GitHub secrets
85103
86104
1. In [GitHub](https://github.com/), go to your repository.
87105
@@ -91,11 +109,30 @@ The most secure way to access Azure Container Registry from your GitHub account
91109
92110
1. Select **New repository secret**.
93111
94-
1. Add a new secret with the name `AZURE_FUNCTIONAPP_PUBLISH_PROFILE` and the value set to the contents of the publishing profile file.
112+
1. Define the secret, which depends on your chosen credential:
113+
114+
### [Publish profile](#tab/publish-profile)
115+
116+
+ **Name**: `AZURE_FUNCTIONAPP_PUBLISH_PROFILE`
117+
+ **Secret**: Paste the entire XML contents of the publish profile.
118+
119+
### [Service principal secret](#tab/service-principal)
120+
121+
+ **Name**: `AZURE_CREDENTIALS`
122+
+ **Secret**: Paste the entire JSON output you obtained when you created your service principal.
123+
124+
### [Docker credentials](#tab/docker-credentials)
125+
126+
+ **Name**: `REGISTRY_USERNAME`
127+
+ **Secret**: The username of your account in the private Docker registry.
128+
+ **Name**: `REGISTRY_PASSWORD`
129+
+ **Secret**: The password for your account in the private Docker registry.
130+
131+
---
95132
96133
1. Select **Add secret**.
97134
98-
GitHub can now authenticate to your function app in Azure.
135+
GitHub can now authenticate with your Azure resources during deployment.
99136
::: zone-end
100137
::: zone pivot="method-manual"
101138
@@ -167,14 +204,28 @@ The best way to manually create a workflow configuration is to start from the of
167204
168205
Remember to do the following before you use this YAML file:
169206
170-
+ Add `AZURE_CREDENTIALS` to your GitHub repository secrets.
171-
+ Add `REGISTRY_USERNAME` to your GitHub repository secrets.
172-
+ Add `REGISTRY_PASSWORD` to your GitHub repository secrets.
173207
+ Update the values of `REGISTRY`, `NAMESPACE`, `IMAGE`, and `TAG` based on your container registry.
174-
208+
+ To use service principal credentials with Azure Container Registry, replace the existing `azure/docker-Login` action with this `docker/login-action`:
209+
210+
```yml
211+
- name: Login to ACR
212+
uses: docker/login-action@v3
213+
with:
214+
registry: <registry-name>.azurecr.io
215+
username: ${{ secrets.AZURE_CREDENTIALS.clientId }}
216+
password: ${{ secrets.AZURE_CREDENTIALS.clientSecret }}
217+
```
175218
---
176219
177220
1. Update the `env.AZURE_FUNCTIONAPP_NAME` parameter with the name of your function app resource in Azure. You may optionally need to update the parameter that sets the language version used by your app, such as `DOTNET_VERSION` for C#.
221+
222+
1. To use a service principal credential instead of a publish profile, remove `publish-profile` from the `azure/functions-action` and add this `azure/login` action before `azure/functions-action`:
223+
224+
```yml
225+
- name: 'Login w/ service principal'
226+
uses: azure/login@v2
227+
with:
228+
creds: ${{ secrets.AZURE_CREDENTIALS }}
178229
179230
1. Add this new YAML file in the `/.github/workflows/` path in your repository.
180231
@@ -258,6 +309,14 @@ You can create the GitHub Actions workflow configuration file from the Azure Fun
258309
259310
1. In the newly created YAML file, update the `env.AZURE_FUNCTIONAPP_NAME` parameter with the name of your function app resource in Azure. You may optionally need to update the parameter that sets the language version used by your app, such as `DOTNET_VERSION` for C#.
260311
312+
1. To use a service principal credential instead of a publish profile, remove `publish-profile` from the `azure/functions-action` and add this `azure/login` action before `azure/functions-action`:
313+
314+
```yml
315+
- name: 'Login w/ service principal'
316+
uses: azure/login@v2
317+
with:
318+
creds: ${{ secrets.AZURE_CREDENTIALS }}
319+
261320
1. Verify that the new workflow file is being saved in `/.github/workflows/` and select **Commit changes...**.
262321
::: zone-end
263322
@@ -319,6 +378,14 @@ Python functions aren't supported on Windows. Choose Linux instead.
319378
320379
:::code language="yml" source="~/azure-actions-workflow-samples/FunctionApp/linux-powershell-functionapp-on-azure.yml" range="1-5,13-31":::
321380
381+
### [Container](#tab/Container/windows)
382+
383+
Container deployments aren't supported on Windows. Choose Linux instead.
384+
385+
### [Container](#tab/Container/linux)
386+
387+
:::code language="yml" source="~/azure-actions-workflow-samples/FunctionApp/linux-container-functionapp-on-azure.yml" range="9-57":::
388+
322389
---
323390
324391
## Azure Functions action
@@ -333,7 +400,7 @@ The following parameters are most commonly used with this action:
333400
|---------|---------|
334401
|_**app-name**_ | (Mandatory) The name of your function app. |
335402
|_**slot-name**_ | (Optional) The name of a specific [deployment slot](functions-deployment-slots.md) you want to deploy to. The slot must already exist in your function app. When not specified, the code is deployed to the active slot. |
336-
|_**publish-profile**_ | (Optional) The name of the GitHub secret that contains your publish profile. |
403+
|_**publish-profile**_ | (Optional) The name of the GitHub secret that contains your publish profile. Don't include this if you are instead using a service principal credential with `azure/login`.|
337404
338405
The following parameters are also supported, but are used only in specific cases:
339406

includes/functions-download-publish-profile.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ ms.author: glenga
88

99
To download the publishing profile of your function app:
1010

11-
1. Select the function app's **Overview** page, and then select **Get publish profile**.
11+
1. In the [Azure portal](https://portal.azure.com), locate the page for your function app, expand **Settings** > **Configuration** in the left column.
12+
13+
1. In the **Configuration** page, select the **General settings** tab and make sure that **SCM Basic Auth Publishing Credentials** is turned **On**. When this setting is **Off**, you can't use publish profiles, so select **On** and then **Save**.
14+
15+
1. Go back to the function app's **Overview** page, and then select **Get publish profile**.
1216

1317
:::image type="content" source="../articles/azure-functions/media/functions-how-to-github-actions/get-publish-profile.png" alt-text="Download publish profile":::
1418

0 commit comments

Comments
 (0)