The repo demonstrates Azure SDK usage via a complete application. This application takes in an image, uploads it to Blog Storage and enqueues a message into a Queue. A process receives that message and uses Form Recognizer to extract the text from the image, then uses Text Analytics to get the sentiment of the text, and then stores the results in a Cosmos DB.
The following are required to run this application.
- A Terminal - We tested this with Git Bash and WSL - it will not currently work with PowerShell or Windows Command Prompt. The Terraform deployment currently only works on Linux compatible systems. You will need to run all the commands below in your selected terminal.
- Install Azure CLI
- Install Terraform
- Install Git
- Install VS Code
- Install Docker
- An Azure Subscription
The following Azure resources will be deployed with the Terraform script.
- Resource Group
- Storage Account
- Cognitive Services Form Recognizer
- Cognitive Services Text Analytics
- Cosmos DB
- Key Vault
- Azure Kubernetes Service
- Application Insights
- Open Git Bash or WSL - The same terminal you used to install the pre-reqs above.
- Clone Repo
git clone https://github.com/jongio/azsdkdemo
- Azure CLI Login
az login
- Create Azure Resources with Terraform
- CD to
iac/terraform
- Terraform init:
terraform init
- Terraform plan:
terraform plan -var="basename=azsdkdemo1" --out tf.plan
Change the
basename
variable fromazsdkdemo1
to something that will be globally unique. It will be used as part of Azure resource names, so keep it short, lowercase, and no special characters. - Terraform apply:
terraform apply tf.plan
- CD to
- Update
.env
file- Copy and paste the Terraform output values to the
.env
file in the root of this repo.NOTE: .env files do not allow spaces around the
=
, so please remove any spaces after you copy and paste.
- Copy and paste the Terraform output values to the
- CD to the
src
folder for the language you would like to run, i.e. for .NET, cd tosrc/net
for Python, cd tosrc/python
- Run
docker-compose up --build
- Navigate to http://localhost:1080
- Add an Image
- Enter url into text box and click "Submit"
- Or click "Add Random Meme"
- The image will be added to the grid. Wait for the service to pick it up. You will eventually see the text and the image border color will change indicating the image text sentiment.
- Copy the values outputted from the Terraform commands above (they should be in your
.env
file if you followed the Code Setup steps above) into thepac/net/k8s/local/env-configmap.yaml
file. - CD to the
src
folder for the language you would like to run, i.e. for .NET, cd tosrc/net
for Python, cd tosrc/python
. - Run
docker-compose build
to build the containers locally. - CD to
pac/net/k8s/local
. - Run
./mount.sh
to mount your local.azure
folder to the container, so we can use AzureCliCredential in Kubernetes. - Run
kubectl apply -f .
- Navigate to http://localhost:31389
- Copy the values outputted from the Terraform commands above (they should be in your
.env
file if you followed the Code Setup steps above) into thepac/net/k8s/aks/env-configmap.yaml
file. - Run the
az aks get-credentials
command that was outputted from theterraform apply
command you ran earlier. It is something likeaz aks get-credentials --resource-group azsdkdemo100rg --name azsdkdemo100aks
. Replace the resource group and cluster name with the one you created with Terraform earlier. - Install Helm - This will be used for an nginx ingress controller that will expose a Public IP for our cluster and handle routing.
- Run the following commands:
helm repo add stable https://kubernetes-charts.storage.googleapis.com/ helm install nginx stable/nginx-ingress
- CD to the
src
folder for the language you would like to run, i.e. for .NET, cd tosrc/net
for Python, cd tosrc/python
. - Login to your container registry.
docker login
oraz acr login
. - Search the entire project for image names that start with
jongio/
and replace with the name of your container registry.Note: This experience will be improved with Helm or Kustomize soon.
- Run
docker-compose push
to push the containers to your container registry of choice. - Run
az network public-ip list -g azsdkdemo100aksnodes --query '[0].ipAddress' --output tsv
to find the AKS cluster's public IP address.Note: Change the resource group to your
node_resource_group
name, this command is also outputted by the Terraform commands. - Open
/pac/net/k8s/aks/web-configmap.yaml
and change theAPI_ENDPOINT
value to the Public IP address. - CD to
/pac/net/k8s/aks
and runkubectl apply -f .
- Open a browser and go to that Public IP.