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
This is the current .NET architecture - we are in the process of developing for other languages and architectures as well.
The following are required to run this application.
- 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.
- Install Azure CLI
- Install Terraform
- Install Git
- Install VS Code
- Install Docker
- 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
You can configure which store the app uses to store your image metadata, either Cosmos DB or Azure Table Storage.
- Open
.env
file - Find the
AZURE_STORAGE_TYPE
setting - 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.
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.
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.
- CD to
iac/terraform
- Run
./azcliuserperms.sh {basename}
You need to replace
{basename}
with the basename you used above, such as 'azsdkdemo1'.
- 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
- Linux:
docker-compose up --build
- Windows:
docker-compose -f docker-compose.windows.yml up --build
- Linux:
- 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 config use-context docker-desktop
to use your local Kubernetes cluster. - 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 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
- 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 build
to build your containers locally. - 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. - Make sure you are in the right Kubernetes context by running
kubectl config get-contexts
and usekubectl config use-context
to set it. - CD to
/pac/net/k8s/aks
and runkubectl apply -f .
- Open a browser and go to the AKS cluster's Public IP.