Skip to content

Commit d44f19b

Browse files
Merge pull request #267473 from craigshoemaker/aca/java-content
[Container Apps] New: Add Java content
2 parents 8f045fe + da572d0 commit d44f19b

File tree

9 files changed

+517
-20
lines changed

9 files changed

+517
-20
lines changed

articles/container-apps/TOC.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,20 @@
287287
href: network-proxy.md
288288
- name: Use a custom VNET
289289
href: vnet-custom.md
290+
- name: Languages and runtimes
291+
items:
292+
- name: Java
293+
items:
294+
- name: Overview
295+
href: java-overview.md
296+
- name: Automatic memory fitting
297+
href: java-memory-fit.md
298+
- name: Build environment variables
299+
href: java-build-environment-variables.md
300+
- name: Tutorials
301+
items:
302+
- name: Deploy a WAR file
303+
href: java-deploy-war-file.md
290304
- name: Billing & quotas
291305
items:
292306
- name: Billing

articles/container-apps/deploy-artifact.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
---
2-
title: 'Deploy an artifact file to Azure Container Apps'
2+
title: Deploy an artifact file to Azure Container Apps
33
description: Use a prebuilt artifact file to deploy to Azure Container Apps.
44
services: container-apps
55
author: craigshoemaker
66
ms.author: cshoe
77
ms.service: container-apps
88
ms.topic: quickstart
9-
ms.date: 11/15/2023
9+
ms.date: 02/27/2024
1010
ms.custom: ignite-2023, devx-track-azurecli
1111
---
1212

1313
# Quickstart: Deploy an artifact file to Azure Container Apps
1414

15-
This article demonstrates how to deploy a container app from a prebuilt artifact file.
16-
17-
The following example deploys a Java application using a JAR file, which includes a Java-specific manifest file.
18-
19-
In this quickstart, you create a backend web API service that returns a static collection of music albums. After completing this quickstart, you can continue to [Tutorial: Communication between microservices in Azure Container Apps](communicate-between-microservices.md) to learn how to deploy a front end application that calls the API.
15+
In this quickstart, you learn to deploy a container app from a prebuilt artifact file. The example in this article deploys a Java application using a JAR file, which includes a Java-specific manifest file. Your job is to create a backend web API service that returns a static collection of music albums. After completing this quickstart, you can continue to [Communication between microservices](communicate-between-microservices.md) to learn how to deploy a front end application that calls the API.
2016

2117
The following screenshot shows the output from the album API service you deploy.
2218

