[Build and Deploy Staging Site] Publish from microsoft/azuretipsandtricks-private:main/src/blog

This commit is contained in:
vaheminasyan2 2021-04-07 15:49:38 +00:00
Родитель 3cf9928661
Коммит afb083d43a
1 изменённых файлов: 108 добавлений и 0 удалений

108
blog/tip311.md Normal file
Просмотреть файл

@ -0,0 +1,108 @@
---
type: post
title: "Tip 311 - How to run Logic Apps in a Docker container"
excerpt: "Learn how to run Logic Apps in a Docker container"
tags: [Integration, Containers]
share: true
date: 2021-04-07 12:00:00
---
::: tip
:fire: Make sure you [star the repo](http://azuredev.tips?WT.mc_id=azure-azuredevtips-azureappsdev) to keep up to date with new tips and tricks.
:bulb: Learn more : [Azure Logic Apps overview](https://docs.microsoft.com/azure/logic-apps/logic-apps-overview?WT.mc_id=docs-azuredevtips-azureappsdev).
:tv: Watch the video : [How to run Logic Apps in a Docker container](https://youtu.be/GHk7Arm247E?WT.mc_id=youtube-azuredevtips-azureappsdev).
:::
### How to run Logic Apps in a Docker container
#### Azure Logic Apps can run anywhere
You can run [Azure Logic Apps](https://azure.microsoft.com/services/logic-apps/?WT.mc_id=azure-azuredevtips-azureappsdev) anywhere, on the [Azure Functions Runtime](https://docs.microsoft.com/azure/azure-functions/functions-versions?WT.mc_id=docs-azuredevtips-azureappsdev). This enables you to deploy and run Logic Apps on your local machine, in your own datacenter, or in another cloud. And you can also run Azure Logic Apps in a [Docker](https://www.docker.com/?WT.mc_id=other-azuredevtips-azureappsdev) container.
In this post, we'll run an Azure Logic App in a Docker container.
#### Prerequisites
If you want to follow along, you'll need the following:
* An Azure subscription (If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=azure-azuredevtips-azureappsdev) before you begin)
* Create an Azure Logic App in VS Code with the newest extension by following [this previous tip](https://microsoft.github.io/AzureTipsAndTricks/blog/tip304.html)
* [Docker Desktop](https://docs.docker.com/docker-for-windows/install/?WT.mc_id=other-azuredevtips-azureappsdev)
* [Postman](https://www.postman.com/downloads/?WT.mc_id=other-azuredevtips-azureappsdev) for sending requests
#### Deploy a Logic App to a container
The Logic App is triggered by an HTTP trigger and creates a queue message in Azure Storage. Let's deploy the Logic App to a container.
1. In VS Code, create a **Dockerfile** in the project of the Logic App. The file has no file extension, and is just called Dockerfile. It should have the following contents:
```
FROM mcr.microsoft.com/azure-functions/dotnet:3.0.14492-appservice
ENV AzureWebJobsStorage=<Your Azure Storage connection string>
ENV AZURE_FUNCTIONS_ENVIRONMENT Development
ENV AzureWebJobsScriptRoot=/home/site/wwwroot
ENV AzureFunctionsJobHost__Logging__Console__IsEnabled=true
ENV FUNCTIONS_V2_COMPATIBILITY_MODE=true
COPY ./bin/release/netcoreapp3.1/publish/ /home/site/wwwroot
```
Fill in your **Azure Storage connection string** for the **AzureWebJobsStorage** environment variable so that the Logic App in the container can use it.
<img :src="$withBase('/files/95dockerfile.png')">
(Dockerfile in VS Code)
2. Next, open the **Terminal** in VS Code and build and publish the project with these commands:
```
dotnet build -c release
dotnet publish -c release
```
3. Now create the container image with this command:
```
docker build --tag local/workflowcontainer .
```
4. Run the container with the following command. This makes the Logic App accessible through localhost:8080
```
docker run -e WEBSITE_HOSTNAME=localhost -p 8080:80 local/workflowcontainer
```
5. Now for the most difficult part. We need to discover the URL for the HTTP trigger. To do that, we first need to get the masterKey to gain access to the Logic App. You can find this key in the Azure Storage Account that you've indicated in the Dockerfile. Go to the **Azure Storage Account** and navigate to **Containers/azure-webjobs-secrets/{id}** and open the **host.json** file.
<img :src="$withBase('/files/95hostjson.png')">
(Host.json file in Azure Storage)
```
"masterKey": {
"name": "master",
"value": "l6vZj8J3aLEZzOfTV7SiiP2H2eru96ajlzZNpoXm5WScABAoP1tlEg==",
"encrypted": false
}
```
Copy the **value** of the **masterKey**. We'll need that in the next step.
6. Open **Postman**
7. Create a new **POST** request for http://localhost:8080/runtime/webhooks/workflow/api/management/workflows/**{your logic app workflow name}**/triggers/manual/listCallbackUrl?api-version=2020-05-01-preview&code=**{masterKey value}** and send it
<img :src="$withBase('/files/95postmanresults.png')">
(Postman results)
The results from the post contain the URL of the HTTP trigger to call and the query parameters to add to the URL.
8. Open a browser and trigger the Logic App with a URL like this: http://localhost:8080/api/**{your logic app workflow name}**/triggers/manual/invoke?api-version=2020-05-01-preview&sp=**{value for sp}**&sv=**{value for sv}**&sig=**{value for sig}**&myqueuetext
The final querystring is a text, which the Logic App takes and puts in a new queue message in Azure Storage
That's it! The Logic App is now triggered and should run successfully and place a message on the Azure Storage queue, like in the image below:
<img :src="$withBase('/files/95result.png')">
(The Logic App created a queue message in the Azure Storage queue)
#### Conclusion
[Azure Logic Apps](https://azure.microsoft.com/services/logic-apps/?WT.mc_id=azure-azuredevtips-azureappsdev) enable you to easily create complex workflows. Now, you can run Azure Logic Apps anywhere, including in a [Docker](https://www.docker.com/?WT.mc_id=other-azuredevtips-azureappsdev) container. Go and check it out!