Skip to content

Updates to the Azure Support PR #1493

Closed

Description

@eahefnawy

Corresponding PR with the WIP: #1547

The Azure support PR (#1426) gave us a good push forward for getting Azure in. However it's a bit outdated. I took a deep dive today and here's what I think we should change:


How it works:

Click here to see how the PRed implementation works.


Todo:

  • Add README.md files to corresponding plugins
  • Add docs
  • Move disabled property to event (rather than having it inside the function under the azure scope)
  • Update function compilation so that the new service bound runtime is used (Add service bound runtime functionality #1536)
  • Separate compile steps into separate plugins
    • The PR is using a single compile plugin with HttpTrigger and TimerTrigger build functions in lib. We should move those two into separate plugins to be consistent with aws plugins.
  • Don't retry to create the resource group on errors
    • The PR retries creating the resource group if an error happened. This could lead to a circular/infinite bug that is hard to track. We should instead let the user know what caused the resource group creation to fail.
  • Get Azure credentials from serverless variables
    • The PR gets the Azure username/password creds from env vars. We should also get it from serverless stage variables to allow users to have different account for each stage just like we're doing with AWS
  • Use new templating mechanism / Organize templates by provider
    • This PR introduces the default azure-arm.json template file (this should be moved inside the plugin like we did with AWS). We should organize the templates directory by provider to keep each provider default resources file separate.
  • Remove dependency on Azure CLI
    • This PR depends on the Azure CLI and deploys resources by spawning a command to that CLI. We should instead use the SDK if possible, or the ARM Rest API (might be complex to implement though)
  • Remove the Azure utils dir/files
    • This PR includes a utils dir/files specific to Azure. To stay consistent with AWS plugins, we'll either move that logic into an Azure specific wrapper, or inside the plugins logic.
  • Validate input
    • This PR lacks input validation. Add it.
  • Update unit tests
    • Based on all these changes, we'll need to update all the unit tests
  • Use new package plugin
  • Fix typos / code cleanup so that it follows the patterns which were also applied in the AWS plugins
  • Add simple and nested event source syntax

Done:

  • Change http_endpoint to http
    • The PR still references the HTTP event as http_endpoint. To keep it simple and consistent with AWS, we'll change the key to be http
  • Update plugins to use new provider property
  • Change resources object to reflect provider per service
    • The PR still references the resources.azure object. We should remove the azure sub property.
  • Rename scheduled_trigger to timer event
  • Change events object to reflect provider per service
    • The PR still references the events.azure object. We should remove the azure sub property.

Thoughts...? cc @flomotlik @pmuens @ac360

Activity

  1. added this to the v1.0.0-alpha.2 milestone on Jul 6, 2016
  2. pmuens commented on Jul 6, 2016

    @pmuens
    Contributor

    Thanks for looking into it!

    Good idea to keep track of all the steps which should be done 👍 .

    I've added the "Use new package plugin" step and updated it so that those bullet points are all checklist items.

  3. pmuens commented on Jul 8, 2016

    @pmuens
    Contributor
    URL to get to functions dashboard:

    http://functions.azure.com

    Available regions:
    • Southeast Asis
    • West Europe
    • West US
    Triggers
    • Timer
    • Azure Event Hub
    • Azure Storage Queue
    • Azure Storage Blob
    • SaaS File Trigger
    • HTTP
    • Azure Service Bus
    • Manual
    Package deployment:
    • GitHub
    • Visual Studio Team Services
    • Azure SDK
    • FTP
    • Azure CLI
    • .zip file
    Languages
    • Node.js
    • C#
    • Python
    • F#
    • PHP
    • batch
    • bash
    • Java
    • "Any other executable"
    Features
    • CI
    • Authentication
    • CORS
    • API definition
    Random notes:
    • Functions can be disabled
    • Baisc monitoring is available
    • In detail monitoring will be coming soon
  4. modified the milestones: v1.0.0-alpha.2, on Jul 11, 2016
  5. pmuens commented on Jul 13, 2016

    @pmuens
    Contributor

    @eahefnawy @flomotlik FYI:

    Just looked through the code and created a list how everything works in plain english:

    How Azure deployment works (the version of the PR).

    1. The compile plugin
      1. Create a functions property on this.serverless.service.resource.azure so that we have this.serverless.service.resource.azure.functions (this will be used to generate function.json files for the deployment later on)
      2. Loop through all functions
        1. Create a function object with the help of the Serverless getFunction method
        2. Look if there’s a http or timer event (create corresponding JSONs for this events)
        3. Add the trigger JSONs to this.serverless.service.resource.azure.functions
          1. e.g. if we have a function foo we’ll get this: this.serverless.service.resources.azure.functions[foo] = correspondingTriggerJSON;
    2. The deploy plugin
      1. deploy:initializeResources
        1. Load the azure-arm.json template from the templates directory
        2. Replace variables in template with service related settings (e.g. the siteName will be the name of the service etc.)
        3. Load Azure resources from this.serverless.service.resources.azure
        4. Merge the already provided resources (e.g. through plugins or the services provider related resources) which we got from above into the Azure templates „template.resources“ section
        5. Add the whole template to this.serverless.service.resources.azure (all the values which were attached to the resources.azure section will be replaced with the whole, filled out template)
      2. before:deploy:createProviderStacks
        1. Set the CLI mode to Azure resource manager (ARM) so that we use ARM and not ASM
      3. deploy:createProviderStacks
        1. Create a new resource group where all the service related resources will be stored (e.g. the functions)
        2. if the resource group is present it will be removed and re-created
      4. deploy:deploy
        1. deployResources
          1. Get the Azure resource template from this.serverless.service.resources.azure(remember that it’s the whole, pre filled template)
          2. Create a temp directory with a .json file. Store the whole resource template in this file
          3. Deploy the template to the previously created resource group
        2. deployFunctions
          1. Zip all the functions
          2. Create a function.json (the JSON is the value stored at this.serverless.service.resources.azure.functions['functionName']) file and include it in the functions .zip file
          3. Upload the .zip files to the „Azure website“ which belongs to the service (via a HTTP PUT request)
    3. The invoke plugin
      1. Do a GET request to the services „Azure website“ and call the function. Print the result on the console
    4. The remove plugin
      1. Remove the resource group (All the service related stuff belongs to this resource so everything will be removed)
  6. eahefnawy commented on Jul 14, 2016

    @eahefnawy
    ContributorAuthor

    @flomotlik @pmuens one caveat about Azure Functions is that it doesn't have a handler concept. Instead, each function is a folder with an index.js file that exports a single function. That's how Azure imports the function code.

    That means that the exported function ("the handler") will always be in the root of the package...which means functions won't be able to reuse common code because anything outside of that root/folder/package will be excluded (not part of the function).

    And because there can only be a single index.js file (that exports a single function) in a folder, we can't reuse the same zip file for all functions like we're doing with AWS because each zip will have a different index.js code in the root based one the function. So we have to deploy each function zip individually.

    I'm trying to think of a directory structure for an azure-nodejs service, and here's what I came up with:

    Option A

    serverless.yaml
    serverless.env.yaml
    functionA
        |- index.js
        |- functionASubFolder
            |- functionASubFile.js
    functionB
        |- index.js
    

    This is the most straightforward directory structure. FunctionA & FunctionB are completely isolated and won't share code. On deployment, the framework will generate a function.json file inside each of the functions folder root based on the data in serverless.yaml (this file is required by Azure) and then the framework will generate 2 zip files: the FunctionA & FunctionB folders, and will push them to Azure.

    This seems simple to implement, but it's a lot of boilerplate. This is how Azure recommends it in their docs.

    Option B

    serverless.yaml
    serverless.env.yaml
    handlers.js
    

    On deployment, the framework generates the required index.js in the root of the service for each function by copying the relevant handler from handlers.js and then zip the entire service and deploy it to Azure. Remember, that must happen for each Function since the zip will always be different because we're generating a different index.js file for each function. Plus of course the function.json mentioned above. This option looks a lot like our current AWS implementation, and it has the advantage of code reuse between functions, but it introduces some issues:

    • The zip is different for each function, so we'll have to deploy the entire service x number of times for each function, because a different index.js file is generated in the root. Will be really slow.
    • handlers.js file will always has to be in the root of the service, because we will generate the index.js file in the root of the service, and the location of handler.js and index.js should match otherwise any requires in the handler won't work. We also have no way to "point" to a certain handler with Azure since Azure has no concept of handlers to begin with.

    I personally prefer option A because:

    • Option B is sort of hacky (we're trying to implement a handler functionality even though it doesn't exist in Azure). Option A will not need a handler property in serverless.yaml. After our transition to a provider per service implementation, I think each provider service should work the same way the provider is expecting it to work. Users can then make explicit decisions on which provider to choose based on that provider UX.
    • Option B is slower and has unnecessarily bigger zip file.
    • Even though option B is close to the AWS implementation, there's no hard requirement in AWS that all handlers should be in the root of the service. So an AWS service could still look like option A if users wants to do that. So having the handlers in the root is not really a "standard" that we should pursue imo.
    • Option B will make supporting multiple Azure languages challenging, because we'll have to generate the equivalent of that index.js file for each runtime/language. Option A simply takes whatever the user has.

    @flomotlik @pmuens and everyone else, any thoughts...?

  7. modified the milestones: , on Jul 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions