page_type | languages | products | description | urlFragment | |||||
---|---|---|---|---|---|---|---|---|---|
sample |
|
|
web-server: This is the host for the dashboard and the api. The dashboard will let you add work to the queue. When work is added a yellow pending container will show up. |
aci-event-driven-worker-queue |
-
web-server: This is the host for the dashboard and the api. The dashboard will let you add work to the queue. When work is added a yellow pending container will show up. This is a default place holder until the actual ACI instance comes up and adds it's InProgress state to the DB to be read. Once the container has reached InProgress, the UI will chagne the default pending to Blue with the container's name in place. You can also hit the "More Details" Button to open the model with that containers ID. Currently the modal is calling to the metrics api endpoint for that specific container.
-
go-worker: This is the container to be spawned by the azure function watching the service bus queue. Its takes the enviorment variables: MESSAGE: The message from the queue, CONTAINER_NAME: container group name, DATABASE_URI: CosmosDb mongo connection string. IMPORTANT: You must remove the ssl=true url param from the connection string or it will break. When the container is started, it will add a state entry to the DB with its name and InProgress. It then waits a set number of seconds and Adds Done as its state to the DB.
-
Spawner-functions: This consists of two functions. One is watching a queue to create aci instances and another is watching a queue to delete aci instances.
Follow the steps below if you want to build your own docker images.
-
Setup
web-server
image- Build image.
cd web-server docker build -t <dockerid>/web-server:latest .
- Push image to Docker Hub.
docker push <dockerid>/web-server:latest
- Open the file azuredeploy.parameters.json in
arm
folder, and update the value of the parameterwebServerImage
to point to the new image."webServerImage": { "value": "<dockerid>/web-server" }
- Build image.
-
Setup
go-worker
image- Build image
cd ../go-worker docker build -t <dockerid>/go-worker:latest .
- Upload image to repository
docker push <dockerid>/go-worker:latest
- Open the file index.js in
spawner-functions/sbqTriggerCreateWorkerContainer
folder, and update this line to point to the new image.const IMAGE = "<dockerid>/go-worker:latest";
- Build image
-
Open and login to Azure Cloud Shell.
-
Clone the repo.
git clone https://github.com/Azure-Samples/aci-event-driven-worker-queue.git cd aci-event-driven-worker-queue
-
Create resource group.
az group create -l westus -n aci-event-driven
-
Create a service principal.
az ad sp create-for-rbac -n aci-event-driven --role contributor
Output sample:
{ "appId": "fb7c4111-2144-4489-8fd9-XXXXXXXXX", "displayName": "aci-event-driven", "name": "http://aci-event-driven", "password": "0fa91eda-261e-47ad-bb65-XXXXXXXX", "tenant": "3dad2b09-9e66-4eb8-9bef-XXXXXXX" }
-
Cd into the
arm
directory and update theazuredeploy.parameters.json
in the folderarm
with the service principal credential created above (appId, password, tenant), and assign an unique name for the parametersfunctionAppName
anddnsNameLabel
(for the website). -
Deploy the Azure resources with the ARM template. This will take a few minutes.
az group deployment create --template-file azuredeploy.json --parameters @azuredeploy.parameters.json -g aci-event-driven
Output sample
"outputs": { "fqdn": { "type": "String", "value": "web-servertmaalsmhtzqta.westus.azurecontainer.io" } }
Note: The output
fqdn
is the URL of the ACI dashboard. -
Download NPM packages.
cd ../spawner-functions npm install
-
Compress the files inside the
spawner-functions
folder as a .zip file.zip -r spawner-functions-compressed.zip .
-
Set deployment credential if you don't have one or forget.
Note: All function and web apps in the subscription will be impacted since they share the same deployment credentials.
az webapp deployment user set --user-name <deployment-user-name> --password <deployment-user-password>
-
Deploy the .zip file to Azure Functions, and type in the deployment user password when prompted by cURL.
curl -X POST -u <deployment-user-name> --data-binary @"spawner-functions-compressed.zip" https://<function-app-name>.scm.azurewebsites.net/api/zipdeploy
Note: The
<function-app-name>
is thefunctionAppName
parameter you used for ARM template deployment previously.