Deploying a Flogo App to Microsoft Azure Functions

Note: The information in this section is applicable for an app executable only.

After you have designed a Flogo app or imported an existing one, you can deploy it to Microsoft Azure Functions as a custom Docker container. You can do this by using the Azure CLI.

Before you beginMake sure you have a Microsoft Azure account with an active subscription and you can log in to the Azure Portal. For more information on getting a Microsoft Azure account, see Microsoft Azure.

Creating the Azure Function App from the Azure CLI

Before you beginInstall the following:
    Procedure
  1. Create a new directory (for example, flogo-func-project) and open it.
  2. Copy
    cd flogo-func-project

  3. Create a new function project using the following command:

  4. Copy
    func init --worker-runtime custom --docker

    The --docker option generates a Dockerfile for the project.

  5. Add a new function from a template using the following command:

  6. Copy
    func new --name <your-app-name> --template "HTTP trigger"

    Here:

    --name argument is the unique name of your function

    --template argument specifies the template based on which the function is created

    Example:

    Copy
    func new --name hello-world --template "HTTP trigger"

  7. Download or build the executable for your HTTP trigger app and copy it into the directory you created earlier.

  8. For example, copy hello-world.json to the flogo-func-project directory.

  9. If it is not an executable file, make it executable by running the following command:

  10. Copy
    chmod +x <executable-filename>

  11. Add the following script to your project folder with the name start.sh:

    Copy

    start.sh

    #!/usr/bin/env sh
    echo "Starting function..."
    PORT=${FUNCTIONS_CUSTOMHANDLER_PORT} ./hello-world-linux_amd64
  12. Make it executable by running the following command:
  13. Copy
    chmod +x start.sh

  14. To update the default app prefix from api to your prefix, edit the function.json file. For example, you can change the prefix to hello-world.

  15. Copy

    function.json

    {
        "bindings": [
            {
                "authLevel": "anonymous",
                "type": "httpTrigger",
                "direction": "in",
                "name": "req",
                "methods": ["get", "post"],
                "route": "books/{bookID}"
            },
            {
                "type": "http",
                "direction": "out",
                "name": "res"
            }
        ]
    }

  16. To add customHeaders in the extensions, edit the host.json file:
  17. Copy

    host.json

    {
        "version": "2.0",
        "logging": {
            "applicationInsights": {
                "samplingSettings": {
                    "isEnabled": true,
                    "excludedTypes": "Request"
                }
            }
        },
        "extensionBundle": {
            "id": "Microsoft.Azure.Functions.ExtensionBundle",
            "version": "[2.*, 3.0.0)"
        },
        "customHandler": {
            "description": {
                "defaultExecutablePath": "start.sh",
                "workingDirectory": "",
                "arguments": []
            },
            "enableForwardingHttpRequest": true
        },
        "extensions": {
            "http": {
                "routePrefix": ""
            }
        }
    }

  18. To change the path, edit the Dockerfile:
  19. Copy

    Dockerfile

    FROM mcr.microsoft.com/azure-functions/dotnet:3.0-appservice 
    ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true
    COPY . /home/site/wwwroot

    Your folder structure should now look similar to the following:

    .
    ├── Dockerfile
    ├── hello-world-app
    │ └── function.json
    ├── hello-world-rest-trigger-linux_amd64
    ├── host.json
    ├── local.settings.json
    └── start.sh

  20. Test your app locally by running the following command:

    Copy
    func start

    The output returns an URL for the app.

  21. Test whether the app works by navigating to the URL provided in the output. For example:

    Copy
    http://localhost:7071/hello-world
  22. Publish your app to Microsoft Azure. For more information, see Publish the project to Azure.