question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PostAction for modifying the deployment.template.json file in IoT Edge solutions

See original GitHub issue

Is your feature request related to a problem? Please describe.

I’m creating a project template for a custom IoT Edge module. When adding an iotedge module to an IoT Edge solution, you need to update the deployment.template.json file that is part of the solution to include that new module into the deployment. It would be nice if there’s a custom ‘PostAction’ which can do these modifications for you, as I currently don’t see any way to do this myself.

As I read that the VS.NET extensions is in maintenance mode, and the CLI way will be the preferred way to create IoT Edge solutions / projects, this should be beneficial for Microsoft too ?

Describe the solution you’d like.

It would be nice if there would exist a PostAction that adds a new entry to the modules section of the deployment.template.json file that exists in an IoT Edge project. It would be helpfull if the developer could also specify the filename (or filenames) of this json file, as it is very much possible that an IoT Edge solution has multiple different deployment templates.

That new entry should look like this:

"IotEdgeModule1": {
            "version": "1.0.0",
            "type": "docker",
            "status": "running",
            "restartPolicy": "always",
            "settings": {
              "image": "${MODULEDIR<../IotEdgeModule1>}",
              "createOptions": {}
            }
          }

Where IoTEdgeModule1 is the name of the new module. This could be the sourceName property of the template.

If this is too specific for a post-action, you could instead provide a post-action that is more generic. A post-action that allows the developer to add a JSON-object / subproperty to a specific property in a specific JSON file could maybe also do the job.

Additional context

No response

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
fgheyselscommented, Jan 11, 2023

I have created a (draft) Pull Request for this (https://github.com/dotnet/sdk/pull/29880) .
The PR contains unit- and end-to-end tests. Documentation still needs to be provided, but I think it would be good to see if this change will be acceptable before doing some work on documentation.

1reaction
fgheyselscommented, Jan 10, 2023

I’ve been working on this for a while now, and I think I made some good progress. However, I’ve noticed that the template engine is not replacing references to the sourceName in a postaction.

Suppose I have a template that looks like this (only relevant parts included):

{
  "name": "SomeTemplate",
  "identity": "SomeTemplate",
  "shortName": "SomeTemplate",
  "sourceName": "MyProject",
  "primaryOutputs": [
    {
      "path": "MyProject.csproj"
    }
  ],
  "postActions": [
    {
      "description": "Modify JSON file",
      "args": {
        "jsonFileName": "deployment.template.json",
        "parentPropertyPath": "modulesContent:$edgeAgent:properties.desired:modules",
        "newJsonPropertyName": "MyProject",
        "newJsonPropertyValue": "{\"image\":\"${MODULEDIR<../MyProject>}\"}"
      }
    }
  ]
}

As can be seen, the ‘arguments’ of the post-action contain some strings containing MyProject which is the sourceName that is configured in the template. I would have expected that these strings would be replaced by the eventual project-name as well, but that is not the case. Of course, the template.json file is not part of the ‘project template’ itself, so I can understand that this is not happening. However, inside the post-action, I also have no knowledge of the sourceName nor the string-value that is used to replace the sourceName. Maybe I’m missing something, but none of the parameters of the ProcessInternal method contain this information.

Is there any way to achieve this ?

edit: I’ve currently ‘worked around’ this by making use of the filechanges in the CreationEffects. It’s a hacky solution imo, but I cannot come up with something better.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Specify Deployment.template.json in IoT Edge Solution
I have a few different "deployment.template.json" files in my IoT edge project. The project is part of Visual Studio 2017 solution with IoT...
Read more >
Manage Azure IoT Edge deployment manifests
Select Edit JSON in the context menu for the deployment manifest you want to modify. Use the JSON editor to make the required...
Read more >
Update PostAction with symbol parameters to cmd file ...
I need to pass symbols parameters to args when executing setup.cmd file using postActions property as below .template.config file.
Read more >
Module 5: Build and deploy the solution
The deployment.template.json file is used by the build process. It defines what modules to build, what message routes to set up, and what...
Read more >
Azure IoT Edge for Visual Studio Code
Azure IoT Edge: Build and Run IoT Edge Solution in Simulator: The context menu of deployment.template.json file in VS Code file explorer. Azure ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found