Skip to content

Commit a55dbd2

Browse files
authored
Merge branch 'Azure-Samples:main' into main
2 parents 04a6796 + ee429f2 commit a55dbd2

File tree

171 files changed

+2983
-2633
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+2983
-2633
lines changed

.devcontainer/devcontainer.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,17 @@
1010
"version": "latest",
1111
"ppa": "false"
1212
},
13-
"ghcr.io/devcontainers/features/azure-cli:1": {},
13+
"ghcr.io/devcontainers/features/azure-cli:1": {
14+
"extensions": [
15+
"account",
16+
"containerapp",
17+
"serviceconnector-passwordless"
18+
],
19+
"installBicep": true
20+
},
1421
"ghcr.io/devcontainers/features/terraform:1": {},
15-
"ghcr.io/devcontainers/features/docker-in-docker:1": {}
22+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
23+
"ghcr.io/azure/azure-dev/azd:latest": {}
1624
},
1725
"containerEnv": {
1826
"JAVA_HOME": "/usr/lib/jvm/msopenjdk-current"
@@ -33,7 +41,7 @@
3341
// "forwardPorts": [],
3442

3543
// Use 'postCreateCommand' to run commands after the container is created.
36-
// "postCreateCommand": "java -version",
44+
"postCreateCommand": "./.devcontainer/postCreateCommand.sh",
3745

3846
// Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
3947
"remoteUser": "vscode"

.devcontainer/postCreateCommand.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
azd config set alpha.deployment.stacks on
4+
5+
DEV_ENV_FILE="\$HOME/.dev-environment"
6+
7+
cat <<EOT >> "$HOME/.bashrc"
8+
9+
# auto load
10+
if [[ -f "$DEV_ENV_FILE" ]]; then
11+
source "$DEV_ENV_FILE"
12+
fi
13+
14+
saveenv() {
15+
# Check if var_save is set
16+
declare -p | grep -v "declare -[a-z]*r" > "$DEV_ENV_FILE"
17+
}
18+
19+
clearenv() {
20+
echo "" > "$DEV_ENV_FILE"
21+
}
22+
23+
EOT

.github/workflows/azure-dev.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Azd Automation
2+
on:
3+
workflow_dispatch:
4+
5+
# Set up permissions for deploying with secretless Azure federated credentials
6+
# https://learn.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-portal%2Clinux#set-up-azure-login-with-openid-connect-authentication
7+
permissions:
8+
id-token: write
9+
contents: read
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
env:
15+
AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }}
16+
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
17+
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
18+
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
19+
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Install azd
26+
uses: Azure/setup-azd@v1.0.0
27+
28+
- name: Install Az extensions
29+
run: |
30+
az extension add --upgrade -n containerapp --allow-preview true
31+
az extension add --upgrade -n serviceconnector-passwordless --allow-preview true
32+
az version
33+
34+
- name: Set up JDK 17
35+
uses: actions/setup-java@v2
36+
with:
37+
java-version: '17'
38+
distribution: 'adopt'
39+
cache: maven
40+
41+
- name: Log in with Azure (Federated Credentials)
42+
run: |
43+
azd auth login \
44+
--client-id ${{env.AZURE_CLIENT_ID}} \
45+
--federated-credential-provider "github" \
46+
--tenant-id ${{env.AZURE_TENANT_ID}}
47+
48+
- name: Azure login
49+
uses: azure/login@v2
50+
with:
51+
client-id: ${{env.AZURE_CLIENT_ID}}
52+
tenant-id: ${{env.AZURE_TENANT_ID}}
53+
subscription-id: ${{env.AZURE_SUBSCRIPTION_ID}}
54+
55+
- name: Set environment name with timestamp
56+
id: set_env_name
57+
run: |
58+
current_time=$(date +%m%d%H%M)
59+
azure_env_name="${{ env.AZURE_ENV_NAME }}-$current_time"
60+
echo "AZURE_ENV_NAME=$azure_env_name" >> $GITHUB_ENV
61+
echo "azure_env_name is $azure_env_name"
62+
shell: bash
63+
env:
64+
AZURE_ENV_NAME: ${{ env.AZURE_ENV_NAME }}
65+
66+
- name: Provision
67+
run: |
68+
azd up --no-prompt
69+
70+
- name: Show azd environments
71+
run: |
72+
azd env list
73+
azd env get-values

