Logic Apps Anywhere — Run logic apps in a docker container

With the new capabilities introduced, Azure Logic Apps has become even more powerful. It can be hosted on any containerized platforms that strengthens Azure Integration Services position in the market. This is second part of the series of 4 part article, where we are hosting logic apps on various container platforms.

If you need some guidance on getting started and development story, please go to the previous article

The logic apps workflow we created in Part 1, can be packaged as a docker image, and run in a docker container.

Pre-requisites:

· Install Docker for Desktop.

· Install Docker extension for VS code Docker — Visual Studio Marketplace

Add Docker definitions to your project:

· Add a “DockerFile” to your project as below

FROM mcr.microsoft.com/azure-functions/node:3.0ENV AzureWebJobsStorage DefaultEndpointsProtocol=<BlobStorageConnectionString>ENV AzureWebJobsScriptRoot=/home/site/wwwroot \    AzureFunctionsJobHost__Logging__Console__IsEnabled=true \    FUNCTIONS_V2_COMPATIBILITY_MODE=trueENV WEBSITE_HOSTNAME localhostENV WEBSITE_SITE_NAME weatherforecastENV AZURE_FUNCTIONS_ENVIRONMENT DevelopmentCOPY . /home/site/wwwrootRUN cd /home/site/wwwroot

Follow this GitHub issue to know more about additional environment variables.

ENV WEBSITE_HOSTNAME localhostENV WEBSITE_SITE_NAME weatherforecastENV AZURE_FUNCTIONS_ENVIRONMENT Development

Getting CallBackUrl for container throws nullreference exception · Issue #129 · Azure/logicapps · GitHub

And modify the local.settings.json to have the storage account as the

"AzureWebJobsStorage": <BlobStorageConnectionString>

· Build the docker container image by using the docker file by running the below command

docker build --tag <ImageName> .

· Run the container locally by using the below command

docker run -p 8080:80 <ImageName>

· Once it is successfully run, you can see a new docker image running on the VS code, with the logs showing an instance started up and successfully acquired a lock.

· From Docker Desktop

· Good, now our logic app is running as a container in our local docker environment. To invoke the logic app, we need to get the callback URL for the logic apps.

· When the container instance is successfully instantiated, it creates couple of entries in the provided storage accounts. It creates a Secret file and a lock file.

· Navigate to the Azure storage account provided in the docker definition and open blob containers. You will see the following folders

· Inside “azure-webjobs-secrets” folder, you will see the folder as the same name as your docker image.

· Find the host.json under the folder and copy the masterKey value from the file

· Open postman and make a call to the following URL

POST http://localhost:8080/runtime/webhooks/workflow/api/management/workflows/{workflow-name}/triggers/{trigger-name}/listCallbackUrl?api-version=2020-05-01-preview&code={master-key}

Where {workflow-name}: <name of your workflow>

{trigger-name}: (manual) if it is http

{master-key}: key copied from above

· The results would have the value for the call back URL.

Callback URL Response structure

{    "value": "https://localhost:443/api/getWeatherByState/triggers/manual/invoke?api-version=2020-05-01-preview&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=<secret>",    "method": "POST",    "basePath": "https://localhost/api/getWeatherByState/triggers/manual/invoke",    "queries": {        "api-version": "2020-05-01-preview",        "sp": "/triggers/manual/run",        "sv": "1.0",        "sig": "<secret>"    }}

· Get the URL value from the result and make a Post as below

POST http://localhost:80/api/getWeatherByState/triggers/manual/invoke?api-version=2020-05-01-preview&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=<secret>

Header

Content-Type: application/json

Body

{
"city":"Wellington"
}

· A successful response is returned

If you see any errors retuned from logic apps due to not being able to read parameters from local.settings.json file, make sure the file is available in the container.

Launch a terminal from VS Code and run the following command

docker ps

From the output find the column NAMES. This column is the name for the docker image of your Logic App. It’s some kind of made-up name and varies each time the image is rebuilt.

For example, I see mine as dreamy_kapitsa. Run the following command to access containers file system

docker exec -it dreamy_kapitsa ./bin/bash

Now that we have got access to the file system, list down the files available on the wwwroot folder

ls /home/site/wwwroot

If you don’t see the local.settings.json file, that may be the cause of the issue. Copy the file from your local solution to the container by running this command

docker cp local.settings.json 16527b513905:/home/site/wwwroot

You can find the instance id by hovering over the container on VS Code.

And open the file to verify the settings, cat the file

cat /home/site/wwwroot/local.settings.json

VS Code docker extension makes it way easier, just by expanding the file system at the bottom of the docker container instance. We can navigate to the file and even the open the file in VS Code to verify.

So now the exciting part begins, we have deployed the logic apps workflow in a container, so cant wait to deploy the same in a cloud service other than Azure. That’s coming up on Part 3. Stay tuned!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vinnarason James

Vinnarason James

An Azure Enthusiast, looking to share my learning about Azure Services I use as part of my job