Skip to content

Commit 48f6910

Browse files
authored
Merge pull request #194547 from craigshoemaker/aca/code-2-cloud
[Container Apps] Quickstart & Tutorial: Code to cloud
2 parents 559658d + 57a0864 commit 48f6910

File tree

9 files changed

+785
-1
lines changed

9 files changed

+785
-1
lines changed

articles/container-apps/TOC.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
href: deploy-visual-studio.md
3131
- name: Visual Studio Code
3232
href: deploy-visual-studio-code.md
33+
- name: With code on your local machine
34+
href: quickstart-code-to-cloud.md
3335
- name: Concepts
3436
items:
3537
- name: Environment
@@ -102,6 +104,8 @@
102104
href: disaster-recovery.md
103105
- name: Tutorials
104106
items:
107+
- name: Communicate between microservices
108+
href: communicate-between-microservices.md
105109
- name: Microservices with Dapr using the CLI
106110
href: microservices-dapr.md
107111
- name: Microservices with Dapr using ARM or Bicep
Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
---
2+
title: 'Tutorial: Communication between microservices in Azure Container Apps'
3+
description: Learn how to communicate between microservices deployed in Azure Container Apps
4+
services: container-apps
5+
author: craigshoemaker
6+
ms.service: container-apps
7+
ms.topic: tutorial
8+
ms.date: 05/13/2022
9+
ms.author: cshoe
10+
zone_pivot_groups: container-apps-image-build-type
11+
---
12+
13+
# Tutorial: Communication between microservices in Azure Container Apps Preview
14+
15+
Azure Container Apps exposes each container app through a domain name if [ingress](ingress.md) is enabled. Ingress endpoints for container apps within an external environment can be either publicly accessible or only available to other container apps in the same [environment](environment.md).
16+
17+
Once you know the fully qualified domain name for a given container app, you can make direct calls to the service from other container apps within the shared environment.
18+
19+
In this tutorial, you deploy a second container app that makes a direct service call to the API deployed in the [Deploy your code to Azure Container Apps](./quickstart-code-to-cloud.md) quickstart.
20+
21+
The following screenshot shows the UI microservice deploys to container apps at the end of this article.
22+
23+
:::image type="content" source="media/communicate-between-microservices/azure-container-apps-album-ui.png" alt-text="Screenshot of album list UI microservice.":::
24+
25+
In this tutorial, you learn to:
26+
27+
> [!div class="checklist"]
28+
> * Deploy a front end application to Azure Container Apps
29+
> * Link the front end app to the API endpoint deployed in the previous quickstart
30+
> * Verify the frontend app can communicate with the back end API
31+
32+
## Prerequisites
33+
34+
In the [code to cloud quickstart](./quickstart-code-to-cloud.md), a back end web API is deployed to return a list of music albums. If you haven't deployed the album API microservice, return to [Quickstart: Deploy your code to Azure Container Apps](quickstart-code-to-cloud.md) to continue.
35+
36+
## Setup
37+
38+
If you're still authenticated to Azure and still have the environment variables defined from the quickstart, you can skip the following steps and go directly to the [Prepare the GitHub repository](#prepare-the-github-repository) section.
39+
40+
[!INCLUDE [container-apps-code-to-cloud-setup.md](../../includes/container-apps-code-to-cloud-setup.md)]
41+
42+
Sign in to the Azure CLI.
43+
44+
# [Bash](#tab/bash)
45+
46+
```azurecli
47+
az login
48+
```
49+
50+
# [PowerShell](#tab/powershell)
51+
52+
```powershell
53+
az login
54+
```
55+
56+
---
57+
58+
::: zone pivot="docker-local"
59+
60+
# [Bash](#tab/bash)
61+
62+
```azurecli
63+
az acr login --name $ACR_NAME
64+
```
65+
66+
# [PowerShell](#tab/powershell)
67+
68+
```powershell
69+
az acr login --name $ACR_NAME
70+
```
71+
72+
---
73+
74+
::: zone-end
75+
76+
## Prepare the GitHub repository
77+
78+
1. In a new browser tab, navigate to the [repository for the UI application](https://github.com/azure-samples/containerapps-albumui) and select the **Fork** button at the top of the page to fork the repo to your account.
79+
80+
Follow the prompts from GitHub to fork the repository and return here once the operation is complete.
81+
82+
1. Navigate to the parent of the *code-to-cloud* folder. If you're still in the *code-to-cloud/src* directory, you can use the below command to return to the parent folder.
83+
84+
```console
85+
cd ../..
86+
```
87+
88+
1. Use the following git command to clone your forked repo into the *code-to-cloud-ui* folder:
89+
90+
```git
91+
git clone https://github.com/$GITHUB_USERNAME/containerapps-albumui.git code-to-cloud-ui
92+
```
93+
94+
> [!NOTE]
95+
> If the `clone` command fails, check that you have successfully forked the repository.
96+
97+
1. Next, change the directory into the *src* folder of the cloned repo.
98+
99+
```console
100+
cd code-to-cloud-ui/src
101+
```
102+
103+
## Build the front end application
104+
105+
::: zone pivot="acr-remote"
106+
107+
# [Bash](#tab/bash)
108+
109+
```azurecli
110+
az acr build --registry $ACR_NAME --image albumapp-ui .
111+
```
112+
113+
# [PowerShell](#tab/powershell)
114+
115+
```powershell
116+
az acr build --registry $ACR_NAME --image albumapp-ui .
117+
```
118+
119+
---
120+
121+
Output from the `az acr build` command shows the upload progress of the source code to Azure and the details of the `docker build` operation.
122+
123+
::: zone-end
124+
125+
::: zone pivot="docker-local"
126+
127+
1. The following command builds a container image for the album UI and tags it with the fully qualified name of the ACR log in server. The `.` at the end of the command represents the docker build context, meaning this command should be run within the *src* folder where the Dockerfile is located.
128+
129+
# [Bash](#tab/bash)
130+
131+
```azurecli
132+
docker build --tag $ACR_NAME.azurecr.io/albumapp-ui .
133+
```
134+
135+
# [PowerShell](#tab/powershell)
136+
137+
```powershell
138+
docker build --tag $ACR_NAME.azurecr.io/albumapp-ui .
139+
```
140+
141+
---
142+
143+
## Push the image to your ACR registry
144+
145+
1. First, sign in to your Azure Container Registry.
146+
147+
# [Bash](#tab/bash)
148+
149+
```azurecli
150+
az acr login --name $ACR_NAME
151+
```
152+
153+
# [PowerShell](#tab/powershell)
154+
155+
```powershell
156+
az acr login --name $ACR_NAME
157+
```
158+
159+
---
160+
161+
1. Now, push the image to your registry.
162+
163+
# [Bash](#tab/bash)
164+
165+
```azurecli
166+
docker push $ACR_NAME.azurecr.io/albumapp-ui .
167+
```
168+
169+
# [PowerShell](#tab/powershell)
170+
171+
```powershell
172+
docker push $ACR_NAME.azurecr.io/albumapp-ui .
173+
```
174+
175+
---
176+
177+
::: zone-end
178+
179+
## Communicate between container apps
180+
181+
In the previous quickstart, the album API was deployed by creating a container app and enabling external ingress. Setting the container app's ingress to *external* made its HTTP endpoint URL publicly available.
182+
183+
Now you can configure the front end application to call the API endpoint by going through the following steps:
184+
185+
* Query the API application for its fully qualified domain name (FQDN).
186+
* Pass the API FQDN to `az containerapp create` as an environment variable so the UI app can set the base URL for the album API call within the code.
187+
188+
The [UI application](https://github.com/Azure-Samples/containerapps-albumui) uses the endpoint provided to invoke the album API. The following code is an excerpt from the code used in the *routes > index.js* file.
189+
190+
```javascript
191+
const api = axios.create({
192+
baseURL: process.env.API_BASE_URL,
193+
params: {},
194+
timeout: process.env.TIMEOUT || 5000,
195+
});
196+
```
197+
198+
Notice how the `baseURL` property gets its value from the `API_BASE_URL` environment variable.
199+
200+
Run the following command to query for the API endpoint address.
201+
202+
# [Bash](#tab/bash)
203+
204+
```azurecli
205+
API_BASE_URL=$(az containerapp show --resource-group $RESOURCE_GROUP --name $API_NAME --query properties.configuration.ingress.fqdn -o tsv)
206+
```
207+
208+
# [PowerShell](#tab/powershell)
209+
210+
```powershell
211+
$API_BASE_URL=$(az containerapp show --resource-group $RESOURCE_GROUP --name $API_NAME --query properties.configuration.ingress.fqdn -o tsv)
212+
```
213+
214+
---
215+
216+
Now that you have set the `API_BASE_URL` variable with the FQDN of the album API, you can provide it as an environment variable to the frontend container app.
217+
218+
## Deploy front end application
219+
220+
Create and deploy your container app with the following command.
221+
222+
# [Bash](#tab/bash)
223+
224+
```azurecli
225+
az containerapp create \
226+
--name $FRONTEND_NAME \
227+
--resource-group $RESOURCE_GROUP \
228+
--environment $ENVIRONMENT \
229+
--image $ACR_NAME.azurecr.io/albumapp-ui \
230+
--target-port 3000 \
231+
--env-vars API_BASE_URL=https://$API_BASE_URL \
232+
--ingress 'external' \
233+
--registry-server $ACR_NAME.azurecr.io \
234+
--query configuration.ingress.fqdn
235+
```
236+
237+
# [PowerShell](#tab/powershell)
238+
239+
```azurecli
240+
az containerapp create `
241+
--name $FRONTEND_NAME `
242+
--resource-group $RESOURCE_GROUP `
243+
--environment $ENVIRONMENT `
244+
--image $ACR_NAME.azurecr.io/albumapp-ui `
245+
--env-vars API_BASE_URL=https://$API_BASE_URL `
246+
--target-port 3000 `
247+
--ingress 'external' `
248+
--registry-server "$ACR_NAME.azurecr.io" `
249+
--query configuration.ingress.fqdn
250+
```
251+
252+
---
253+
254+
By adding the argument `--env-vars "API_BASE_URL=https://$API_ENDPOINT"` to `az containerapp create`, you define an environment variable for your front end application. With this syntax, the environment variable named `API_BASE_URL` is set to the API's FQDN.
255+
256+
## View website
257+
258+
The `az containerapp create` CLI command returns the fully qualified domain name (FQDN) of your album UI container app. Open this location in a browser to navigate to the web application resembling the following screenshot.
259+
260+
:::image type="content" source="media/communicate-between-microservices/azure-container-apps-album-ui.png" alt-text="Screenshot of album list UI microservice.":::
261+
262+
## Clean up resources
263+
264+
If you're not going to continue to use this application, run the following command to delete the resource group along with all the resources created in this quickstart.
265+
266+
# [Bash](#tab/bash)
267+
268+
```azurecli
269+
az group delete --name $RESOURCE_GROUP
270+
```
271+
272+
# [PowerShell](#tab/powershell)
273+
274+
```powershell
275+
az group delete --name $RESOURCE_GROUP
276+
```
277+
278+
---
279+
280+
> [!TIP]
281+
> Having issues? Let us know on GitHub by opening an issue in the [Azure Container Apps repo](https://github.com/microsoft/azure-container-apps).
282+
283+
## Next steps
284+
285+
> [!div class="nextstepaction"]
286+
> [Environments in Azure Container Apps](environment.md)

articles/container-apps/deploy-visual-studio-code.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Now that you have a container app environment in Azure you can create a containe
120120

121121
9) Choose **External** to configure the HTTP traffic that the endpoint will accept.
122122

123-
10) Enter a value of 3000 for the port, and then select **Enter** to complete the workflow. This value should be set to the port number that your container uses, which in the case of the sample app is 3000.
123+
10) Enter a value of 3500 for the port, and then select **Enter** to complete the workflow. This value should be set to the port number that your container uses, which in the case of the sample app is 3500.
124124

125125
During this process, Visual Studio Code and Azure create the container app for you. The published Docker image you created earlier is also be deployed to the app. Once this process finishes, Visual Studio Code displays a notification with a link to browse to the site. Click this link, and to view your app in the browser.
126126

91.1 KB
Loading
84.2 KB
Loading

0 commit comments

Comments
 (0)