Deploying a Flogo App to Microsoft Azure Functions

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 Microsoft Azure portal or do it by using the CLI.

Before you beginMake sure you have a Microsoft Azure account with an active subscription and you can login to https://portal.azure.com. For more information on getting a Microsoft Azure account, see https://azure.microsoft.com/.

Creating the Azure Function App in the Azure Portal

Before you beginInstall the following:
    Procedure
  1. Build a Docker image of your Flogo app.
  2. If you are using Azure container registry, log in to the repository created on the Azure container registry.
  3. Tag and push the Docker image of the Flogo app to the repository in Azure container registry. For example:
  4. docker tag flogo/hello-world:latest myregistry.azurecr.io/flogo-hello-world:latest

  5. In the Azure portal, create a new Azure Function app. While creating the Azure Function app, in the Instance details dialog box, select Docker Container as the Publish mode.
  6. After the Azure Function app is created, go to Settings > Container Settings (Classic) on the left navigation pane.
  7. On the right pane, select the image Source, enter other details, and click Save.
    Tip: If you select Registry SettingsRegistry Source as Azure Container Registry, and you face issues while selecting the Registry, verify the Repository permissions for the repository created for the Flogo app. Update the Azure Container Registry and enable Admin user; this enables the Azure function to access the images in the repositories.
  8. If you are using a trigger port other than 80 or 8080, navigate to Settings > Configuration and click New application setting. Specify:
    • Name: WEBSITES_PORT

    • Value: <your trigger port>

  9. Click Save. The app is restarted and changes made are reflected in the app.
  10. To copy the URL for your app and check whether it is working, go to the Overview menu.

    Note: Do NOT add the port declared in the trigger settings to the URL. If the URL does not work, restart the app manually.
  11. For an app with app properties, to override the app properties, add the following to Configuration > Application settings:

    • All the app properties
    • FLOGO_APP_PROPS_ENV=auto
  12. Save the settings. The app restarts when you save the properties.

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 binary 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 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:
  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

    # To enable ssh & remote debugging on app service change the base image to the one below
    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.