arnaupv / nvim-devcontainer-cli

MIT License
72 stars 0 forks source link

DevcontainerUp fails with exec format error #9

Open stickperson opened 1 year ago

stickperson commented 1 year ago

Neovim version: v0.9.1 OS: macOS Venture (M2 chip) Error: I see the following error when running DevcontainerUp

#0 154.7 + + curl -s https://api.github.com/repos/jesseduffield/lazygit/releases/latest
#0 154.7 grep -Po "tag_name": "v\K[^"]*
#0 155.1 + LAZYGIT_VERSION=0.38.2
#0 155.1 + curl -Lo lazygit.tar.gz https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_0.38.2_Linux_x86_64.tar.gz
#0 155.1   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
#0 155.1                                  Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 5502k  100 5502k    0     0  4100k      0  0:00:01  0:00:01 --:--:-- 6869k
#0 156.5 + tar xf lazygit.tar.gz lazygit
#0 156.6 + install lazygit /usr/local/bin
#0 156.6 + rm lazygit.tar.gz lazygit
#0 156.6 + curl -LO https://github.com/neovim/neovim/releases/download/v0.8.3/nvim.appimage
#0 156.6   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
#0 156.6                                  Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0
100 14.6M  100 14.6M    0     0  4725k      0  0:00:03  0:00:03 --:--:-- 9486k
#0 159.8 + chmod u+x nvim.appimage
#0 159.8 + ./nvim.appimage --appimage-extract
#0 159.8 ./root_setup.sh: 49: ./nvim.appimage: Exec format error
------
ERROR: failed to solve: executor failed running [/bin/sh -c ./root_setup.sh]: exit code: 2
Error: Command failed: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /var/folders/lj/6_5xmzvn1r91cqnmkjp568_40000gn/T/devcontainercli/contai
ner-features/0.46.0-1688010510960/Dockerfile-with-features -t vsc-nvim-devcontainer-cli-032014f2e706f27e325ddc3ab8c4fe5dcb126d18463d55a7526c170c88138293 --targe
t dev_containers_target_stage --build-arg USER_NAME=my-app --build-arg GROUP_NAME=my-app --build-arg _DEV_CONTAINERS_BASE_IMAGE=builder /private/tmp/nvim-devcon
tainer-cli
    at Nte (/opt/homebrew/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:2008:1698)
    at async cC (/opt/homebrew/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:2007:1691)
    at async QN (/opt/homebrew/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:2007:610)
    at async Zte (/opt/homebrew/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:2024:3660)
    at async Kf (/opt/homebrew/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:2024:4775)
    at async wne (/opt/homebrew/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:2156:12125)
    at async bne (/opt/homebrew/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:2156:11866)
{"outcome":"error","message":"Command failed: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /var/folders/lj/6_5xmzvn1r91cqnmkjp568_40000gn/T
/devcontainercli/container-features/0.46.0-1688010510960/Dockerfile-with-features -t vsc-nvim-devcontainer-cli-032014f2e706f27e325ddc3ab8c4fe5dcb126d18463d55a75
26c170c88138293 --target dev_containers_target_stage --build-arg USER_NAME=my-app --build-arg GROUP_NAME=my-app --build-arg _DEV_CONTAINERS_BASE_IMAGE=builder /
private/tmp/nvim-devcontainer-cli","description":"An error occurred building the image."}

[Process exited 1]

Steps to reproduce: Clone this repo, cd into the root, open neovim and run DevcontainerUp

arnaupv commented 1 year ago

The error message you encountered, "./nvim.appimage: Exec format error," typically indicates that the executable file is not compatible with the architecture of your system (M2 ARM). In your case, the issue is likely arising from running the command in a Docker image for Ubuntu 20.04 on a macOS machine with an M2 chip.

So the way how the current plugin installs NVIM inside the Docker container here, is not compatible with the architecture of your host. In order to fix that, the way nvim is installed in the Docker container (based on ubuntu 20.04) needs to be adapted to your architecture.

I'm currently aware of this problem and there is an enhancement created already: #5 So closing this issue in favor of #5.

In fact, I'm currently working on that, we can continue the discussion in the other issue @stickperson

arnaupv commented 1 year ago

It looks like currently there are no nvim.appimage built for arm / aarch64 architecture https://github.com/neovim/neovim/issues/15143

arnaupv commented 1 year ago

The PR has been merged @stickperson , can you check if it works now in your machine? There can still be issues as I do not have access to a mac with m2 arm architecture.

stickperson commented 1 year ago

There's an issue with spam_container.sh where env is passed in as an empty string. I'm not setting anything special, just copying what's in the README. After removing the env check, I could get the build up and running. DevcontainerConnect doesn't seem to do anything though; it exits nvim and that's it.

arnaupv commented 1 year ago

With this PR https://github.com/arnaupv/nvim-devcontainer-cli/pull/11 I'm fixing the problem from DevcontainerConnect: (if you still experience problems, these are the commands I'm using for opening a new terminal in Mac) https://github.com/arnaupv/nvim-devcontainer-cli/blob/main/bin/connect_to_devcontainer.sh#L33-L38 It would be great if you can check if it works in your machine or adjust such lines to make it work!

Also the env problem, is also fixed in this other PR: https://github.com/arnaupv/nvim-devcontainer-cli/pull/12

Both PRs have been merged.

arnaupv commented 1 year ago

Hi @stickperson the DevcontainerConnect command still is not working on iTerm and Mac Terminal. What you can do instead to try the plugin after running DevcontainerUp is leaving neovim and from the root folder of the repo run the following script: ./bin/open_shell_in_devcontainer.sh this will connect you to the devcontainer and you can try stuff there

However this is definitely far from ideal. In order to make DevcontainerConnect work for MacOS, we need to fix the problem here with iTerm and Terminal (This problem is not present for Alacritty or Gnome-Terminal for instance).

The problem is here, where the command open -a iTerm.app will open a new terminal and try to run this script "${SCRIPT_DIR}"/open_shell_in_devcontainer.sh from the HOME folder! And that's the problem!! Ideally this should have to open another terminal in the same folder than the first terminal (this is the behavior for Gnome-Terminal and Alacritty, but not for iTerm or Terminal).

I'm not familiar on MacOS but for fixing that looks like an applescript could do the work for us, it would be great if you can try it out!

tell application "iTerm"
    activate
    if exists window 1 then
        set currentDir to (quoted form of (get target of current session of window 1 as string))
    else
        set currentDir to ""
    end if
    set newWindow to (create window with default profile)
    tell newWindow
        tell current session
            write text "cd " & currentDir
            write text "${SCRIPT_DIR}"/open_shell_in_devcontainer.sh
        end tell
    end tell
end tell

Save this script in new_iterm_window.scpt and then execute it from an iTerm open -a iTerm.app "osascript new_iterm_window.scpt" ... Or maybe this is too cumbersome and the only thing that's needed is to Configure iTerm throught the configurations clicking somewhere to force that when a terminal is open from another terminal the folder is preserved.