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
# Quickstart: Build and deploy from local source code to Azure Container Apps
18
16
19
17
This article demonstrates how to build and deploy a microservice to Azure Container Apps from local source code using the programming language of your choice. In this quickstart, you create a backend web API service that returns a static collection of music albums.
20
18
21
-
> [!NOTE]
22
-
> This sample application is available in two versions. One version where the source contains a Dockerfile. The other version has no Dockerfile. Select the version that best reflects your source code. If you are new to containers, select the **No Dockerfile** option at the top.
23
-
24
19
The following screenshot shows the output from the album API service you deploy.
25
20
26
21
:::image type="content" source="media/quickstart-code-to-cloud/azure-container-apps-album-api.png" alt-text="Screenshot of response from albums API endpoint.":::
@@ -32,220 +27,207 @@ To complete this project, you need the following items:
32
27
| Requirement | Instructions |
33
28
|--|--|
34
29
| Azure account | If you don't have one, [create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F). You need the *Contributor* or *Owner* permission on the Azure subscription to proceed. <br><br>Refer to [Assign Azure roles using the Azure portal](../role-based-access-control/role-assignments-portal.yml?tabs=current) for details. |
Extract the download and change into the *containerapps-albumapi-java-buildpack* folder.
141
+
# [Java](#tab/java)
124
142
125
-
> [!NOTE]
126
-
> The Java Buildpack uses [Maven](https://maven.apache.org/what-is-maven.html) with default settings to build your application. Alternatively, you can the [use `--build-env-vars` parameter to configure the image build from source code](java-build-environment-variables.md).
Build and deploy your first container app with the `containerapp up` command. This command will:
173
+
First, run the following command to create the resource group that will contain the resources you create in this quickstart.
151
174
152
-
::: zone pivot="with-dockerfile"
153
-
- Create the resource group
154
-
- Create an Azure Container Registry
155
-
- Build the container image and push it to the registry
156
-
- Create the Container Apps environment with a Log Analytics workspace
157
-
- Create and deploy the container app using the built container image
158
-
::: zone-end
175
+
# [Bash](#tab/bash)
159
176
160
-
::: zone pivot="without-dockerfile"
161
-
- Create the resource group
162
-
- Create a default registry as part of your environment
163
-
- Detect the language and runtime of your application and build the image using the appropriate Buildpack
164
-
- Push the image into the Azure Container Apps default registry
165
-
- Create the Container Apps environment with a Log Analytics workspace
166
-
- Create and deploy the container app using the built container image
167
-
::: zone-end
177
+
```bash
178
+
az group create --name $RESOURCE_GROUP --location $LOCATION
179
+
```
168
180
169
-
::: zone pivot="with-dockerfile"
181
+
# [PowerShell](#tab/powershell)
170
182
171
-
The `up` command uses the Dockerfile in the root of the repository to build the container image. The `EXPOSE` instruction in the Dockerfile defined the target port, which is the port used to send ingress traffic to the container.
183
+
```powershell
184
+
az group create --name $RESOURCE_GROUP --location $LOCATION
185
+
```
172
186
173
-
::: zone-end
174
-
::: zone pivot="without-dockerfile"
187
+
---
175
188
176
-
If the `up` command doesn't find a Dockerfile, it automatically uses Buildpacks to turn your application source into a runnable container. Since the Buildpack is trying to run the build on your behalf, you need to tell the `up` command which port to send ingress traffic to.
189
+
Build and deploy your first container app with the `containerapp up` command. This command will:
177
190
178
-
::: zone-end
191
+
- Create the resource group
192
+
- Create an Azure Container Registry
193
+
- Build the container image and push it to the registry
194
+
- Create the Container Apps environment with a Log Analytics workspace
195
+
- Create and deploy the container app using the built container image
179
196
197
+
The `up` command uses the Dockerfile in project folder to build the container image. The `EXPOSE` instruction in the Dockerfile defines the target port, which is the port used to send ingress traffic to the container.
180
198
181
-
In the following code example, the `.` (dot) tells `containerapp up` to run in the current directory of the extracted sample API application.
199
+
In the following code example, the `.` (dot) tells `containerapp up` to run in the current directory of the project that also contains the Dockerfile.
182
200
183
201
# [Bash](#tab/bash)
184
202
185
-
::: zone pivot="with-dockerfile"
186
-
187
-
```azurecli
188
-
az containerapp up \
189
-
--name $API_NAME \
190
-
--location $LOCATION \
191
-
--environment $ENVIRONMENT \
192
-
--source .
193
-
```
194
-
195
-
::: zone-end
196
-
::: zone pivot="without-dockerfile"
197
-
198
-
```azurecli
203
+
```bash
199
204
az containerapp up \
200
205
--name $API_NAME \
206
+
--resource-group $RESOURCE_GROUP \
201
207
--location $LOCATION \
202
208
--environment $ENVIRONMENT \
203
-
--ingress external \
204
-
--target-port 8080 \
205
209
--source .
206
210
```
207
-
> [!IMPORTANT]
208
-
> In order to deploy your container app to an existing resource group, include `--resource-group yourResourceGroup` to the `containerapp up` command.
209
-
210
-
::: zone-end
211
-
212
-
213
-
# [Azure PowerShell](#tab/azure-powershell)
214
-
215
-
::: zone pivot="with-dockerfile"
216
-
217
-
```powershell
218
-
az containerapp up `
219
-
--name $API_NAME `
220
-
--resource-group $RESOURCE_GROUP `
221
-
--location $LOCATION `
222
-
--environment $ENVIRONMENT `
223
-
--source .
224
-
```
225
211
226
-
::: zone-end
227
-
::: zone pivot="without-dockerfile"
212
+
# [PowerShell](#tab/powershell)
228
213
229
214
```powershell
230
215
az containerapp up `
231
216
--name $API_NAME `
232
217
--resource-group $RESOURCE_GROUP `
233
218
--location $LOCATION `
234
219
--environment $ENVIRONMENT `
235
-
--ingress external `
236
-
--target-port 8080 `
237
220
--source .
238
221
```
239
222
240
-
::: zone-end
241
-
242
-
243
223
---
244
224
225
+
> [!NOTE]
226
+
> If the command returns an error with the message "AADSTS50158: External security challenge not satisfied", run `az login --scope https://graph.microsoft.com//.default` to log in with the required permissions and then run the `az containerapp up` command again.
245
227
246
228
## Verify deployment
247
229
248
-
Copy the FQDN to a web browser. From your web browser, go to the `/albums`endpoint of the FQDN.
230
+
Locate the container app's URL in the output of the `az containerapp up` command. Navigate to the URL in your browser. Add `/albums`to the end of the URL to see the response from the API.
249
231
250
232
:::image type="content" source="media/quickstart-code-to-cloud/azure-container-apps-album-api.png" alt-text="Screenshot of response from albums API endpoint.":::
251
233
@@ -262,11 +244,11 @@ If you're not going to continue on to the [Deploy a frontend](communicate-betwee
0 commit comments