{"id":18837275,"url":"https://github.com/clarenceb/tutorial-dapr-cli","last_synced_at":"2025-04-14T06:22:20.940Z","repository":{"id":142072116,"uuid":"424395033","full_name":"clarenceb/tutorial-dapr-cli","owner":"clarenceb","description":"Based on tutorial at https://docs.microsoft.com/en-us/azure/container-apps/microservices-dapr","archived":false,"fork":false,"pushed_at":"2022-12-06T23:31:29.000Z","size":26,"stargazers_count":2,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-27T20:11:10.856Z","etag":null,"topics":["azure","containerapps","dapr"],"latest_commit_sha":null,"homepage":"","language":"Bicep","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clarenceb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-03T22:10:15.000Z","updated_at":"2023-02-14T15:16:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"f7360a5b-fb5d-4b1f-b10a-c4d955284e7a","html_url":"https://github.com/clarenceb/tutorial-dapr-cli","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarenceb%2Ftutorial-dapr-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarenceb%2Ftutorial-dapr-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarenceb%2Ftutorial-dapr-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarenceb%2Ftutorial-dapr-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clarenceb","download_url":"https://codeload.github.com/clarenceb/tutorial-dapr-cli/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248830906,"owners_count":21168369,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure","containerapps","dapr"],"created_at":"2024-11-08T02:34:37.342Z","updated_at":"2025-04-14T06:22:20.919Z","avatar_url":"https://github.com/clarenceb.png","language":"Bicep","funding_links":[],"categories":[],"sub_categories":[],"readme":"Microservices with Dapr using the CLI\n=====================================\n\nPrerequisites\n-------------\n\n* [Azure Subscription](https://azure.microsoft.com/en-au/free/)\n* [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli)\n* [k6](https://k6.io/docs/getting-started/installation/) for generating orders\n\nSetup base resources\n--------------------\n\n```sh\nRESOURCE_GROUP=\"containerapps\"\nLOCATION=\"canadacentral\"\nCONTAINERAPPS_ENVIRONMENT=\"containerapps\"\n\naz login\n\naz extension add --name containerapp\naz provider register --namespace Microsoft.App\naz provider show -n Microsoft.App --query registrationState\n\naz group create \\\n  --name $RESOURCE_GROUP \\\n  --location \"$LOCATION\"\n\naz deployment group create \\\n  --name env-create \\\n  -g $RESOURCE_GROUP \\\n  --template-file ./environment.bicep \\\n  --parameters environmentName=$CONTAINERAPPS_ENVIRONMENT\n\naz containerapp env list -o table\naz containerapp env show -n containerapps -g containerapps\naz containerapp env dapr-component list -n containerapps -g containerapps -o table\naz containerapp env dapr-component show -n containerapps -g containerapps --dapr-component-name statestore\n\nDEPLOY_OUTPUTS=$(az deployment group show --name env-create -g $RESOURCE_GROUP --query properties.outputs)\n\nACR_USERNAME=$(echo $DEPLOY_OUTPUTS | jq -r .acrUserName.value)\nACR_PASSWORD=$(echo $DEPLOY_OUTPUTS | jq -r .acrPassword.value)\nACR_LOGIN_SERVER=$(echo $DEPLOY_OUTPUTS | jq -r .acrloginServer.value)\nACR_NAME=$(echo $ACR_LOGIN_SERVER | cut -f1,1 -d .)\nWORKSPACE_CLIENT_ID=$(echo $DEPLOY_OUTPUTS | jq -r .workspaceId.value)\n```\n\nCreate new contaimer images (for displaying a custom message with the the app version)\n--------------------------------------------------------------------------------------\n\n```sh\npushd ~\n\ngit clone https://github.com/clarenceb/quickstarts dapr-quickstarts\ncd dapr-quickstarts/hello-kubernetes/node\n\naz acr build --image hello-k8s-node:v1 \\\n  --registry $ACR_NAME \\\n  --file Dockerfile .\n\ncd ../python\n\naz acr build --image hello-k8s-python:v1 \\\n  --registry $ACR_NAME \\\n  --file Dockerfile .\n\npopd\n```\n\nDeploy the service application (HTTP web server)\n------------------------------------------------\n\n```sh\n# Deploy via Bicep template\naz deployment group create \\\n  --name nodeapp-v1 \\\n  -g $RESOURCE_GROUP \\\n  --template-file ./nodeapp-containerapp.bicep \\\n  --parameters environment_name=$CONTAINERAPPS_ENVIRONMENT \\\n    custom_message=\"v1\" \\\n    image_name=\"$ACR_LOGIN_SERVER/hello-k8s-node:v1\" \\\n    registry_login_server=$ACR_LOGIN_SERVER \\\n    registry_username=$ACR_USERNAME \\\n    registry_password=$ACR_PASSWORD\n\n# Or via CLI\naz containerapp create \\\n  --name nodeapp \\\n  --container-name nodeapp \\\n  --revisions-mode multiple \\\n  --resource-group $RESOURCE_GROUP \\\n  --environment $CONTAINERAPPS_ENVIRONMENT \\\n  --image $ACR_LOGIN_SERVER/hello-k8s-node:v1 \\\n  --registry-server $ACR_LOGIN_SERVER \\\n  --registry-username $ACR_USERNAME \\\n  --registry-password $ACR_PASSWORD \\\n  --env-vars MESSAGE=v1 \\\n  --cpu 0.5 \\\n  --memory 1.0Gi \\\n  --target-port 3000 \\\n  --ingress external \\\n  --min-replicas 1 \\\n  --max-replicas 1 \\\n  --enable-dapr \\\n  --dapr-app-port 3000 \\\n  --dapr-app-id nodeapp \\\n  --dapr-app-protocol http\n\naz containerapp list -o table\naz containerapp revision list -n nodeapp -g $RESOURCE_GROUP -o table\n```\n\nDeploy the client application (headless client)\n-----------------------------------------------\n\nThe [Python App](https://github.com/dapr/quickstarts/tree/master/hello-kubernetes/python) will invoke the NodeApp every second via it's Dapr sidecar via the URI: `http://localhost:{DAPR_PORT}/v1.0/invoke/nodeapp/method/neworder`\n\n```sh\nNODEAPP_INGRESS_URL=\"https://$(az containerapp show -n nodeapp -g $RESOURCE_GROUP --query properties.configuration.ingress.fqdn -o tsv)\"\n\n# Deploy via Bicep template\naz deployment group create \\\n  --name pythonapp \\\n  -g $RESOURCE_GROUP \\\n  --template-file ./pythonapp-containerapp.bicep \\\n  --parameters environment_name=$CONTAINERAPPS_ENVIRONMENT \\\n    image_name=\"$ACR_LOGIN_SERVER/hello-k8s-python:v1\" \\\n    registry_login_server=$ACR_LOGIN_SERVER \\\n    registry_username=$ACR_USERNAME \\\n    registry_password=$ACR_PASSWORD\n\n# Or via CLI\naz containerapp create \\\n  --name pythonapp \\\n  --container-name pythonapp \\\n  --resource-group $RESOURCE_GROUP \\\n  --environment $CONTAINERAPPS_ENVIRONMENT \\\n  --image $ACR_LOGIN_SERVER/hello-k8s-node:v1 \\\n  --registry-server $ACR_LOGIN_SERVER \\\n  --registry-username $ACR_USERNAME \\\n  --registry-password $ACR_PASSWORD \\\n  --cpu 0.5 \\\n  --memory 1.0Gi \\\n  --min-replicas 1 \\\n  --max-replicas 1 \\\n  --enable-dapr \\\n  --dapr-app-id pythonapp \\\n  --dapr-app-protocol http\n\n# Append paraemter `nodeapp_url` if not using Dapr for service discovery\n# nodeapp_url=$NODEAPP_INGRESS_URL/neworder\n\naz containerapp list -o table\naz containerapp revision list -n pythonapp -g $RESOURCE_GROUP -o table\n```\n\nCreate some orders\n------------------\n\n```sh\ncurl -i --request POST --data \"@sample.json\" --header Content-Type:application/json $NODEAPP_INGRESS_URL/neworder\n\ncurl -s $NODEAPP_INGRESS_URL/order | jq\n\naz monitor log-analytics query \\\n  --workspace $WORKSPACE_CLIENT_ID \\\n  --analytics-query \"ContainerAppConsoleLogs_CL | where ContainerAppName_s == 'nodeapp' and (Log_s contains 'persisted' or Log_s contains 'order') | where TimeGenerated \u003e= ago(30m) | project ContainerAppName_s, Log_s, TimeGenerated | order by TimeGenerated desc | take 20\" \\\n  --out table\n\nwatch -n 5 az monitor log-analytics query --workspace $WORKSPACE_CLIENT_ID --analytics-query \"\\\"ContainerAppConsoleLogs_CL | where ContainerAppName_s == 'nodeapp' and (Log_s contains 'persisted' or Log_s contains 'order') | where TimeGenerated \u003e= ago(30m) | project ContainerAppName_s, Log_s, TimeGenerated | order by TimeGenerated desc | take 20\\\"\" --out table\n\n# Or in the Azure Portal, enter this KQL query:\nContainerAppConsoleLogs_CL\n| where ContainerAppName_s == 'nodeapp' and (Log_s contains 'persisted' or Log_s contains 'order')\n| where TimeGenerated \u003e= ago(30m)\n| project ContainerAppName_s, Log_s, TimeGenerated\n| order by TimeGenerated desc\n| take 20\n\n# Note: There is some latency when streaming logs via the CLI. Use the Azure Portal if you want to query logs with less latency.\n\nURL=$NODEAPP_INGRESS_URL/neworder k6 run k6-script.js\n```\n\nDeploy v2 of nodeapp\n--------------------\n\n```sh\n# Deploy via Bicep template\naz deployment group create \\\n  --name nodeapp-v1 \\\n  -g $RESOURCE_GROUP \\\n  --template-file ./nodeapp-containerapp.bicep \\\n  --parameters environment_name=$CONTAINERAPPS_ENVIRONMENT \\\n    custom_message=\"v2\" \\\n    image_name=\"$ACR_LOGIN_SERVER/hello-k8s-node:v1\" \\\n    registry_login_server=$ACR_LOGIN_SERVER \\\n    registry_username=$ACR_USERNAME \\\n    registry_password=$ACR_PASSWORD\n\n# Or via CLI\naz containerapp update \\\n  --name nodeapp \\\n  --container-name nodeapp \\\n  --resource-group $RESOURCE_GROUP \\\n  --image $ACR_LOGIN_SERVER/hello-k8s-node:v1 \\\n  --replace-env-vars MESSAGE=v2 \\\n  --min-replicas 1 \\\n  --max-replicas 1\n\naz containerapp list -o table\naz containerapp revision list -n nodeapp -g $RESOURCE_GROUP -o table\n```\n\nIn the Azure Portal, split traffic 50% to v1 and v2 and send some orders.\n\n```sh\nURL=$NODEAPP_INGRESS_URL/neworder k6 run k6-script.js\n```\n\nInspect the logs via CLI or in the Azure Portal to see round-robin between the two revisions.\n\n```sh\nwatch -n 5 az monitor log-analytics query --workspace $WORKSPACE_CLIENT_ID --analytics-query \"\\\"ContainerAppConsoleLogs_CL | where ContainerAppName_s == 'nodeapp' and (Log_s contains 'persisted' or Log_s contains 'order') | where TimeGenerated \u003e= ago(30m) | project ContainerAppName_s, Log_s, TimeGenerated | order by TimeGenerated desc | take 20\\\"\" --out table\n\n# Or in the Azure Portal, enter this KQL query:\nContainerAppConsoleLogs_CL\n| where ContainerAppName_s == 'nodeapp' and (Log_s contains 'persisted' or Log_s contains 'order')\n| where TimeGenerated \u003e= ago(30m)\n| project ContainerAppName_s, Log_s, TimeGenerated\n| order by TimeGenerated desc\n| take 20\n```\n\nApplication Insights\n--------------------\n\nAfter creating some orders, check the App Insights resource.\n\n* Application Map\n* Performance\n\nCleanup\n-------\n\nCleanup container apps to restart the demo (retaining enviornment and other resources):\n\n```sh\naz deployment group delete --name nodeapp-v1 -g $RESOURCE_GROUP\naz deployment group delete --name pythonapp -g $RESOURCE_GROUP\n\naz containerapp delete --name nodeapp --resource-group $RESOURCE_GROUP --yes\naz containerapp delete --name pythonapp --resource-group $RESOURCE_GROUP --yes\n```\n\nor full cleanup:\n\n```sh\naz group delete \\\n    --resource-group $RESOURCE_GROUP \\\n    --yes\n```\n\nResources\n---------\n\n* [Tutorial: Deploy a Dapr application to Azure Container Apps using the Azure CLI](https://docs.microsoft.com/en-us/azure/container-apps/microservices-dapr)\n* [Hello Kubernetes](https://github.com/dapr/quickstarts/tree/v1.4.0/hello-kubernetes) - Dapr quickstart\n* [Container Apps Preview ARM template API specification](https://docs.microsoft.com/en-us/azure/container-apps/azure-resource-manager-api-spec)\n* [Container apps Bicep specifications for 2022-01-01-preview apiVersion](https://github.com/Azure/azure-rest-api-specs/tree/main/specification/app/resource-manager/Microsoft.App/preview/2022-01-01-preview)\n* [Container apps Bicep specifications for 2022-03-01 apiVersion](https://github.com/Azure/azure-rest-api-specs/tree/main/specification/app/resource-manager/Microsoft.App/stable/2022-03-01)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclarenceb%2Ftutorial-dapr-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclarenceb%2Ftutorial-dapr-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclarenceb%2Ftutorial-dapr-cli/lists"}