.github/workflows/maven-build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ jobs:
1818

1919
steps:
2020
- uses: actions/checkout@v2
21+
2122
- name: Set up JDK 17
2223
uses: actions/setup-java@v2
2324
with:
2425
java-version: '17'
2526
distribution: 'adopt'
2627
cache: maven
28+
2729
- name: Build with Maven
2830
run: mvn -B package --file src/pom.xml
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Validation Sample Workflow
2+
on:
3+
workflow_dispatch:
4+
5+
permissions:
6+
contents: read
7+
id-token: write
8+
pull-requests: write
9+
10+
jobs:
11+
template_validation_job:
12+
runs-on: ubuntu-latest
13+
name: template validation
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
# https://github.com/microsoft/template-validation-action
18+
- uses: microsoft/template-validation-action@v0.3.2
19+
id: validation
20+
with:
21+
validateAzd: true
22+
useDevContainer: true
23+
env:
24+
AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }}
25+
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
26+
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
27+
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
28+
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
31+
- name: print result
32+
run: cat ${{ steps.validation.outputs.resultFile }}

LICENSE.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
MIT License
1+
MIT License
22

3-
Copyright (c) Microsoft Corporation.
3+
Copyright (c) Microsoft Corporation.
44

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
1111

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
1414

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE

LabTips.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: 'Lab Tips and troubleshooting'
3-
layout: default
4-
nav_order: 13
3+
layout: home
4+
nav_order: 14
55
---
66

77
# A couple of tips when you run this lab

README.md

Lines changed: 122 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,138 @@
1-
# Lab: Deploying and running Java Applications in Azure Container Apps
1+
# Deploying and running Java Applications with AI in Azure Container Apps
22

