Skip to content

Commit 9b5f8d9

Browse files
committed
update
1 parent 1f34fbf commit 9b5f8d9

22 files changed

+640
-314
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ __pycache__/
33
*.py[cod]
44
*$py.class
55

6+
components/output.yaml
7+
components/queue.yaml
8+
9+
output/*
10+
11+
src/objectdetection/flickr30k_dataset/
12+
src/objectdetection/Dataset/
613
# C extensions
714
*.so
815

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"appId": "optimizer",
66
"appPort": 6000,
77
"logLevel": "debug",
8-
"componentsPath": "/Users/dennis/labs/serverless-container-ml/components",
8+
"componentsPath": "./components-local",
99
"label": "daprd-debug",
1010
"type": "daprd"
1111
},

README.md

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,35 @@ This sample is taken from https://techcommunity.microsoft.com/t5/apps-on-azure-b
44

55
![](/python.png)
66

7-
## create test data
87

9-
export AZURE_STORAGE_CONNECTION_STRING=""
10-
11-
MESSAGE=$(echo -n "hello from azure cli" | base64)
8+
## Deploy Azure resources
129

13-
az storage message put --content $MESSAGE -q requests
10+
```
11+
PROJECT_NAME="dzopt5"
12+
LOCATION="westeurope"
1413
15-
for i in {1..300}; do for i in {1..300}; az storage message put --content $MESSAGE -q requests; done
14+
bash ./deploy-infra.sh $PROJECT_NAME $LOCATION
1615
16+
```
1717

18-
## deployment guid
18+
## Deploy Apps into Container Apps
1919

2020
```
21+
PROJECT_NAME="dzopt5"
22+
GITHUB_REPO_OWNER="denniszielke"
23+
IMAGE_TAG="latest"
2124
22-
DEPLOYMENT_NAME="dzmlserverless" # here the deployment
23-
RESOURCE_GROUP=$DEPLOYMENT_NAME # here enter the resources group
24-
LOCATION="northeurope" # azure region can only be canadacentral or northeurope
25-
AZURE_SUBSCRIPTION_ID=$(az account show --query id -o tsv) # here enter your subscription id
26-
GHUSER="denniszielke" # replace with your user name
27-
GHREPO="serverless-container-ml" # here the repo name
28-
AZURE_TENANT_ID=$(az account show --query tenantId -o tsv)
29-
GHREPO_BRANCH=":ref:refs/heads/main"
30-
az group create -n $RESOURCE_GROUP -l $LOCATION -o none
25+
bash ./deploy-apps.sh $PROJECT_NAME $GITHUB_REPO_OWNER $IMAGE_TAG
3126
32-
AZURE_CLIENT_ID=$(az ad sp create-for-rbac --name "$DEPLOYMENT_NAME" --role contributor --scopes "/subscriptions/$AZURE_SUBSCRIPTION_ID/resourceGroups/$RESOURCE_GROUP" -o json | jq -r '.appId')
33-
34-
AZURE_CLIENT_OBJECT_ID="$(az ad app show --id ${AZURE_CLIENT_ID} --query objectId -otsv)"
27+
```
3528

36-
az rest --method POST --uri "https://graph.microsoft.com/beta/applications/$AZURE_CLIENT_OBJECT_ID/federatedIdentityCredentials" --body "{'name':'$DEPLOYMENT_NAME','issuer':'https://token.actions.githubusercontent.com','subject':'repo:$GHUSER/$GHREPO$GHREPO_BRANCH','description':'GitHub Actions for $DEPLOYMENT_NAME','audiences':['api://AzureADTokenExchange']}"
29+
## Create test data
3730

38-
echo $AZURE_CLIENT_ID
31+
export AZURE_STORAGE_CONNECTION_STRING=""
3932

40-
echo $AZURE_TENANT_ID
33+
MESSAGE=$(echo -n "hello from azure cli" | base64)
4134

42-
echo $AZURE_SUBSCRIPTION_ID
35+
az storage message put --content $MESSAGE -q requests
4336

44-
echo $RESOURCE_GROUP
37+
for i in {1..300}; do for i in {1..300}; az storage message put --content $MESSAGE -q requests; done
4538

46-
```
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
apiVersion: dapr.io/v1alpha1
22
kind: Component
33
metadata:
4-
name: bloboutput
4+
name: output
55
spec:
6-
name: bloboutput
6+
name: output
77
type: bindings.azure.blobstorage
88
version: v1
99
metadata:
1010
- name: storageAccount
11-
value: dserverless1
11+
value: {.storageAccount}
1212
- name: storageAccessKey
13-
value: ""
13+
value: "{.storageAccessKey}"
1414
- name: container
15-
value: items
15+
value: output
1616
- name: decodeBase64
1717
value: "true"

components/queue.yaml renamed to component-templates/queue-template.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ spec:
77
version: v1
88
metadata:
99
- name: storageAccount
10-
value: dserverless1
10+
value: "{.storageAccount}"
1111
- name: storageAccessKey
12-
value: ""
12+
value: "{.storageAccessKey}"
1313
- name: queue
1414
value: requests
1515
- name: ttlInSeconds

components-local/output-local.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: dapr.io/v1alpha1
2+
kind: Component
3+
metadata:
4+
name: output
5+
spec:
6+
type: bindings.localstorage
7+
version: v1
8+
metadata:
9+
- name: rootPath
10+
value: output

components-local/queue-local.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: dapr.io/v1alpha1
2+
kind: Component
3+
metadata:
4+
name: requests
5+
spec:
6+
type: pubsub.redis
7+
version: v1
8+
metadata:
9+
- name: redisHost
10+
value: localhost:6379
11+
- name: redisPassword
12+
value: ""
13+
- name: consumerID
14+
value: "requests"

create-config.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# infrastructure deployment properties
6+
7+
DEPLOYMENT_NAME="$1" # here enter unique deployment name (ideally short and with letters for global uniqueness)
8+
9+
if [ "$DEPLOYMENT_NAME" == "" ]; then
10+
echo "No project name provided - aborting"
11+
exit 0;
12+
fi
13+
14+
if [[ $DEPLOYMENT_NAME =~ ^[a-z0-9]{5,9}$ ]]; then
15+
echo "project name $DEPLOYMENT_NAME is valid"
16+
else
17+
echo "project name $DEPLOYMENT_NAME is invalid - only numbers and lower case min 5 and max 8 characters allowed - aborting"
18+
exit 0;
19+
fi
20+
21+
RESOURCE_GROUP="$DEPLOYMENT_NAME"
22+
23+
AZURE_CORE_ONLY_SHOW_ERRORS="True"
24+
25+
if [ $(az group exists --name $RESOURCE_GROUP) = false ]; then
26+
echo "resource group $RESOURCE_GROUP does not exist"
27+
error=1
28+
else
29+
echo "resource group $RESOURCE_GROUP already exists"
30+
LOCATION=$(az group show -n $RESOURCE_GROUP --query location -o tsv)
31+
fi
32+
33+
STORAGE_KEY=$(az storage account keys list --account-name strg$DEPLOYMENT_NAME --resource-group $RESOURCE_GROUP --query "[0].value" -o tsv)
34+
STORAGE_NAME="strg$DEPLOYMENT_NAME"
35+
36+
STORAGE_KEY_ESC=$(echo $STORAGE_KEY | sed 's/\//\\\//g')
37+
38+
replaces="s/{.storageAccount}/$STORAGE_NAME/;";
39+
replaces="$replaces s/{.storageAccessKey}/$STORAGE_KEY_ESC/;";
40+
41+
mkdir -p components
42+
43+
cat ./component-templates/output-template.yaml | sed -e "$replaces" > ./components/output.yaml
44+
cat ./component-templates/queue-template.yaml | sed -e "$replaces" > ./components/queue.yaml
45+
46+
echo "create component files in /components directory"

create-infra.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

deploy-apps.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# infrastructure deployment properties
6+
PROJECT_NAME="$1"
7+
REGISTRY_OWNER="$2"
8+
IMAGE_TAG="$3"
9+
10+
if [ "$PROJECT_NAME" == "" ]; then
11+
echo "No project name provided - aborting"
12+
exit 0;
13+
fi
14+
15+
if [[ $PROJECT_NAME =~ ^[a-z0-9]{5,8}$ ]]; then
16+
echo "project name $PROJECT_NAME is valid"
17+
else
18+
echo "project name $PROJECT_NAME is invalid - only numbers and lower case min 5 and max 8 characters allowed - aborting"
19+
exit 0;
20+
fi
21+
22+
RESOURCE_GROUP="$PROJECT_NAME"
23+
24+
AZURE_CORE_ONLY_SHOW_ERRORS="True"
25+
26+
if [ $(az group exists --name $RESOURCE_GROUP) = false ]; then
27+
echo "resource group $RESOURCE_GROUP does not exist"
28+
error=1
29+
else
30+
echo "resource group $RESOURCE_GROUP already exists"
31+
LOCATION=$(az group show -n $RESOURCE_GROUP --query location -o tsv)
32+
fi
33+
34+
az deployment group create -g $RESOURCE_GROUP -f ./infrastructure/apps.bicep \
35+
-p projectName=$PROJECT_NAME -p imageTag=$IMAGE_TAG \
36+
-p containerRegistryOwner=$REGISTRY_OWNER
37+
38+
39+

deploy-infra.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# infrastructure deployment properties
6+
PROJECT_NAME="$1"
7+
LOCATION="$2"
8+
9+
if [ "$PROJECT_NAME" == "" ]; then
10+
echo "No project name provided - aborting"
11+
exit 0;
12+
fi
13+
14+
if [[ $PROJECT_NAME =~ ^[a-z0-9]{5,8}$ ]]; then
15+
echo "project name $PROJECT_NAME is valid"
16+
else
17+
echo "project name $PROJECT_NAME is invalid - only numbers and lower case min 5 and max 8 characters allowed - aborting"
18+
exit 0;
19+
fi
20+
21+
RESOURCE_GROUP="$PROJECT_NAME"
22+
23+
AZURE_CORE_ONLY_SHOW_ERRORS="True"
24+
25+
if [ $(az group exists --name $RESOURCE_GROUP) = false ]; then
26+
echo "creating resource group $RESOURCE_GROUP..."
27+
az group create -n $RESOURCE_GROUP -l $LOCATION -o none
28+
echo "resource group $RESOURCE_GROUP created"
29+
else
30+
echo "resource group $RESOURCE_GROUP already exists"
31+
LOCATION=$(az group show -n $RESOURCE_GROUP --query location -o tsv)
32+
fi
33+
34+
az deployment group create -g $RESOURCE_GROUP -f ./infrastructure/main.bicep \
35+
-p projectName=$PROJECT_NAME -p internalOnly=false
36+
37+
38+

0 commit comments

Comments
 (0)