@@ -30,7 +26,7 @@ The following screenshot shows the output from the album API service you deploy.
3026
| GitHub Account | Get one for [free](https://github.com/join). |
3127
| git | [Install git](https://git-scm.com/downloads) |
3228
| Azure CLI | Install the [Azure CLI](/cli/azure/install-azure-cli).|
33-
| Java | Install the [JDK](/java/openjdk/install), recommend 17 or later|
29+
| Java | Install the [JDK](/java/openjdk/install), recommend 17, or later|
3430
| Maven | Install the [Maven](https://maven.apache.org/download.cgi).|
3531

3632
## Setup
@@ -67,7 +63,7 @@ az upgrade
6763

6864
---
6965

70-
Next, install or update the Azure Container Apps extension for the CLI.
66+
Next, install, or update the Azure Container Apps extension for the CLI.
7167

7268
# [Bash](#tab/bash)
7369

@@ -212,7 +208,7 @@ This command:
212208
- Creates the Container Apps environment with a Log Analytics workspace
213209
- Creates and deploys the container app using a public container image
214210

215-
The `up` command uses the Docker file in the root of the repository to build the container image. The `EXPOSE` instruction in the Docker file defines the target port. A Docker file, however, isn't required to build a container app.
211+
The `up` command uses the Docker file in the root of the repository to build the container image. The `EXPOSE` instruction in the Docker file defines the target port. A Docker file, however, isn't required to build a container app.
216212

217213
> [!NOTE]
218214
> Note: When using `containerapp up` in combination with a Docker-less code base, use the `--location` parameter so that application runs in a location other than US East.
@@ -249,10 +245,14 @@ az containerapp up `
249245

250246
## Verify deployment
251247

252-
Copy the FQDN to a web browser. From your web browser, go to the `/albums` endpoint of the FQDN.
248+
Copy the FQDN to a web browser. From your web browser, go to the `/albums` endpoint of the FQDN.
253249

254250
:::image type="content" source="media/quickstart-code-to-cloud/azure-container-apps-album-api.png" alt-text="Screenshot of response from albums API endpoint.":::
255251

252+
## Deploy a WAR file
253+
254+
You can also deploy your container app from a [WAR file](java-deploy-war-file.md).
255+
256256
## Clean up resources
257257

258258
If you're not going to continue to use this application, you can delete the Azure Container Apps instance and all the associated services by removing the resource group.

articles/container-apps/faq.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ metadata:
88
ms.service: container-apps
99
ms.custom:
1010
- ignite-2023
11-
ms.date: 04/14/2023
11+
ms.date: 02/27/2024
1212
ms.author: cshoe
1313
title: Azure Container Apps frequently asked questions (FAQs)
1414
summary: This article lists commonly asked questions about Azure Container Apps together with related answers.
@@ -120,19 +120,21 @@ sections:
120120
- name: Deploy Java applications
121121
questions:
122122
- question: |
123-
Which JDK versions are supported?
123+
Which JDK versions are supported and how can I configure the JDK version?
124124
answer: |
125125
Container Apps supports four LTS JDK versions: JDK 8, JDK 11, JDK 17 and JDK 21.
126126
For source code build, the default version is JDK 17.
127127
For a JAR file build, the JDK version is read from the file location *META-INF\MANIFEST.MF* in the JAR, but uses the default JDK version 17 if the specified version isn't available.
128+
129+
You can configure JDK version to override the default version via [build environment variables](java-build-environment-variables.md).
128130
- question: |
129131
Which Java build tools are supported?
130132
answer: |
131133
Maven
132134
- question: |
133-
Are build environment variables supported?
135+
How can I customize a Java image build from source code?
134136
answer: |
135-
No. Container Apps automatically selects the Maven version.
137+
You can customize a Java image build via [build environment variables](java-build-environment-variables.md).
136138
- question: |
137139
How do I ensure the build and image of my Docker-less build are available in the same region as my app?
138140
answer: |
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---
2+
title: Build environment variables for Java in Azure Container Apps
3+
description: Learn about Java image build from source code via environment variables.
4+
services: container-apps
5+
author: craigshoemaker
6+
ms.service: container-apps
7+
ms.topic: conceptual
8+
ms.date: 02/27/2024
9+
ms.author: cshoe
10+
---
11+
12+
# Build environment variables for Java in Azure Container Apps
13+
14+
Azure Container Apps uses [Buildpacks](https://buildpacks.io/) to automatically create a container image that allows you to deploy from your source code directly to the cloud. To take control of your build configuration, you can use environment variables to customize parts of your build like the JDK, Maven, and Tomcat. The following article shows you how to configure environment variables to help you take control over builds that automatically create a container for you.
15+
16+
## Supported Java build environment variables
17+
18+
### Configure JDK
19+
20+
Container Apps use [Microsoft Build of OpenJDK](https://www.microsoft.com/openjdk) to build source code and as the runtime environment. Four LTS JDK versions are supported: 8, 11, 17 and 21.
21+
22+
- For source code build, the default version is JDK 17.
23+
24+
- For a JAR file build, the JDK version is read from the file location `META-INF\MANIFEST.MF` in the JAR, but uses the default JDK version 17 if the specified version isn't available.
25+
26+
Here's a listing of the environment variables used to configure JDK:
27+
28+
| Environment variable | Description | Default |
29+
|--|--|--|
30+
| `BP_JVM_VERSION` | Controls the JVM version. | `17` |
31+
32+
### Configure Maven
33+
34+
Container Apps supports building Maven-based applications from source.
35+
36+
Here's a listing of the environment variables used to configure Maven:
37+
38+
| Build environment variable | Description | Default |
39+
|--|--|--|
40+
| `BP_MAVEN_VERSION` | Sets the major Maven version. Since Buildpacks only ships a single version of each supported line, updates to the buildpack can change the exact version of Maven installed. If you require a specific minor/patch version of Maven, use the Maven wrapper instead. | `3` |
41+
| `BP_MAVEN_BUILD_ARGUMENTS` | Defines the arguments passed to Maven. The `--batch-mode` is prepended to the argument list in environments without a TTY. | `-Dmaven.test.skip=true --no-transfer-progress package` |
42+
| `BP_MAVEN_ADDITIONAL_BUILD_ARGUMENTS` | Defines extra arguments used (for example, `-DskipJavadoc` appended to `BP_MAVEN_BUILD_ARGUMENTS`) to pass to Maven. | |
43+
| `BP_MAVEN_ACTIVE_PROFILES` | Comma separated list of active profiles passed to Maven. | |
44+
| `BP_MAVEN_BUILT_MODULE` | Designates application artifact that contains the module. By default, the build looks in the root module. | |
45+
| `BP_MAVEN_BUILT_ARTIFACT` | Location of the built application artifact. This value supersedes the `BP_MAVEN_BUILT_MODULE` variable. You can match a single file, multiple files, or a directory through one or more space separated patterns. | `target/*.[ejw]ar` |
46+
| `BP_MAVEN_POM_FILE` | Specifies a custom location to the project's *pom.xml* file. This value is relative to the root of the project (for example, */workspace*). | `pom.xml` |
47+
| `BP_MAVEN_DAEMON_ENABLED` | Triggers the installation and configuration of Apache `maven-mvnd` instead of Maven. Set this value to `true` if you want to the Maven Daemon. | `false` |
48+
| `BP_MAVEN_SETTINGS_PATH` | Specifies a custom location to Maven's *settings.xml* file. | |
49+
| `BP_INCLUDE_FILES` | Colon separated list of glob patterns to match source files. Any matched file is retained in the final image. | |
50+
| `BP_EXCLUDE_FILES` | Colon separated list of glob patterns to match source files. Any matched file is removed from the final image. Any include patterns are applied first, and you can use "exclude patterns" to reduce the files included in the build. | |
51+
| `BP_JAVA_INSTALL_NODE` | Control whether or not a separate Buildpack installs Yarn and Node.js. If set to `true`, the Buildpack checks the app root or path set by `BP_NODE_PROJECT_PATH`. The project path looks for either a *yarn.lock* file, which requires the installation of Yarn and Node.js. If there's a *package.json* file, then the build only requires Node.js. | `false` |
52+
| `BP_NODE_PROJECT_PATH` | Direct the project subdirectory to look for *package.json* and *yarn.lock* files. | |
53+
54+
### Configure Tomcat
55+
56+
Container Apps supports running war file in Tomcat application server.
57+
58+
Here's a listing of the environment variables used to configure Tomcat:
59+
60+
| Build environment variable | Description | Default |
61+
|--|--|--|
62+
| `BP_TOMCAT_CONTEXT_PATH` | The context path where the application is mounted. | Defaults to empty (`ROOT`) |
63+
| `BP_TOMCAT_EXT_CONF_SHA256` | The SHA256 hash of the external configuration package. | |
64+
| `BP_TOMCAT_ENV_PROPERTY_SOURCE_DISABLED` | When set to `true`, the Buildpack doesn't configure `org.apache.tomcat.util.digester.EnvironmentPropertySource`. This configuration option is added to support loading configuration from environment variables and referencing them in Tomcat configuration files. | |
65+
| `BP_TOMCAT_EXT_CONF_STRIP` | The number of directory levels to strip from the external configuration package. | `0` |
66+
| `BP_TOMCAT_EXT_CONF_URI` | The download URI of the external configuration package. | |
67+
| `BP_TOMCAT_EXT_CONF_VERSION` | The version of the external configuration package. | |
68+
| `BP_TOMCAT_VERSION` | Used to configure a specific Tomcat version. Supported Tomcat versions include 8, 9, and 10. | `9.*` |
69+
70+
### Configure Cloud Build Service
71+
72+
Here's a listing of the environment variables used to configure a Cloud Build Service:
73+
74+
| Build environment variable | Description | Default |
75+
|--|--|--|
76+
| `ORYX_DISABLE_TELEMETRY` | Controls whether or not to disable telemetry collection. | `false` |
77+
78+
## How to configure Java build environment variables
79+
80+
You can configure Java build environment variables when you deploy Java application source code via CLI command `az containerapp up`, `az containerapp create`, or `az containerapp update`:
81+
82+
```azurecli
83+
az containerapp up \
84+
--name <CONTAINER_APP_NAME> \
85+
--source <SOURCE_DIRECTORY> \
86+
--build-env-vars <NAME=VALUE NAME=VALUE> \
87+
--resource-group <RESOURCE_GROUP_NAME> \
88+
--environment <ENVIRONMENT_NAME>
89+
```
90+
91+
The `build-env-vars` argument is a list of environment variables for the build, space-separated values in `key=value` format. Here's an example list you can pass in as variables:
92+
93+
```bash
94+
BP_JVM_VERSION=21 BP_MAVEN_VERSION=4 "BP_MAVEN_BUILD_ARGUMENTS=-Dmaven.test.skip=true --no-transfer-progress package"
95+
```
96+
97+
You can also configure the Java build environment variables when you [set up GitHub Actions with Azure CLI in Azure Container Apps](github-actions-cli.md).
98+
99+
```azurecli
100+
az containerapp github-action add \
101+
--repo-url "https://github.com/<OWNER>/<REPOSITORY_NAME>" \
102+
--build-env-vars <NAME=VALUE NAME=VALUE> \
103+
--branch <BRANCH_NAME> \
104+
--name <CONTAINER_APP_NAME> \
105+
--resource-group <RESOURCE_GROUP> \
106+
--registry-url <URL_TO_CONTAINER_REGISTRY> \
107+
--registry-username <REGISTRY_USER_NAME> \
108+
--registry-password <REGISTRY_PASSWORD> \
109+
--service-principal-client-id <appId> \
110+
--service-principal-client-secret <password> \
111+
--service-principal-tenant-id <tenant> \
112+
--token <YOUR_GITHUB_PERSONAL_ACCESS_TOKEN>
113+
```
114+
115+
## Next steps
116+
117+
> [!div class="nextstepaction"]
118+
> [Build and deploy from a repository](quickstart-code-to-cloud.md)
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
title: Deploy a WAR file on Tomcat in Azure Container Apps
3+
description: Learn how to deploy a WAR file on Tomcat in Azure Container Apps.
4+
services: container-apps
5+
author: craigshoemaker
6+
ms.service: container-apps
7+
ms.topic: tutorial
8+
ms.date: 02/27/2024
9+
ms.author: cshoe
10+
---
11+
12+
# Tutorial: Deploy a WAR file on Tomcat in Azure Container Apps
13+
14+
Rather than manually creating a Dockerfile and directly using a container registry, you can deploy your Java application directly from a web application archive (WAR) file. This article demonstrates how to deploy a Java application on Tomcat using a WAR file to Azure Container Apps.
15+
16+
By the end of this tutorial you deploy an application on Container Apps that displays the home page of the Spring PetClinic sample application.
17+
18+
:::image type="content" source="media/java-deploy-war-file/azure-container-apps-petclinic-warfile.png" alt-text="Screenshot of petclinic app.":::
19+
20+
> [!NOTE]
21+
> If necessary, you can specify the Tomcat version in the build environment variables.
22+
23+
## Prerequisites
24+
25+
| Requirement | Instructions |
26+
|--|--|
27+
| Azure account | If you don't have one, [create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).<br<br>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.md?tabs=current) for details. |
28+
| GitHub Account | Get one for [free](https://github.com/join). |
29+
| git | [Install git](https://git-scm.com/downloads) |
30+
| Azure CLI | Install the [Azure CLI](/cli/azure/install-azure-cli).|
31+
| Java | Install the [Java Development Kit](/java/openjdk/install). Use version 17 or later. |
32+
| Maven | Install the [Maven](https://maven.apache.org/download.cgi).|
33+
34+
## Deploy a WAR file on Tomcat
35+
36+
1. Get the sample application.
37+
38+
Clone the Spring PetClinic sample application to your machine.
39+
40+
```bash
41+
git clone https://github.com/spring-petclinic/spring-framework-petclinic.git
42+
```
43+
44+
1. Build the WAR package.
45+
46+
First, change into the *spring-framework-petclinic* folder.
47+
48+
```bash
49+
cd spring-framework-petclinic
50+
```
51+
52+
Then, clean the Maven build area, compile the project's code, and create a WAR file, all while skipping any tests.
53+
54+
```bash
55+
mvn clean package -DskipTests
56+
```
57+
58+
After you execute the build command, a file named *petclinic.war* is generated in the */target* folder.
59+
60+
1. Deploy the WAR package to Azure Container Apps.
61+
62+
Now you can deploy your WAR file with the `az containerapp up` CLI command.
63+
64+
```azurecli
65+
az containerapp up \
66+
--name <YOUR_CONTAINER_APP_NAME> \
67+
--resource-group <YOUR_RESOURCE_GROUP> \
68+
--subscription <YOUR_SUBSCRIPTION>\
69+
--location <LOCATION> \
70+
--environment <YOUR_ENVIRONMENT_NAME> \
71+
--artifact <YOUR_WAR_FILE_PATH> \
72+
--build-env-var BP_TOMCAT_VERSION=10.* \
73+
--ingress external \
74+
--target-port 8080 \
75+
--query properties.configuration.ingress.fqdn
76+
```
77+
78+
> [!NOTE]
79+
> The default Tomcat version is 9. If you need to change the Tomcat version for compatibility with your application, you can use the `--build-env-var BP_TOMCAT_VERSION=<YOUR_TOMCAT_VERSION>` argument to adjust the version number.
80+
81+
In this example, the Tomcat version is set to `10` (including any minor versions) by setting the `BP_TOMCAT_VERSION=10.*` environment variable.
82+
83+
You can find more applicable build environment variables in [Java build environment variables](java-build-environment-variables.md)
84+
85+
1. Verify the app status.
86+
87+
In this example, `containerapp up` command includes the `--query properties.configuration.ingress.fqdn` argument, which returns the fully qualified domain name (FQDN), also known as the app's URL.
88+
89+
View the application by pasting this URL into a browser. Your app should resemble the following screenshot.
90+
91+
:::image type="content" source="media/java-deploy-war-file/azure-container-apps-petclinic-warfile.png" alt-text="Screenshot of petclinic application.":::
92+
93+
## Next steps
94+
95+
> [!div class="nextstepaction"]
96+
> [Java build environment variables](java-build-environment-variables.md)

0 commit comments

Comments
 (0)