3-
This lab teaches you how to deploy the [Spring Petclinic Microservices](https://github.com/Azure-Samples/java-microservices-aca-lab/tree/main/src) application to Azure container apps and integrate it with additional Azure services.
3+
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/Azure-Samples/java-microservices-aca-lab)
4+
[![Open in Dev Containers](https://img.shields.io/static/v1?style=for-the-badge&label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/azure-samples/java-microservices-aca-lab)
45

5-
## Modules
6+
This project shows how to deploy the [Spring Petclinic Microservices](https://github.com/Azure-Samples/java-microservices-aca-lab/tree/main/src) application with OpenAI to [Azure Container Apps](https://learn.microsoft.com/azure/container-apps/overview) and integrate it with additional Azure services, also some samples for Azure Container Apps features.
67

7-
This lab has modules on:
8+
[Features](#features)[Gettting Started](#getting-started)[Guidance](#guidance)
89

9-
* Plan a Java application migration to Azure Container Apps
10-
* Migrate a Spring Apps microservices application to Azure Container Apps
11-
* Enable monitoring and end-to-end tracing
12-
* Secure application secrets.
13-
* Protect endpoints using Web Application Firewalls
14-
* Secure MySQL database and Key Vault using a Private Endpoint
10+
![main page](./images/api-gateway-main.png)
1511

16-
The lab is available as GitHub pages [here](https://azure-samples.github.io/java-microservices-aca-lab/)
12+
## Important Security Notice
13+
14+
This template, the application code and configuration it contains, has been built to showcase Microsoft Azure specific services and tools. We strongly advise our customers not to make this code part of their production environments without implementing or enabling additional security features.
15+
16+
For a more comprehensive list of best practices and security recommendations for Intelligent Applications, visit [Azure security best practices and patterns](https://learn.microsoft.com/en-us/azure/security/fundamentals/best-practices-and-patterns), [Azure security baseline for Intelligent Recommendations](https://learn.microsoft.com/en-us/security/benchmark/azure/baselines/intelligent-recommendations-security-baseline)
17+
18+
## Features
19+
20+
The following technologies are part of the project:
21+
22+
* Java 17
23+
* Maven
24+
* [Azure CLI](https://learn.microsoft.com/en-us/cli/azure/)
25+
* [Azure Developer CLI (azd)](https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/)
26+
27+
This project provides the following features:
28+
29+
* A [Spring Petclinic Microservices](https://github.com/Azure-Samples/java-microservices-aca-lab/tree/main/src) deployment on Azure Container Apps with AI chat agent.
30+
* Azure Container Apps java components ([eureka server](https://learn.microsoft.com/en-us/azure/container-apps/java-eureka-server-usage) /[config server](https://learn.microsoft.com/en-us/azure/container-apps/java-config-server-usage) / [spring boot admin](https://learn.microsoft.com/en-us/azure/container-apps/java-admin-for-spring-usage)) support.
31+
* [Bicep files](https://docs.microsoft.com/azure/azure-resource-manager/bicep/) for provisioning Azure resources, including Azure OpenAI, Azure Container Apps, Azure Database for MySQL - Flexible Server, Azure Container Registry, Azure Log Analytics, Azure Application Insights and RBAC roles. See [Deploy to Azure automatically](https://azure-samples.github.io/java-microservices-aca-lab/docs/06_lab_automation/06_openlab_automation.html).
32+
* Best practices to build [more secure](https://azure-samples.github.io/java-microservices-aca-lab/docs/07_lab_security/07_openlab_security_aca.html), [more reliable](https://azure-samples.github.io/java-microservices-aca-lab/docs/10_lab_reliable_application/10_reliable_java_aca.html) and [more flexible](https://azure-samples.github.io/java-microservices-aca-lab/docs/11_lab_scale/11_openlab_scale_aca.html) java apps on Azure Container Apps.
33+
* AI chat agent to take advantage of large-scale, generative AI models with deep understandings of language and code to enable new reasoning and comprehension capabilities. See [Integrate with Azure OpenAI](https://azure-samples.github.io/java-microservices-aca-lab/docs/05_lab_openai/05_openlab_openai_aca.html)
34+
35+
![Screenshot of the chat app](./images/acalab-ai-chat.png)
36+
37+
### Architecture Diagram
38+
39+
![Architecture Diagram](./images/acalab-overview.png)
1740

1841
## Getting Started
1942

43+
You have a few options for getting started with this template.
44+
45+
* [GitHub codespace](#github-codespaces)
46+
* [Visual Studio Code with remote containers option](#vs-code-dev-containers)
47+
* [Local Development](#local-environment)
48+
49+
All the steps of this lab have been tested in the GitHub CodeSpace. This is the preferred option for running this lab!
50+
51+
### GitHub Codespaces
52+
53+
* Prepare the environment following the steps in [Using a GitHub codespace](https://azure-samples.github.io/java-microservices-aca-lab/install.html#using-a-github-codespace)
54+
* Continue with [deploying steps](#deploying)
55+
56+
### VS Code Dev Containers
57+
58+
* Prepare the environment following the steps in [Using Visual Studio Code with remote containers](https://azure-samples.github.io/java-microservices-aca-lab/install.html#using-a-github-codespace)
59+
* Continue with [deploying steps](#deploying)
60+
61+
### Local Environment
62+
63+
* Prepare the environment following the steps in [Install all the tools on your local machine](https://azure-samples.github.io/java-microservices-aca-lab/install.html#install-all-the-tools-on-your-local-machine)
64+
* Continue with [deploying steps](#deploying)
65+
66+
### Deploying
67+
68+
Once you've opened the project in [Codespaces](#github-codespaces), in [Dev Containers](#vs-code-dev-containers), or [locally](#local-environment), you can deploy it to Azure.
69+
70+
* Your Azure account must have `Microsoft.Authorization/roleAssignments/write` permissions, such as [Role Based Access Control Administrator](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#role-based-access-control-administrator-preview), [User Access Administrator](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#user-access-administrator), or [Owner](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#owner). If you don't have subscription-level permissions, you must be granted [RBAC](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#role-based-access-control-administrator-preview) for an existing resource group and [deploy to that existing group](./docs/06_lab_automation/0604.md).
71+
* Your Azure account also needs `Microsoft.Resources/deployments/write` permissions on the subscription level.
72+
73+
Suggested: Both **Contributor** and **User Access Administrator** roles on the subscription.
74+
75+
1. Login to Azure
76+
77+
`azd auth login`
78+
79+
`az login`
80+
81+
1. Provision and deploy all the resources:
82+
83+
`azd up`
84+
85+
It will prompt you to provide an `azd` environment name (like "java-ai"), select a subscription from your Azure account, and select a [location where OpenAI is available](#region-availability) (like "eastus2"). Then it will provision the resources in your account and deploy the latest code. If you get an error or timeout with deployment, changing the location can help, as there may be availability constraints for the OpenAI resource.
86+
87+
1. When azd has finished deploying, visit the api-gateway url and begin your experience on AI java apps.
88+
89+
```text
90+
INFO: Deploy finish succeed!
91+
INFO: Api Gateway App url: https://api-gateway.<cluster>.<region>.azurecontainerapps.io
92+
INFO: Spring Boot Admin url: https://springbootadmin-azure-java.ext.<cluster>.<region>.azurecontainerapps.io
93+
```
94+
95+
1. When you've made any changes to the app code, you can just run:
96+
97+
- `azd deploy` for all services
98+
99+
- `azd deploy -n <service>` for single service
100+
101+
102+
103+
## Guidance
104+
20105
### Prerequisites
21106

22107
For running this lab you will need:
23108

24-
- A GitHub account
25-
- An Azure Subscription
109+
* A GitHub account
110+
* An Azure Subscription
111+
112+
### Region Availability
113+
114+
1. This template uses [Azure OpenAI Service](https://learn.microsoft.com/en-us/azure/ai-services/openai/overview) deployment mododules **gpt-4o** and **text-embedding-ada-002** which may not be available in all Azure regions. Check for [up-to-date region availability](https://learn.microsoft.com/azure/ai-services/openai/concepts/models#standard-deployment-model-availability) and select a region during deployment accordingly
115+
116+
1. The template uses [Azure Database for MySQL - Flexible Server](https://learn.microsoft.com/en-us/azure/mysql/flexible-server/overview) version 8.0 to store data. You may select a region suite for this service. Or create a database instance manually then [Reuse existing service](https://azure-samples.github.io/java-microservices-aca-lab/docs/06_lab_automation/0604.html).
117+
118+
* We recommend using **East US**, **East US 2**, **North Central US**, **Sweden Central**.
119+
120+
### Costs
121+
122+
You can estimate the cost of this project's architecture with [Azure's pricing calculator](https://azure.microsoft.com/pricing/calculator/)
123+
124+
* Azure Container Apps - [Consumption](https://azure.microsoft.com/en-us/pricing/details/container-apps/)
125+
* Azure Database for MySQL - [Flexible Server](https://azure.microsoft.com/en-us/pricing/details/mysql/)
126+
* Azure OpenAI Service - [Standard](https://azure.microsoft.com/en-us/pricing/details/cognitive-services/openai-service/)
127+
* Azure Monitor - [Analytics Logs](https://azure.microsoft.com/en-us/pricing/details/monitor/)
128+
129+
### Security
26130

27-
### Installation
131+
This template has [Managed Identity](https://learn.microsoft.com/entra/identity/managed-identities-azure-resources/overview) built in to eliminate the need for developers to manage these credentials.
28132

29-
For running this lab with all the needed tooling, there are 3 options available:
133+
Applications can use managed identities to obtain Microsoft Entra tokens without having to manage any credentials. Additionally, we have added a [GitHub Action tool](https://github.com/microsoft/security-devops-action) that scans the infrastructure-as-code files and generates a report containing any detected issues. To ensure best practices in your repo we recommend anyone creating solutions based on our templates ensure that the [Github secret scanning](https://docs.github.com/code-security/secret-scanning/about-secret-scanning) setting is enabled in your repos.
30134

31-
- Using a GitHub codespace
32-
- Using Visual Studio Code with remote containers option
33-
- Install all the tools on your local machine
135+
## Resources
34136

35-
Full installation guidance and options for running this lab can be found in the [Installation instructions](install.md).
137+
* Go to the lab for more details [Deploying and running Java Applications with AI in Azure Container Apps](https://azure-samples.github.io/java-microservices-aca-lab/)
138+
* Full installation guidance and options for running this lab can be found in the [Installation instructions](install.md).

0 commit comments

Comments
 (0)