Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions 00-setup-your-environment/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# 00 - Setup your environment

__This guide is part of the [Azure Spring Apps training](../README.md)__
__This guide is part of the [Azure Container Apps training](../README.md)__

In this section, we'll set up everything you need to expeditiously complete the training.

---

## Creating Azure Resources

To save time, we provide an ARM template for creating all the Azure resources you will need for this lab other than the Azure Spring Apps instance itself. Use the Deploy to Azure button below.
To save time, we provide an ARM template for creating all the Azure resources you will need for this lab other than the Azure Container Apps environment itself. Use the Deploy to Azure button below.

> 💡 Use the following settings for deploying the Azure Template:
>
> * Create a new resource group.
> * In the location field, select the nearest region from [the list of regions where Azure Spring Apps is available](https://azure.microsoft.com/global-infrastructure/services/?products=spring-apps&regions=all).
> * In the location field, select the nearest region from [the list of regions where Azure Container Apps is available](https://azure.microsoft.com/explore/global-infrastructure/products-by-region/?products=container-apps).
> * Save the MySQL password you specify in this step. You will need it in section 6. If you don't set one, it will be `super$ecr3t`.

[![Deploy to Azure](media/deploybutton.svg)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fmicrosoft%2Fazure-spring-cloud-training%2Fmaster%2F00-setup-your-environment%2Fazuredeploy.json?WT.mc_id=asa-java-judubois)
Expand All @@ -37,7 +37,7 @@ This training lab requires the following to be installed on your machine:

> 💡 If you try the command above and you see the error `bash: az: command not found`, run the following command: `alias az='az.cmd'` and try again.

* 🚧 The `spring` extension for Azure CLI. You can install this extension after installing Azure CLI by running `az extension add -n spring -y`. If the extension is already installed, update it to the latest version by running `az extension update -n spring`.
* 🚧 The `containerapp` extension for Azure CLI. You can install this extension after installing Azure CLI by running `az extension add --name containerapp --upgrade`. If the extension is already installed, update it to the latest version by running `az extension update --name containerapp`.

> 💡 In sections 9 and 10, you will access the UI of the Microservice applications in a web browser. Use the [new Edge](https://microsoft.com/edge/?WT.mc_id=java-spring-judubois), Google Chrome, or Firefox for these sections.

Expand All @@ -47,4 +47,4 @@ You can then use Visual Studio Code or an IDE of your choice.

---

➡️ Next guide: [01 - Create an Azure Spring Apps instance](../01-create-an-azure-spring-cloud-instance/README.md)
➡️ Next guide: [01 - Create an Azure Container Apps environment](../01-create-an-azure-spring-cloud-instance/README.md)
37 changes: 19 additions & 18 deletions 01-create-an-azure-spring-cloud-instance/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# 01 - Create an Azure Spring Apps instance
# 01 - Create an Azure Container Apps environment

__This guide is part of the [Azure Spring Apps training](../README.md)__
__This guide is part of the [Azure Container Apps training](../README.md)__

In this section, we'll create an Azure Spring Apps instance using Azure CLI. While there are other ways of creating Azure resources, Azure CLI is the quickest and simplest method.
In this section, we'll create an Azure Container Apps environment using Azure CLI. While there are other ways of creating Azure resources, Azure CLI is the quickest and simplest method.

---

Expand All @@ -20,38 +20,39 @@ az account show # See the currently signed-in account.
Ensure your default subscription is the one you intend to use for this lab, and if not - set the subscription via
```az account set --subscription <SUBSCRIPTION_ID>```

## Create an Azure Spring Apps instance
## Create an Azure Container Apps environment

In this section, we will create our Azure Spring Apps instance using Azure CLI.
In this section, we will create our Azure Container Apps environment using Azure CLI.

First, you will need to come up with a name for your Azure Spring Apps instance.
First, you will need to come up with a name for your Azure Container Apps environment.

- __The name must be unique among all Azure Spring Apps instances across all of Azure__. Consider using your username as part of the name.
- The name can contain only lowercase letters, numbers and hyphens. The first character must be a letter. The last character must be a letter or number. The value must be between 4 and 32 characters long.
- __The name must be unique within your resource group__.
- The name can contain only lowercase letters, numbers and hyphens. The first character must be a letter. The last character must be a letter or number. The value must be between 2 and 32 characters long.

To limit typing, set the variable `AZ_RESOURCE_GROUP` to the name of the resource group created in the previous section. Set the variable `AZ_SPRING_APPS_NAME` to the name of the Azure Spring Apps instance to be created:
To limit typing, set the variable `AZ_RESOURCE_GROUP` to the name of the resource group created in the previous section. Set the variable `AZ_CONTAINERAPP_ENV` to the name of the Azure Container Apps environment to be created:

>🛑 Be sure to substitute your own values for `AZ_RESOURCE_GROUP` and `AZ_SPRING_APPS_NAME` as described above. __`AZ_SPRING_APPS_NAME` must be globally unique, use lowercase letters and should not have special characters.__
>🛑 Be sure to substitute your own values for `AZ_RESOURCE_GROUP` and `AZ_CONTAINERAPP_ENV` as described above.

```bash
export AZ_RESOURCE_GROUP=spring-apps-lab
export AZ_SPRING_APPS_NAME=azure-spring-apps-lab
export AZ_CONTAINERAPP_ENV=aca-env-lab
export AZ_LOCATION=eastus
```

With these variables set, we can now create the Azure Spring Apps instance.
With these variables set, we can now create the Azure Container Apps environment.

```bash
az spring create \
-g "$AZ_RESOURCE_GROUP" \
-n "$AZ_SPRING_APPS_NAME" \
--sku standard
az containerapp env create \
--name "$AZ_CONTAINERAPP_ENV" \
--resource-group "$AZ_RESOURCE_GROUP" \
--location "$AZ_LOCATION"
```

For the remainder of this workshop, we will be running Azure CLI commands referencing the same resource group and Azure Spring Apps instance. So let's set them as defaults, so we don't have to specify them again:
For the remainder of this workshop, we will be running Azure CLI commands referencing the same resource group and Azure Container Apps environment. So let's set them as defaults, so we don't have to specify them again:

```bash
az configure --defaults group=$AZ_RESOURCE_GROUP
az configure --defaults spring=$AZ_SPRING_APPS_NAME
az configure --defaults location=$AZ_LOCATION
```

---
Expand Down
135 changes: 97 additions & 38 deletions 02-build-a-simple-spring-boot-microservice/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# 02 - Build a simple Spring Boot microservice

__This guide is part of the [Azure Spring Apps training](../README.md)__
__This guide is part of the [Azure Container Apps training](../README.md)__

In this section, we'll build a simple Spring boot microservice and deploy it to Azure Spring Apps. This will give us a starting point for adding Spring Cloud technologies in later sections.
In this section, we'll build a simple Spring boot microservice and deploy it to Azure Container Apps. This will give us a starting point for adding Spring Cloud technologies in later sections.

---

Expand Down Expand Up @@ -39,7 +39,7 @@ public class HelloController {

@GetMapping("/hello")
public String hello() {
return "Hello from Azure Spring Apps\n";
return "Hello from Azure Container Apps\n";
}
}
```
Expand All @@ -56,7 +56,7 @@ cd simple-microservice
cd ..
```

Requesting the `/hello` endpoint should return the "Hello from Azure Spring Apps" message.
Requesting the `/hello` endpoint should return the "Hello from Azure Container Apps" message.

```bash
curl http://127.0.0.1:8080/hello
Expand All @@ -68,68 +68,100 @@ Finally, kill running app:
kill %1
```

## Create and deploy the application on Azure Spring Apps
## Create and deploy the application on Azure Container Apps

This section shows how to create an app instance and then deploy your code to it.
This section shows how to build a container image and deploy it to Azure Container Apps.

In order to create the app instance graphically, you can use [the Azure portal](https://portal.azure.com/?WT.mc_id=java-asa-judubois):
First, we need to build the application and create a container image. We'll use Docker to build the container image.

- Look for your Azure Spring Apps instance in your resource group
- Click on the "Apps" link under "Settings" on the navigation sidebar.
- Click on "Create App" link at the top of the Apps page.
- Create a new application named "simple-microservice", using the Java 17 environment.

![Create application](media/00-create-application.png)

- Click on "Create".

Alternatively, you can use the command line to create the app instance, which is easier:
Create a `Dockerfile` in the `simple-microservice` directory:

```bash
az spring app create -n simple-microservice --runtime-version Java_17
cd simple-microservice
cat > Dockerfile << 'EOF'
FROM eclipse-temurin:17-jdk-alpine as build
WORKDIR /workspace/app

COPY mvnw .
COPY .mvn .mvn
COPY pom.xml .
COPY src src

RUN ./mvnw package -DskipTests
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar)

FROM eclipse-temurin:17-jre-alpine
VOLUME /tmp
ARG DEPENDENCY=/workspace/app/target/dependency
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*","com.example.demo.DemoApplication"]
EOF
cd ..
```

You can now build your "simple-microservice" project and deploy it to Azure Spring Apps:
Now build your "simple-microservice" project and deploy it to Azure Container Apps:

```bash
cd simple-microservice
./mvnw clean package
az spring app deploy -n simple-microservice --artifact-path target/demo-0.0.1-SNAPSHOT.jar

# Build and deploy directly to Azure Container Apps
az containerapp up \
--name simple-microservice \
--resource-group $AZ_RESOURCE_GROUP \
--environment $AZ_CONTAINERAPP_ENV \
--source . \
--target-port 8080 \
--ingress external

cd ..
```

This creates a jar file on your local disk and uploads it to the app instance you created in the preceding step. The `az` command will output a result in JSON. You don't need to pay attention to this output right now, but in the future, you will find it useful for diagnostic and testing purposes.
This command builds your application from source, creates a container image, and deploys it to Azure Container Apps with an external ingress endpoint.

## Test the project in the cloud

Go to [the Azure portal](https://portal.azure.com/?WT.mc_id=azurespringcloud-github-judubois):

- Look for your Azure Spring Apps instance in your resource group
- Click "Apps" in the "Settings" section of the navigation pane and select "simple-microservice"
- Find the "Test endpoint" in the "Essentials" section.
![Test endpoint](media/01-test-endpoint.png)
- This will give you something like:
`https://primary:BBQM6nsYnmmdQREXQINityNx63kWUbjsP7SIvqKhOcWDfP6HJTqg27klMLaSfpTB@rwo1106f.test.azuremicroservices.io/simple-microservice/default/`
>💡 Note the text between `https://` and `@`. These are the basic authentication credentials, without which you will not be authorized to access the service.
- Append `hello` to the URL. Failure to do this will result in a "404 not found".
- Look for your Azure Container Apps environment in your resource group
- Click on your container app "simple-microservice"
- Find the "Application Url" in the "Essentials" section.

You can also get the URL using the Azure CLI:

You can now use cURL again to test the `/hello` endpoint, this time served by Azure Spring Apps. For example.
```bash
az containerapp show \
--name simple-microservice \
--resource-group $AZ_RESOURCE_GROUP \
--query properties.configuration.ingress.fqdn \
-o tsv
```

You can now use cURL to test the `/hello` endpoint:

```bash
curl https://primary:...simple-microservice/default/hello
SIMPLE_MICROSERVICE_URL=$(az containerapp show \
--name simple-microservice \
--resource-group $AZ_RESOURCE_GROUP \
--query properties.configuration.ingress.fqdn \
-o tsv)

curl https://$SIMPLE_MICROSERVICE_URL/hello
```

If successful, you should see the message: `Hello from Azure Spring Apps`.
If successful, you should see the message: `Hello from Azure Container Apps`.

## Conclusion

Congratulations, you have deployed your first Spring Boot microservice to Azure Spring Apps!
Congratulations, you have deployed your first Spring Boot microservice to Azure Container Apps!

If you need to check your code, the final project is available in the ["simple-microservice" folder](simple-microservice/).

Here is the final script to build and deploy everything that was done in this guide:

```
```bash
curl https://start.spring.io/starter.tgz -d type=maven-project -d dependencies=web -d baseDir=simple-microservice -d bootVersion=3.1.3 -d javaVersion=17 | tar -xzvf -
cd simple-microservice
cat > HelloController.java << EOF
Expand All @@ -143,19 +175,46 @@ public class HelloController {

@GetMapping("/hello")
public String hello() {
return "Hello from Azure Spring Apps";
return "Hello from Azure Container Apps";
}
}
EOF
mv HelloController.java src/main/java/com/example/demo/HelloController.java
az spring app create -n simple-microservice --runtime-version Java_17

cat > Dockerfile << 'EOF'
FROM eclipse-temurin:17-jdk-alpine as build
WORKDIR /workspace/app

COPY mvnw .
COPY .mvn .mvn
COPY pom.xml .
COPY src src

RUN ./mvnw package -DskipTests
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar)

FROM eclipse-temurin:17-jre-alpine
VOLUME /tmp
ARG DEPENDENCY=/workspace/app/target/dependency
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*","com.example.demo.DemoApplication"]
EOF

./mvnw clean package
az spring app deploy -n simple-microservice --artifact-path target/demo-0.0.1-SNAPSHOT.jar
az containerapp up \
--name simple-microservice \
--resource-group $AZ_RESOURCE_GROUP \
--environment $AZ_CONTAINERAPP_ENV \
--source . \
--target-port 8080 \
--ingress external
cd ..
```

---

⬅️ Previous guide: [01 - Create an Azure Spring Apps instance](../01-create-an-azure-spring-cloud-instance/README.md)
⬅️ Previous guide: [01 - Create an Azure Container Apps environment](../01-create-an-azure-spring-cloud-instance/README.md)

➡️ Next guide: [03 - Configure monitoring](../03-configure-monitoring/README.md)
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public class HelloController {

@GetMapping("/hello")
public String hello() {
return "Hello from Azure Spring Apps\n";
return "Hello from Azure Container Apps\n";
}
}
32 changes: 23 additions & 9 deletions 03-configure-monitoring/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
# 03 - Configure application logs

__This guide is part of the [Azure Spring Apps training](../README.md)__
__This guide is part of the [Azure Container Apps training](../README.md)__

Now that we have an application deployed, we'll configure Log Analytics, so that we can quickly search the application's logs if something goes wrong. We'll see how to take advantage of Log Analytics in a later section, but because it takes time for log entries to start coming in, we'll do the configuration steps here before moving on with the training.

---

## Configure log aggregation

There are actually three ways to access your application's logs: [Azure Storage](https://docs.microsoft.com/en-us/azure/storage/common/storage-introduction/?WT.mc_id=azurespringcloud-github-judubois), [Azure Events Hub](https://docs.microsoft.com/en-us/azure/event-hubs/?WT.mc_id=azurespringcloud-github-judubois), and [Log Analytics](https://docs.microsoft.com/en-us/azure/azure-monitor/log-query/get-started-portal/?WT.mc_id=azurespringcloud-github-judubois). We will focus here on Log Analytics as it's the most common one, and as it's integrated into Azure Spring Apps.
There are actually three ways to access your application's logs: [Azure Storage](https://docs.microsoft.com/en-us/azure/storage/common/storage-introduction/?WT.mc_id=azurespringcloud-github-judubois), [Azure Events Hub](https://docs.microsoft.com/en-us/azure/event-hubs/?WT.mc_id=azurespringcloud-github-judubois), and [Log Analytics](https://docs.microsoft.com/en-us/azure/azure-monitor/log-query/get-started-portal/?WT.mc_id=azurespringcloud-github-judubois). We will focus here on Log Analytics as it's the most common one, and as it's integrated into Azure Container Apps.

[Log Analytics](https://docs.microsoft.com/en-us/azure/azure-monitor/log-query/get-started-portal/?WT.mc_id=azurespringcloud-github-judubois) is part of [Azure Monitor](https://azure.microsoft.com/en-us/services/monitor/?WT.mc_id=azurespringcloud-github-judubois), which is well-integrated into Azure Spring Apps and which we will also use for metrics monitoring.
[Log Analytics](https://docs.microsoft.com/en-us/azure/azure-monitor/log-query/get-started-portal/?WT.mc_id=azurespringcloud-github-judubois) is part of [Azure Monitor](https://azure.microsoft.com/en-us/services/monitor/?WT.mc_id=azurespringcloud-github-judubois), which is well-integrated into Azure Container Apps and which we will also use for metrics monitoring.

Having completed the setup in [Section 00](../00-setup-your-environment/README.md), you should have a Log Analytics workspace named `sclab-la-<unique string>` in your resource group for this workshop. We must now configure our Azure Spring Apps instance to send its data to this workspace.
Having completed the setup in [Section 00](../00-setup-your-environment/README.md), you should have a Log Analytics workspace named `sclab-la-<unique string>` in your resource group for this workshop.

- Navigate to the Azure Spring Apps instance in Azure Portal and select "Diagnostic settings" in the "Monitoring" section of the navigation pane:
Azure Container Apps automatically sends logs to Log Analytics when you create the environment. When you created the Container Apps environment in Section 01, it was automatically configured to use a Log Analytics workspace.

![Diagnostic Settings](media/01-diagnostic-settings.png)
To verify the logs are flowing:

- Click on "Add diagnostic setting" and configure your instance to send all its logs to the Log analytics workspace that we just created.
- Fill in the values as shown here and click "Save".
- Navigate to your Azure Container Apps environment in the Azure Portal
- Select "Logs" in the "Monitoring" section of the navigation pane
- You can now run queries against your container app logs using the Kusto query language

![Send logs to the log analytics workspace](media/02-send-logs-to-log-analytics-workspace.png)
For example, to see recent logs from your simple-microservice:

```kusto
ContainerAppConsoleLogs_CL
| where ContainerAppName_s == "simple-microservice"
| order by TimeGenerated desc
| take 100
```

You can also view logs for individual container apps:

- Navigate to your container app (e.g., "simple-microservice") in the Azure Portal
- Select "Log stream" to see real-time logs
- Or select "Logs" for more advanced querying capabilities

⬅️ Previous guide: [02 - Build a simple Spring Boot microservice](../02-build-a-simple-spring-boot-microservice/README.md)

Expand Down
Loading