Azure Container Apps

Azure Container Apps offers a serverless approach to publishing microservices without the need to use Kubernetes. In this tutorial we demonstrate the publication of two microservices developed using the DevPrime platform.

The implementation of this environment involving two microservices DevPrime and Azure Container Apps will additionally use Azure Container Registry (ACR), Azure Log Analytics, Azure Container Apps Environment, Azure CosmosDB, Azure EventHub services.

The image below demonstrates how the final environment will look after we start all the procedures for creating the environment and publishing the microservices.

Azure Services

Items needed in your environment

  • Install .NET SDK 6 or higher
  • Visual Studio Code
  • An active account on the Microsoft Azure
  • An active account on the platform DevPrime and devloper or enterprise use license.
  • DevPrime CLI installed and active (dp auth)
  • Azure CLI installed and active (az login)
  • Active local Docker
  • Microsoft Powershell installed
  • Microsoft Bicep installed ( az bicep install)
  • GIT

In this article we will use two microservices built by DevPrime and implemented as presented in the article Asynchronous Microservices Communication. You can pre-run the cited example or go straight to the code provided by github.

This project uses powershell and bicep-based scripts to create the Azure Container Apps environment in Azure. You can adapt the scripts as needed.

First steps

a) Run a project clone on github
git clone https://github.com/devprime/azure-container-apps-bicep
b) Check the home folder with the Order and Payment items. Each folder of this folder has a microservice development with the DevPrime platform.
Pasta clonada localmente
c)Enter the ‘order’ folder and add your Devprime license. After executing the command it will change
the file ‘order\src\App\appsettings.json’
dp license
d)Enter the ‘payment’ folder and add your Devprime license. After running it will change
the file ‘payment\src\App\appsettings.json’
dp license

Local database and stream credentials
To run the microservice locically by adding the credentials of a mongodb database and a kafka cluster in the project order and payment project by editing the file ‘appsettings.json’ as example below. At deployment we will use azure environment credentials.

Optionally locate the ‘State’ and ‘Stream’ keys and change the values with mongodb and/or kafka service credentials in the ‘order’ and ‘payment’ folders

code order\src\App\appsettings.json
code payment\src\App\appsettings.json

Running the microservice locally
Enter the order or payment folder and run
.\run.ps1 ou ./run.sh (Linux, macOS)

Exporting microservices configurations
Enter the order folder and run the DevPrime CLI export command to create a deployment file. Repeat the same procedure in the folder and ‘payment’. We’ll copy some parameters.
dp export kubernetes

Now return the root folder and open the files to observe the parameters that will be sent
during Azure Container Apps deployment. View the ‘env:’ key in the files below.
code order\.devprime\kubernetes\deployment.yml
code payment\.devprime\kubernetes\deployment.yml

[Environment variables]
When you run the Order and Payment microservices on the Azure Container Apps instance, you must configure the environment variables. This procedure is very similar to the one used in Docker and Kubernetes and you can have a preview in the image below.
Environment variables

Defining environment variables
a) Edit file 1-docker-build-push.ps1, 2-deploy-azure.ps1, and 3-cleanup.ps1 by set a new value in the $app. Do not use special characters.
b) Edit the deploy\main.bicep file to change the settings of the environment variables.
code deploy\main.bicep
c) Copy the contents of the ‘devprime_app’ key to the ‘order.devprime\kubernetes\deployment.yml’ file in Order and change to the deploy\main.bicep file in the Order microservice key. Note that in main.bicep we will create two instances of Azure Container Apps and you must repeat the pasos in Payment.

// Container Apps: Order
// Container Apps: Payment

In this example we will not change other settings. If you need to set more parameters for your application repeat the procedure the other keys.

Running environment creation in Azure Container Apps
We’ll run the scripts so you can follow up step by step. In the end if all goes well you will already have in the logs the azure container apps url and consult the services in the Azure portal.

a) We will start with the creation of Azure Resource Group, Azure Container Registry (ACR), Docker Build and Push services for the private response in ACR.
.\1-docker-build-push.ps1

b) We will now use bicep to create Azure Container Apps, Azure Container App Environment, Azure CosmosDB, Log Analytics, Event Hubs.
.\2-deploy-azure.ps1

Accessing microservices in Azure Container Apps
In our example when creating the services in Container Apps we are using the option to receive requests (ingress) through a public endpoint.

The urls below are examples of the accesses made available. Get yours.

When you post the Order API it will process the business rule, persistence in mongodb (Azure CosmosDB), and then issue an event through Kafka (Azure EventHub).

The second microservices will govern to the event and carry out its natural processing cycle according to the implemented business rule.

Excluding the entire environment created
To delete all services created in Azure run the script below. Before confirming, make sure about the name of the Resource Group created in this demo
.\3-cleanup.ps1

Suggestion for next steps

  • Automate this process using Azure DevOps, Github…
  • Add a security setting to the API’s display
  • Add an Azure API Management service

To learn more:
Azure Container Apps documentation

How to deploy Azure Container Apps with Bicep

Deploy to Azure Container App from using a CI/CD Azure DevOps

How to Build and Deliver Apps Fast and Scalable with Azure Container Apps

Output connection strings and keys from Azure Bicep

CosmosDB Bicep

Last modified March 10, 2022 (615ec2b)