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

Array format in postCreateCommand fails to find any dependencies #491

Open
TAM360 opened this issue Aug 17, 2024 · 1 comment
Open

Array format in postCreateCommand fails to find any dependencies #491

TAM360 opened this issue Aug 17, 2024 · 1 comment

Comments

@TAM360
Copy link

TAM360 commented Aug 17, 2024

Hi,

I've a simple .devcontainer.json like which uses golang base image, install 3 different tools (kind, kubebuilder, and kubectl). I am using the array syntax in postCreateCommand to install the packages. Here's the file.

{
  "name": "Kubebuilder DevContainer",
  "image": "golang:1.22-bullseye",
  "features": {
    "ghcr.io/devcontainers/features/docker-in-docker:2": {},
    "ghcr.io/devcontainers/features/git:1": {}
  },

  // Required for running Kind inside DevContainer
  "runArgs": ["--network=host"],

  "customizations": {
    "vscode": {
      "settings": {
        "terminal.integrated.shell.linux": "/bin/bash"
      },
      "extensions": [
        "ms-kubernetes-tools.vscode-kubernetes-tools",
        "ms-azuretools.vscode-docker"
      ]
    }
  },

  "onCreateCommand": [
    // Install Kind
    "curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.24.0/kind-linux-amd64",
    "chmod +x ./kind",
    "mv ./kind /usr/local/bin/kind",

    // Install kubebuilder
    "KUBEBUILDER_LATEST=$(curl -s https://api.github.com/repos/kubernetes-sigs/kubebuilder/releases/latest | grep 'tag_name' | cut -d\\\" -f4)",
    "curl -Lo kubebuilder.tar.gz https://dl.kubebuilder.io/kubebuilder/${KUBEBUILDER_LATEST}/kubebuilder_${KUBEBUILDER_LATEST}_linux_amd64.tar.gz",
    "tar -zxvf kubebuilder.tar.gz -C /usr/local/",
    "rm kubebuilder.tar.gz",
    "ln -s /usr/local/kubebuilder/bin/kubebuilder /usr/local/bin/kubebuilder",

    // Install kubectl
    "KUBECTL_LATEST=$(curl -s https://dl.k8s.io/release/stable.txt)",
    "curl -LO https://dl.k8s.io/release/${KUBECTL_LATEST}/bin/linux/amd64/kubectl",
    "chmod +x ./kubectl",
    "mv ./kubectl /usr/local/bin/kubectl",

    // Verify installations
    "kind version",
    "kubebuilder version",
    "docker --version",
    "go version",
    "kubectl version --client",
    "apt-get clean"
  ]
}

However, the postCreateCommand fails to find the curl binary.

[408195 ms] onCreateCommand failed with exit code 126. Skipping any further user-provided commands.
Error: Command failed: curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.24.0/kind-linux-amd64 chmod +x ./kind mv ./kind /usr/local/bin/kind KUBEBUILDER_LATEST=$(curl -s https://api.github.com/repos/kubernetes-sigs/kubebuilder/releases/latest | grep 'tag_name' | cut -d\" -f4) curl -Lo kubebuilder.tar.gz https://dl.kubebuilder.io/kubebuilder/${KUBEBUILDER_LATEST}/kubebuilder_${KUBEBUILDER_LATEST}_linux_amd64.tar.gz tar -zxvf kubebuilder.tar.gz -C /usr/local/ rm kubebuilder.tar.gz ln -s /usr/local/kubebuilder/bin/kubebuilder /usr/local/bin/kubebuilder KUBECTL_LATEST=$(curl -s https://dl.k8s.io/release/stable.txt) curl -LO https://dl.k8s.io/release/${KUBECTL_LATEST}/bin/linux/amd64/kubectl chmod +x ./kubectl mv ./kubectl /usr/local/bin/kubectl kind version kubebuilder version docker --version go version kubectl version --client apt-get clean
    at N7 (/home/linuxbrew/.linuxbrew/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:235:130)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Am (/home/linuxbrew/.linuxbrew/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:227:4393)
    at async Xw (/home/linuxbrew/.linuxbrew/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:227:3738)
    at async $w (/home/linuxbrew/.linuxbrew/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:227:2745)
    at async fa (/home/linuxbrew/.linuxbrew/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:227:2386)
    at async DtA (/home/linuxbrew/.linuxbrew/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:465:1496)
    at async NH (/home/linuxbrew/.linuxbrew/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:465:964)
    at async KtA (/home/linuxbrew/.linuxbrew/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:482:3771)
    at async eB (/home/linuxbrew/.linuxbrew/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:482:4886)
{"outcome":"error","message":"Command failed: curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.24.0/kind-linux-amd64 chmod +x ./kind mv ./kind /usr/local/bin/kind KUBEBUILDER_LATEST=$(curl -s https://api.github.com/repos/kubernetes-sigs/kubebuilder/releases/latest | grep 'tag_name' | cut -d\\\" -f4) curl -Lo kubebuilder.tar.gz https://dl.kubebuilder.io/kubebuilder/${KUBEBUILDER_LATEST}/kubebuilder_${KUBEBUILDER_LATEST}_linux_amd64.tar.gz tar -zxvf kubebuilder.tar.gz -C /usr/local/ rm kubebuilder.tar.gz ln -s /usr/local/kubebuilder/bin/kubebuilder /usr/local/bin/kubebuilder KUBECTL_LATEST=$(curl -s https://dl.k8s.io/release/stable.txt) curl -LO https://dl.k8s.io/release/${KUBECTL_LATEST}/bin/linux/amd64/kubectl chmod +x ./kubectl mv ./kubectl /usr/local/bin/kubectl kind version kubebuilder version docker --version go version kubectl version --client apt-get clean","description":"The onCreateCommand in the devcontainer.json failed.","containerId":"cef2971520f45f99fc5313bbb8c9b42ad8083b6c5e79d14624091bae9d6c2bcb"}

If I run the same steps inside the devcontainer or pass a shell script, it works just fine. I've gone through the documentation that array syntax doesn't pass the commands to shell, whereas the string format does.

My question is how can I use the array syntax to execute multi line script?

@camilamacedo86
Copy link

Hi @TAM360

See that it is probably permissions issue.
We might need to use root user

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants