Skip to content

Commit d059665

Browse files
authored
Merge pull request #178256 from craigshoemaker/ca/new/github
[Container Apps] GitHub Actions CLI (new article)
2 parents a5b9949 + 7d7b7bd commit d059665

File tree

2 files changed

+149
-0
lines changed

2 files changed

+149
-0
lines changed
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
---
2+
title: Publish revisions with GitHub Actions in Azure Container Apps Preview
3+
description: Learn to automatically create new revisions using GitHub Actions in Azure Container Apps Preview
4+
services: app-service
5+
author: craigshoemaker
6+
ms.service: app-service
7+
ms.topic: how-to
8+
ms.date: 11/02/2021
9+
ms.author: cshoe
10+
---
11+
12+
# Publish revisions with GitHub Actions in Azure Container Apps Preview
13+
14+
Azure Container Apps allows you to use GitHub Actions to publish [revisions](revisions.md) to your container app. As commits are pushed to your GitHub repository, a GitHub Action is triggered which updates the [container](containers.md) image in the container registry. Once the container is updated in the registry, Azure Container Apps creates a new revision based on the updated container image.
15+
16+
:::image type="content" source="media/github-actions/azure-container-apps-github-actions.png" alt-text="Changes to a GitHub repo trigger an action to create a new revision.":::
17+
18+
The GitHub action is triggered by commits to a specific branch in your repository. When creating the integration link, you decide which branch triggers the action.
19+
20+
## Authentication
21+
22+
When adding or removing a GitHub Actions integration, you can authenticate by either passing in a GitHub [personal access token](https://docs.github.com/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token), or using the interactive GitHub login experience. The interactive experience opens a form in your web browser and gives you the opportunity to log in to GitHub. Once successfully authenticated, then a token is passed back to the CLI that is used by GitHub for the rest of the current session.
23+
24+
- To pass a personal access token, use the `--token` parameter and provide a token value.
25+
- If you choose to use interactive login, use the `--login-with-github` parameter with no value.
26+
27+
## Add
28+
29+
The `containerapp github-action add` command creates a GitHub Actions integration with your container app.
30+
31+
The first time you attach GitHub Actions to your container app, you need to provide a service principal context. The following command shows you how to create a service principal.
32+
33+
# [Bash](#tab/bash)
34+
35+
```azurecli
36+
az ad sp create-for-rbac \
37+
--name <SERVICE_PRINCIPAL_NAME> \
38+
--role "contributor" \
39+
--scopes /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP_NAME> /subscriptions/<SUBSCRIPTION_ID> \
40+
--sdk-auth
41+
```
42+
43+
# [PowerShell](#tab/powershell)
44+
45+
```azurecli
46+
az ad sp create-for-rbac `
47+
--name <SERVICE_PRINCIPAL_NAME> `
48+
--role "contributor" `
49+
--scopes /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP_NAME> /subscriptions/<SUBSCRIPTION_ID> `
50+
--sdk-auth
51+
```
52+
53+
---
54+
55+
As you interact with this example, replace the placeholders surrounded by `<>` with your values.
56+
57+
The return value from this command is a JSON payload, which includes the service principal's `tenantId`, `cliendId`, and `clientSecret`.
58+
59+
The following example shows you how to add an integration while using a personal access token.
60+
61+
# [Bash](#tab/bash)
62+
63+
```azurecli
64+
az containerapp github-action add \
65+
--repo-url "https://github.com/<OWNER>/<REPOSITORY_NAME>" \
66+
--docker-file-path "./dockerfile" \
67+
--branch <BRANCH_NAME> \
68+
--registry-url <URL_TO_CONTAINER_REGISTRY> \
69+
--registry-user-name <REGISTRY_USER_NAME> \
70+
--registry-password <REGISTRY_PASSWORD> \
71+
--service-principal-client-id <CLIENT_ID> \
72+
--service-principal-client-secret <CLIENT_SECRET> \
73+
--service-principal-tenant-id <TENANT_ID> \
74+
--token <YOUR_GITHUB_PERSONAL_ACCESS_TOKEN>
75+
```
76+
77+
# [PowerShell](#tab/powershell)
78+
79+
```azurecli
80+
az containerapp github-action add `
81+
--repo-url "https://github.com/<OWNER>/<REPOSITORY_NAME>" `
82+
--docker-file-path "./dockerfile" `
83+
--branch <BRANCH_NAME> `
84+
--registry-url <URL_TO_CONTAINER_REGISTRY> `
85+
--registry-user-name <REGISTRY_USER_NAME> `
86+
--registry-password <REGISTRY_PASSWORD> `
87+
--service-principal-client-id <CLIENT_ID> `
88+
--service-principal-client-secret <CLIENT_SECRET> `
89+
--service-principal-tenant-id <TENANT_ID> `
90+
--token <YOUR_GITHUB_PERSONAL_ACCESS_TOKEN>
91+
```
92+
93+
---
94+
95+
As you interact with this example, replace the placeholders surrounded by `<>` with your values.
96+
97+
## Show
98+
99+
The `containerapp github-action show` command returns the GitHub Actions configuration settings for a container app.
100+
101+
This example shows how to add an integration while using the personal access token.
102+
103+
# [Bash](#tab/bash)
104+
105+
```azurecli
106+
az containerapp github-action show \
107+
--resource-group <RESOURCE_GROUP_NAME> \
108+
--name <CONTAINER_APP_NAME>
109+
```
110+
111+
# [PowerShell](#tab/powershell)
112+
113+
```azurecli
114+
az containerapp github-action show `
115+
--resource-group <RESOURCE_GROUP_NAME> `
116+
--name <CONTAINER_APP_NAME>
117+
```
118+
119+
---
120+
121+
As you interact with this example, replace the placeholders surrounded by `<>` with your values.
122+
123+
This command returns a JSON payload with the GitHub Actions integration configuration settings.
124+
125+
## Delete
126+
127+
The `containerapp github-action remove` command removes the GitHub Actions from the container app.
128+
129+
# [Bash](#tab/bash)
130+
131+
```azurecli
132+
az containerapp github-action remove \
133+
--resource-group <RESOURCE_GROUP_NAME> \
134+
--name <CONTAINER_APP_NAME> \
135+
--token <YOUR_GITHUB_PERSONAL_ACCESS_TOKEN>
136+
```
137+
138+
# [PowerShell](#tab/powershell)
139+
140+
```azurecli
141+
az containerapp github-action remove `
142+
--resource-group <RESOURCE_GROUP_NAME> `
143+
--name <CONTAINER_APP_NAME> `
144+
--token <YOUR_GITHUB_PERSONAL_ACCESS_TOKEN>
145+
```
146+
147+
---
148+
149+
As you interact with this example, replace the placeholders surrounded by `<>` with your values.
30.2 KB
Loading

0 commit comments

Comments
 (0)