Azure-docs: Error in VS Code when creating IoT Edge module project

Created on 15 Oct 2018  Â·  5Comments  Â·  Source: MicrosoftDocs/azure-docs

Hi,

I have encountered an error in VS Code at the following point in the Python IoT Edge module tutorial: Step 5 under the heading "Create an IoT Edge module project", subheading "Create a new solution". I am being asked to run the command "Azure IoT Edge: New IoT Edge solution" in the command palette.

The command being executed by VS Code appears to be:
cookiecutter --no-input https://github.com/Azure/cookiecutter-azure-iot-edge-module module_name=PythonModule image_repository=<my-repository-address>/pythonmodule --checkout master

After the Python traceback there is the following message:
subprocess.CalledProcessError: Command '['git', 'clone', 'https://github.com/Azure/cookiecutter-azure-iot-edge-module']' returned non-zero exit status 128.
Error: Command failed with exit code 1

I have a suspicion that this is caused by my corporate proxy. I needed to install Git to get this command to run in the first place, but if I do not set the proxy settings by running "git config --global http.proxy http://proxyuser:[email protected]:8080" in the terminal, I get an identical error when running the command myself. Only once I set the correct proxy settings am I able to run this command manually.

I am running Windows 10, with up to date versions of VS Code, the Azure IoT Edge extension, Python, the VS Code Python Extension, Pip, Docker CE (i.e. all the prerequisites), as well as Git for Windows.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

cxp in-progress iot-edgsvc resolved-by-customer triaged

Most helpful comment

Hi,

I've managed to solve the problem. Thanks @shizn for pointing me in the right direction, much appreciated!

I will lay out my solution for future reference in case others have the same issue with a proxy. I had to make changes to three files: deployment.template.json, .env and Dockerfile.amd64. I also needed to deploy via the Azure CLI as the integration with VS Code also didn't work behind a proxy and I was unable to see my edge device in the VS Code explorer.

Prior to these changes, I ran the cookiecutter command while in the modules folder to pull the appropriate files from the repository:
cookiecutter --no-input https://github.com/Azure/cookiecutter-azure-iot-edge-module module_name=PythonModule image_repository=<my-repository-address>/pythonmodule --checkout master

The changes to deployment.template.json and .env were simply doing what the VS Code extension would do if the error had not occurred, but the change to Dockerfile.amd64 is in addition to the original error, as during the Docker build process we must pass through the proxy to run apt-get and pip/pip3.

