Skip to content

christothes/azsdkdemo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Memealyzer

Meme + Analyzer = Memealyzer

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 Cosmos DB or Azure Table Storage.

If the text in the image is positive then the border color will change to green, if neutral then black, and if negative it will change to red.

Download the Azure SDK Releases

.NET Architecture

This is the current .NET architecture - we are in the process of developing for other languages and architectures as well.

Pre-reqs

The following are required to run this application.

  1. A Terminal - WSL, GitBash, PowerShell. The Terraform deployment will not work with Windows Command Prompt because it uses some shell scripts to fill Terraform gaps. You will need to run all the commands below in your selected terminal.
  2. Install Azure CLI
  3. Install Terraform
  4. Install Git
  5. Install VS Code
  6. Install Docker
  7. Azure Subscription

Azure Resources

The following Azure resources will be deployed with the Terraform script.

  1. Resource Group
  2. Storage Account
  3. Cognitive Services Form Recognizer
  4. Cognitive Services Text Analytics
  5. Cosmos DB
  6. Key Vault
  7. Azure Kubernetes Service
  8. Application Insights

Code Setup

  1. Open Git Bash or WSL - The same terminal you used to install the pre-reqs above.
  2. Clone Repo git clone https://github.com/jongio/azsdkdemo

Azure Setup

  1. Azure CLI Login az login
  2. Create Azure Resources with Terraform
    1. CD to iac/terraform
    2. Terraform init: terraform init
    3. Terraform plan: terraform plan -var="basename=azsdkdemo1" --out tf.plan

      Change the basename variable from azsdkdemo1 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.

    4. Terraform apply: terraform apply tf.plan
  3. Update .env file
    1. 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.

Configuration

Data Provider

You can configure which store the app uses to store your image metadata, either Cosmos DB or Azure Table Storage.

  1. Open .env file
  2. Find the AZURE_STORAGE_TYPE setting
  3. Set it to one of the following values:
    • COSMOS_SQL - This will instruct the app to use Cosmos DB.
    • STORAGE_TABLE - This will instruct the app to use Azure Storage Tables. As of 8/31/2020, this option uses a dev build of the Azure Tables client library, which will go to preview soon.

Border Style

You can configure the image border style with the Azure App Configuration service. It will default to solid, but you can change it to any valid CSS border style. You can either do this in the Azure Portal, or via the Azure CLI with this command:

az appconfig kv set -y -n {basename}appconfig --key borderStyle --value dashed

Replace {basename} with the basename you used when you created your Azure resources above.

After you change the setting, reload the WebApp to see the new style take effect.

Permissions Setup

This app uses the Azure CLI login to connect to Azure resources for local development. You need to run the following script to assign the appropriate roles to the Azure CLI user.

  1. CD to iac/terraform
  2. Run ./azcliuserperms.sh {basename}

    You need to replace {basename} with the basename you used above, such as 'azsdkdemo1'.

Run Application

Docker Compose

  1. CD to the src folder for the language you would like to run, i.e. for .NET, cd to src/net for Python, cd to src/python
  2. Run Docker Compose
    1. Linux: docker-compose up --build
    2. Windows: docker-compose -f docker-compose.windows.yml up --build
  3. Navigate to http://localhost:1080
  4. Add an Image
    1. Enter url into text box and click "Submit"
    2. Or click "Add Random Meme"
    3. 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.

Local Kubernetes

  1. 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 the pac/net/k8s/local/env-configmap.yaml file.
  2. CD to the src folder for the language you would like to run, i.e. for .NET, cd to src/net for Python, cd to src/python.
  3. Run docker-compose build to build the containers locally.
  4. CD to pac/net/k8s/local.
  5. Run ./mount.sh to mount your local .azure folder to the container, so we can use AzureCliCredential in Kubernetes.
  6. Run kubectl config use-context docker-desktop to use your local Kubernetes cluster.
  7. Run kubectl apply -f .
  8. Navigate to http://localhost:31389

Azure Kubernetes Service

  1. 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 the pac/net/k8s/aks/env-configmap.yaml file.
  2. Run the az aks get-credentials command that was outputted from the terraform apply command you ran earlier. It is something like az aks get-credentials --resource-group azsdkdemo100rg --name azsdkdemo100aks. Replace the resource group and cluster name with the one you created with Terraform earlier.
  3. Install Helm - This will be used for an nginx ingress controller that will expose a Public IP for our cluster and handle routing.
  4. Run the following commands:
    helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
    helm repo add stable https://kubernetes-charts.storage.googleapis.com/
    helm repo update
    helm install nginx ingress-nginx/ingress-nginx
    
    # If you already have installed or get this error: Error: cannot re-use a name that is still in use
    
    helm upgrade --install nginx ingress-nginx/ingress-nginx
    
  5. CD to the src folder for the language you would like to run, i.e. for .NET, cd to src/net for Python, cd to src/python.
  6. Login to your container registry. docker login or az acr login.
  7. 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.

  8. Run docker-compose build to build your containers locally.
  9. Run docker-compose push to push the containers to your container registry of choice.
  10. 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.

  11. Open /pac/net/k8s/aks/web-configmap.yaml and change the API_ENDPOINT value to the Public IP address.
  12. Make sure you are in the right Kubernetes context by running kubectl config get-contexts and use kubectl config use-context to set it.
  13. CD to /pac/net/k8s/aks and run kubectl apply -f .
  14. Open a browser and go to the AKS cluster's Public IP.

About

Let's demo the new Azure SDKs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 52.2%
  • HCL 18.0%
  • HTML 12.1%
  • Python 5.8%
  • CSS 5.3%
  • Dockerfile 3.4%
  • Shell 3.2%