Git Product home page Git Product logo

isabella232 / aci-event-driven-worker-queue Goto Github PK

View Code? Open in Web Editor NEW

This project forked from azure-samples/aci-event-driven-worker-queue

0.0 0.0 0.0 46.14 MB

Learn how to use Azure Container Instances to scale up containers on-demand in response to incoming work.

License: MIT License

Makefile 2.02% Go 4.65% JavaScript 11.84% Shell 1.08% Python 34.26% HTML 41.51% PowerShell 1.55% Dockerfile 3.11%

aci-event-driven-worker-queue's Introduction

page_type languages products description urlFragment
sample
html
python
javascript
go
azure
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

ACI Event Driven Worker Queue

Components

  1. 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.

  2. 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.

  3. 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.

Setup Docker Images

Follow the steps below if you want to build your own docker images.

  1. 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 parameter webServerImage to point to the new image.
      "webServerImage": {
          "value": "<dockerid>/web-server"
      }
  2. 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";

Deployment Steps

  1. Open and login to Azure Cloud Shell.

  2. Clone the repo.

    git clone https://github.com/Azure-Samples/aci-event-driven-worker-queue.git
    
    cd aci-event-driven-worker-queue
  3. Create resource group.

    az group create -l westus -n aci-event-driven
  4. 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"
    }
    
  5. Cd into the arm directory and update the azuredeploy.parameters.json in the folder arm with the service principal credential created above (appId, password, tenant), and assign an unique name for the parameters functionAppName and dnsNameLabel (for the website).

  6. 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.

  7. Download NPM packages.

    cd ../spawner-functions
    
    npm install
  8. Compress the files inside the spawner-functions folder as a .zip file.

    zip -r spawner-functions-compressed.zip .
  9. 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>
  10. 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 the functionAppName parameter you used for ARM template deployment previously.

aci-event-driven-worker-queue's People

Contributors

alexchx avatar chadliuxc avatar jluk avatar microsoftopensource avatar msftgits avatar ogcanviz avatar v-rajagt-zz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.