Skip to content

epomatti/azure-containerapps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Azure Container Apps

Serverless micro-services on Azure with Container Apps with Dapr integration.

As per Microsoft documentation on networking for Container Apps:

When you call another container in the same environment using the FQDN, the network traffic never leaves the environment.

Deploy

Register these providers if they have never been used:

az provider register --namespace Microsoft.App
az provider register --namespace Microsoft.OperationalInsights

Simply run the following to start the environment:

cd infra

terraform init
terraform apply -auto-approve

If you prefer, customize the inputs by creating a .auto.tfvars.

Testing liveness from external:

curl "https://<containerapp-orders-fqdn>/liveness"

Testing the endpoint:

curl -d '{"orderId":"ORD-00001"}' -H "Content-Type: application/json" -X POST "<containerapp-orders-fqdn>/api/orders"

Self-Hosted Dapr

Create the application insights resource for local testing:

az group create -n "rg-containerapps-dev" -l "eastus"
az monitor log-analytics workspace create -g "rg-containerapps-dev" -n "log-containerapps-dev" -l "eastus"
az monitor app-insights component create --app "appi-containerapps-dev" -g "rg-containerapps-dev" --workspace "log-containerapps-dev" -l "eastus"
az monitor app-insights component show --app "appi-containerapps-dev" -g "rg-containerapps-dev" --query "connectionString" -o tsv

Create a .env file for each of the two node apps.

Order:

DAPR_APP_PORT="3000"
DAPR_HTTP_PORT="3500"
APPLICATIONINSIGHTS_CONNECTION_STRING="..."

Delivery:

DAPR_APP_PORT="3100"
DAPR_HTTP_PORT="3501"
APPLICATIONINSIGHTS_CONNECTION_STRING="..."

Start the services:

# Start RabbitMQ
docker run -d -p 5672:5672 --name dtc-rabbitmq rabbitmq

cd delivery

# Delivery
dapr run \
  --app-id delivery \
  --app-port 3100 \
  --app-protocol http \
  --dapr-http-port 3501 \
  --components-path ../components \
  npm run dev

cd orders

# Orders Dapr
dapr run \
  --app-id order \
  --app-port 3000 \
  --app-protocol http \
  --dapr-http-port 3500 \
  --components-path ../components \
  npm run dev

To test it, send a message to the queue:

curl -d '{"orderId":"ORD-00001"}' -H "Content-Type: application/json" -X POST "http://localhost:3000/api/orders"

Publishing directly to the topic:

dapr publish --publish-app-id order --pubsub order-pub-sub --topic orders --data '{"orderId": "100"}'

Docker commands

To publish container changes:

cd services

docker build ./order -t epomatti/azure-containerapps-order
docker build ./delivery -t epomatti/azure-containerapps-delivery

docker login --username=<username>

docker push epomatti/azure-containerapps-order
docker push epomatti/azure-containerapps-delivery

Clean-up

terraform destroy -auto-approve

References