deployment.template.json

  1. Under modulesContent.$edgeAgent.properties.desired.runtime.settings.registryCredentials I included the following lines:
              "<my-registry-name>": {
                "username": "$CONTAINER_REGISTRY_USERNAME_<my-registry-name>",
                "password": "$CONTAINER_REGISTRY_PASSWORD_<my-registry-name>",
                "address": "<my-registry-address>"
              }
  1. Under modulesContent.$edgeAgent.properties.desired.modules I included the following lines (note these are after the tempsensor structure):
          "PythonModule": {
            "version": "1.0",
            "type": "docker",
            "status": "running",
            "restartPolicy": "always",
            "settings": {
              "image": "${MODULES.PythonModule.amd64}",
              "createOptions": "{}"
            }
  1. Under modulesContent.$edgeHub.properties.desired.routes I included the following lines:
          "PythonModuleToIoTHub": "FROM /messages/modules/PythonModule/outputs/* INTO $upstream",
          "sensorToPythonModule": "FROM /messages/modules/tempSensor/outputs/temperatureOutput INTO BrokeredEndpoint(\"/modules/PythonModule/inputs/input1\")"
  1. (As per the tutorial) I added the following lines under modulesContent at the end of the file:
    "PythonModule": {
      "properties.desired":{
          "TemperatureThreshold":25
      }
    }

.env
This file was not created due to the original error, so I created this file with the following contents:

CONTAINER_REGISTRY_USERNAME_<my-registry-name>="<my-registry-username>"
CONTAINER_REGISTRY_PASSWORD_<my-registry-name>="<my-registry-password>"

Dockerfile.amd64
Please note that I am not certain this is the best practice way of getting apt-get to work behind a proxy.

  1. I included these lines below WORKDIR /app:
ENV HTTP_PROXY=<my-proxy-details>`
RUN echo 'Acquire::http::Proxy "'$HTTP_PROXY'";' > /etc/apt/apt.conf
  1. I changed the pip3 command to include the proxy:
    RUN pip3 install --proxy=$HTTP_PROXY --upgrade pip
  2. I changed the pip command to include the proxy:
    RUN pip install --proxy=$HTTP_PROXY -r requirements.txt

After these changes were made, I was able to build, and push to my repository. Then using the Azure CLI I was able to deploy to my edge device.

All 5 comments

Hi @proctorm . Have you successfully get a python module project in VS Code? Looks like it's your proxy issue. If you haven't resolved this issue, I'd suggest first you can manually download the files from here (https://github.com/Azure/cookiecutter-azure-iot-edge-module/tree/master/%7B%7Bcookiecutter.module_name%7D%7D) and put it in the modules folder. Make sure you update the module.json and deployment.template.json file, so that you can continue the tutorial.
BTW, If you are able to run git clone https://github.com/Azure/cookiecutter-azure-iot-edge-module, the cookiecutter command should work fine.

Let me know if you have any updates to share.

Thanks for your response. I am currently working through the details of what changes I'll need to make to the json files to get this running and will update once I've figured it out, or need extra help. I have been reading the extension source code and think I've figured out where the problem occurs. I'm not at all experienced in Javascript or Node.js, but it seems that Git does not play nicely with child_process.spawn() in terms of passing the proxy environment variables when the command is executed.

Do you think it would be worthwhile adding an issue to vscode-azure-iot-edge for later follow-up?

Hi,

I've managed to solve the problem. Thanks @shizn for pointing me in the right direction, much appreciated!

I will lay out my solution for future reference in case others have the same issue with a proxy. I had to make changes to three files: deployment.template.json, .env and Dockerfile.amd64. I also needed to deploy via the Azure CLI as the integration with VS Code also didn't work behind a proxy and I was unable to see my edge device in the VS Code explorer.

Prior to these changes, I ran the cookiecutter command while in the modules folder to pull the appropriate files from the repository:
cookiecutter --no-input https://github.com/Azure/cookiecutter-azure-iot-edge-module module_name=PythonModule image_repository=<my-repository-address>/pythonmodule --checkout master

The changes to deployment.template.json and .env were simply doing what the VS Code extension would do if the error had not occurred, but the change to Dockerfile.amd64 is in addition to the original error, as during the Docker build process we must pass through the proxy to run apt-get and pip/pip3.

deployment.template.json

  1. Under modulesContent.$edgeAgent.properties.desired.runtime.settings.registryCredentials I included the following lines:
              "<my-registry-name>": {
                "username": "$CONTAINER_REGISTRY_USERNAME_<my-registry-name>",
                "password": "$CONTAINER_REGISTRY_PASSWORD_<my-registry-name>",
                "address": "<my-registry-address>"
              }
  1. Under modulesContent.$edgeAgent.properties.desired.modules I included the following lines (note these are after the tempsensor structure):
          "PythonModule": {
            "version": "1.0",
            "type": "docker",
            "status": "running",
            "restartPolicy": "always",
            "settings": {
              "image": "${MODULES.PythonModule.amd64}",
              "createOptions": "{}"
            }
  1. Under modulesContent.$edgeHub.properties.desired.routes I included the following lines:
          "PythonModuleToIoTHub": "FROM /messages/modules/PythonModule/outputs/* INTO $upstream",
          "sensorToPythonModule": "FROM /messages/modules/tempSensor/outputs/temperatureOutput INTO BrokeredEndpoint(\"/modules/PythonModule/inputs/input1\")"
  1. (As per the tutorial) I added the following lines under modulesContent at the end of the file:
    "PythonModule": {
      "properties.desired":{
          "TemperatureThreshold":25
      }
    }

.env
This file was not created due to the original error, so I created this file with the following contents:

CONTAINER_REGISTRY_USERNAME_<my-registry-name>="<my-registry-username>"
CONTAINER_REGISTRY_PASSWORD_<my-registry-name>="<my-registry-password>"

Dockerfile.amd64
Please note that I am not certain this is the best practice way of getting apt-get to work behind a proxy.

  1. I included these lines below WORKDIR /app:
ENV HTTP_PROXY=<my-proxy-details>`
RUN echo 'Acquire::http::Proxy "'$HTTP_PROXY'";' > /etc/apt/apt.conf
  1. I changed the pip3 command to include the proxy:
    RUN pip3 install --proxy=$HTTP_PROXY --upgrade pip
  2. I changed the pip command to include the proxy:
    RUN pip install --proxy=$HTTP_PROXY -r requirements.txt

After these changes were made, I was able to build, and push to my repository. Then using the Azure CLI I was able to deploy to my edge device.

Glad to know you made it. And really appreciate the detailed steps!!! Thanks a lot.

We will now proceed to close this thread. If there are further questions regarding this matter, please tag me in your reply. We will gladly continue the discussion and we will reopen the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jharbieh picture jharbieh  Â·  3Comments

jamesgallagher-ie picture jamesgallagher-ie  Â·  3Comments

Favna picture Favna  Â·  3Comments

spottedmahn picture spottedmahn  Â·  3Comments

DeepPuddles picture DeepPuddles  Â·  3Comments