Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dapr Extension fails to start sidecar when in Dev Container spawn /bin/sh ENOENT #247

Open
robinmanuelthiel opened this issue Jul 25, 2022 · 6 comments
Labels
bug Something isn't working investigate Issues that require investigation

Comments

@robinmanuelthiel
Copy link
Member

robinmanuelthiel commented Jul 25, 2022

I am trying to use Dapr within a Visual Studio Dev Container. Whenever I want to start the Dapr sidecar using the official daprd Visual Studio Code Task, the spawn /bin/sh ENOENT error appears. When I enter the same command manually to the command line, it works fine.

This is my tasks.json file:

{
  "version": "2.0.0",
  "tasks": [
    // does not work
    {
      "appId": "main",
      "appPort": 60200,
      "label": "daprd-main-debug-old",
      "type": "daprd",
      "componentsPath": "env/dapr/components",
      "logLevel": "debug"
    },
    // works
    {
      "label": "daprd-main-debug",
      "type": "shell",
      "dependsOn": "build-main",
      "isBackground": true,
      "command": "daprd --app-id \"main\" --app-port \"60200\" --components-path \"env/dapr/components\" --log-level \"debug\" --placement-host-address \"localhost:50005\""
    },
    {
      "appId": "main",
      "label": "daprd-main-down",
      "type": "daprd-down"
    }
  ]
}

Does this occur consistently? Yes
Repro steps:

  1. Open a project in a Visual Studio Dev Conainer
  2. Start a Debugging Session that uses the daprd task
  3. See the spawn /bin/sh ENOENT error

image

Details

Find some details about the Dev Container config here.

Dev Container Configuration details

Dockerfile:

ARG VARIANT="buster"
FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT}

# Install Dapr
RUN wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash

# Add daprd to PATH (for VSCode Extension)
ENV PATH "$PATH:/home/vscode/.dapr/bin"

devcontainer.json:

// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.238.1/containers/debian
{
  "name": "wemogy",
  "build": {
    "dockerfile": "Dockerfile",
    // Update 'VARIANT' to pick an Debian version: bullseye, buster
    // Use bullseye on local arm64/Apple Silicon.
    "args": { "VARIANT": "bullseye" }
  },
  "customizations": {
    "vscode": {
      "extensions": [
        "PKief.material-icon-theme",
        "editorconfig.editorconfig",
        "streetsidesoftware.code-spell-checker",
        "esbenp.prettier-vscode",
        "dbaeumer.vscode-eslint",
        "DavidAnson.vscode-markdownlint",
        "k--kato.docomment",
        "eamodio.gitlens",
        "spmeesseman.vscode-taskexplorer",
        "hbenl.vscode-test-explorer",
        "Gruntfuggly.todo-tree",
        "dracula-theme.theme-dracula"
      ],
      "settings": {
        "terminal.integrated.fontFamily": "Menlo, Monaco, 'Courier New', monospace"
      }
    }
  },
  // Use 'forwardPorts' to make a list of ports inside the container available locally.
  "forwardPorts": [60200],

  "postCreateCommand": "dapr uninstall --all && dapr init --slim",

  // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
  "remoteUser": "vscode",

  "features": {
    "docker-from-docker": "latest",
    "terraform": "latest",
    "git": "latest",
    "azure-cli": "latest",
    "node": "lts",
    "dotnet": "latest"
  }
}

Action: vscode-dapr.tasks.daprd
Error type: ENOENT
Error Message: spawn /bin/sh ENOENT

Version: 0.6.0
OS: darwin
OS Release: 21.5.0
Product: Visual Studio Code
Product Version: 1.69.0
Language: en

@robinmanuelthiel
Copy link
Member Author

Here is my workaround until this is fixed.

Below, you can find a working example for a Launch Configuration and the accordings Tasks for starting the Dapr Sidecar, building a .NET Web Application and attach the Debugger to it. It will also kill the Dapr sidecar afterwards.

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch Main",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "daprd-main-debug",
      "program": "${workspaceFolder}/src/webservices/main/Wemogy.Subscriptions.Webservices.Main.Api/bin/Debug/net6.0/Wemogy.Subscriptions.Webservices.Main.Api.dll",
      "args": [],
      "cwd": "${workspaceFolder}/src/webservices/main/Wemogy.Subscriptions.Webservices.Main.Api",
      "stopAtEntry": false,
      "serverReadyAction": {
        "action": "openExternally",
        "pattern": "\\bNow listening on:\\s+(http?://\\S+)"
      },
      "env": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "sourceFileMap": {
        "/Views": "${workspaceFolder}/Views"
      },
      "postDebugTask": "daprd-main-down"
    }
  ]
}
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "build-main",
      "command": "dotnet",
      "type": "process",
      "args": [
        "build",
        "${workspaceFolder}/src/webservices/main/Wemogy.Subscriptions.Webservices.Main.Api/Wemogy.Subscriptions.Webservices.Main.Api.csproj",
        "/property:GenerateFullPaths=true",
        "/consoleloggerparameters:NoSummary"
      ],
      "problemMatcher": "$msCompile"
    },
    // As the official daprd Tasks don't work in Visual Studio Code Dev Containers currently, we manually create
    // shell tasks. GitHub Issue: https://github.com/microsoft/vscode-dapr/issues/247
    {
      "label": "daprd-main-debug",
      "type": "shell",
      "dependsOn": "build-main",
      "command": "daprd",
      "args": [
        "--app-id",
        "main",
        "--app-port",
        "60200",
        "--components-path",
        "env/dapr/components",
        "--placement-host-address",
        "",
        "--log-level",
        "debug"
      ],
      "isBackground": true,
      "problemMatcher": {
        "pattern": [
          {
            "regexp": ".",
            "file": 1,
            "location": 2,
            "message": 3
          }
        ],
        "background": {
          "beginsPattern": "^.*starting Dapr Runtime.*",
          "endsPattern": "^.*(waiting on port|dapr initialized)"
        }
      }
    },
    {
      "label": "daprd-main-down",
      "type": "shell",
      "command": "pkill",
      "args": ["-9", "-f", "daprd --app-id main"],
      "presentation": {
        "clear": true,
        "close": true,
        "reveal": "never"
      }
    }
  ]
}

@philliphoff
Copy link
Member

@robinmanuelthiel I can reproduce this, but have no idea yet what path it's complaining about. I get the same error even when I explicitly specify the path to dapr or daprd. I'll need to do some investigation.

@philliphoff philliphoff added bug Something isn't working investigate Issues that require investigation labels Aug 4, 2022
@philliphoff
Copy link
Member

@robinmanuelthiel So it appears to be this: the Dapr extension is running locally instead of in the container, and hence why it can't find what it's looking for. If I add the extension to the devcontainer.json, it then (almost) works as expected.

For some reason, I have to also go into the extensions tab, locate the Dapr extension, and then press the "reload required" button (which then seems to switch between local and remote). I'm not sure why this is necessary; perhaps because it was already being used locally prior to opening the workspace in the Dev Container? I'll have to look into that further.

@BC89
Copy link

BC89 commented Dec 20, 2022

Facing this issue too. Any resolution?

@BrunoWouters
Copy link

A solution for this problem would be awesome. The reload solution works fine but this problem makes it difficult to rollout to this to the rest of our IT departement.

@NSTA2
Copy link

NSTA2 commented Jan 19, 2024

@robinmanuelthiel So it appears to be this: the Dapr extension is running locally instead of in the container, and hence why it can't find what it's looking for. If I add the extension to the devcontainer.json, it then (almost) works as expected.

For some reason, I have to also go into the extensions tab, locate the Dapr extension, and then press the "reload required" button (which then seems to switch between local and remote). I'm not sure why this is necessary; perhaps because it was already being used locally prior to opening the workspace in the Dev Container? I'll have to look into that further.

Adding "waitFor": "postCreateCommand" to devcontainer.json resolved this reload requirement for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working investigate Issues that require investigation
Projects
None yet
Development

No branches or pull requests

5 participants