Iotedge: Variables in module.json

Created on 24 Jul 2018  路  8Comments  路  Source: Azure/iotedge

Expected Behavior

Variables should be substituted in both deployment.template.json and module.json

Current Behavior

I can set variables in .env that are used in deployment.template.json but these aren't populated in module.json file.

We use different environments for dev and prod and hence different container registrys as well. Currently there doesn't seem to be a way to use variables in module.json, specifically the repository value. It'd be great to use $CONTAINER_REGISTRY_SERVER in module.json as well as deployment.template.json

Similar to this, an ability for a CI system (e.g. VSTS) to set the tag version in module.json for CI/CD

e.g. module.json could look like

{
    "$schema-version": "0.0.1",
    "description": "",
    "image": {
        "repository": "$CONTAINER_REGISTRY_SERVER/myiotmodule",
        "tag": {
            "version": "$TAG_VERSION",
            "platforms": {
                "linuxx64": "./Dockerfile"
            }
        }
    },
    "language": "csharp"
}
customer-reported iotedge

Most helpful comment

Some formal docs on module.json would be nice. Might expose the various consistency issues too. I too was stumped by this and was just about to go down the path of ditching the use of module.json and iotedgedev.

All 8 comments

@shizn Could you please take a look. Thanks!

@damienpontifex , If you are using vscode-iot-edge-extension currently, you can use variables in module.json. And the values are expanded in the final deployment.json (deployment manifest). (Run command "Generate IoT Edge Deployment Manifest" or "Build Solution")

And I found you are mention CI system. We have VSTS plugin for the CI of IoT edge Project. We will double check this feature is enabled in the plugin and keep you updated.

@adashen yes I can get that behaviour with deployment.json, but it'd be good to have the same with module.json for values specific to that module and it's docker image

And yes, I'm using the VSTS IoT Edge task off the marketplace and seeing the same behaviour working correctly in deployment.json but not module.json

Is this process just a string pattern replacement step? I could reproduce that in VSTS with other tasks to substitute build variables if that's the case.

@damienpontifex currently, the env in module.json will be expanded when generating the final deployment.json.

Does your request is

  1. Expand env in module.json and out the result to another module.json file?

So can you provide more detail about your requirement in the scenario where you want the expanded module.json be used?

@damienpontifex, For VSTS Edge extension, actually there's a test case here to track the variable expand in both deployment.template.json and module.json.

Here's my module.json

{
    "$schema-version": "0.0.1",
    "description": "",
    "image": {
        "repository": "michaeljqzq/multi-1${zhiqing}",
        "tag": {
            "version": "0.0.1${zhiqing}",
            "platforms": {
                "amd64": "./Dockerfile",
                "amd64.debug": "./Dockerfile.amd64.debug",
                "arm32v7": "./Dockerfile.arm32v7",
                "windows-amd64": "./Dockerfile"
            }
        }
    },
    "language": "csharp"
}

Here's variable setting in VSTS
image

Here's the final docker image to push:

docker push ***/multi-1master:0.0.1master-amd64

By the way, are you using the latest version of VSTS extension? If not, you can upgrade to latest extension to verify the env expand function.

Thanks everyone for the support and rapid replies. Using the format ${VARIABLE} worked in both files.

Some formal docs on module.json would be nice. Might expose the various consistency issues too. I too was stumped by this and was just about to go down the path of ditching the use of module.json and iotedgedev.

@adashen to share the schema of module.json

Was this page helpful?
0 / 5 - 0 ratings