Migrating existing IoT Edge modules to the 0.2.0 template scaffolding

Just today I found out a new version of the Azure IoT Edge extension for VSCode is available. Amongst other changes like new commands, Microsoft also introduced a new folder structure and new files.

Microsoft also introduced a migration wizard for old modules.

This was a bit of a confusion. My first thoughts were that Microsoft offered migration from the old 1.1 modules (based on classes) to the new (Docker-based) modules.

But this migration is offered for previous built C# modules and IoT Edge Azure functions. Microsoft offers some documentation but let’s look at this migration in detail.

I have built and blogged about a C# Heartbeat module. Let’s migrate it.

Prerequisites

What you need is:

  • a previously built C# module or an IoT Edge Azure Function
  • the module is deployed to an image repository (I use hub.docker.com in this example)
  • VSCode
  • The latest 0.2.0 IoT Edge Extension
  • Docker running locally
  • Being logged in into the Repository environment at the dos prompt (perform a ‘docker login’)

Load the project

In my case, I took the existing IoT Edge Heartbeat module and opened the containing folder in VSCode. With a right-click on the .csproj file, I selected “Convert to IoT Edge Module”:

I was prompted for the name of the image repository. I changed the existing name to ‘svelde/iot-edge-heartbeat’:

This name ends up in a new file named module.json. There is also a property named version. I changed it to 2.0:

So in the end, this wizard added three files:

Now compile it (just press control-shift-b) and when asked for, select Build. Please check if the project builds correctly.

Deployment

So we have the same code but now in a new solution.

Just right-click the module.json file again:

We can build and push the module in one step. Let’s do that!

We are then asked about the type of Image we want to produce: Windows or Linux:

I select amd64 because I target Linux…

The deployment to my image repository is started:

The push refers to repository [docker.io/svelde/iot-edge-heartbeat]
6df228489xxxx: Layer already exists
66aac04baxxxx: Layer already exists
60c326a19xxxx: Layer already exists
97490e4e4xxxx: Layer already exists
fb1b6aca02xxxx: Layer already exists
e1df5dc88xxxx: Layer already exists
2.1-amd64: digest: sha256:1eeefd15816475b12b6b5f12bbfafa5faf4c52fff04b11cb61aa9448d28bxxxx size: 1580
PS C:\dev\edgev2\iot.edge.heartbeat>

So the push is performed. And if we check the image repository, the file can be seen there:

So the deployment is executed correctly.

What is interesting, is the change name of the image. It now exposes what kind of platform it is constructed for.

Conclusion

The migration is not that hard to understand but the combination of migrating and using the deployment tooling differs at a few points.

This new deployment wizard makes it again a bit easier to deploy our modules to an image repository.

Azure Functions are migrated the same way and pushing should be done the same way.

Advertenties