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

direnv not working in devcontainer #1106

Closed
giannoug opened this issue Dec 28, 2023 · 13 comments · Fixed by #1107
Closed

direnv not working in devcontainer #1106

giannoug opened this issue Dec 28, 2023 · 13 comments · Fixed by #1107

Comments

@giannoug
Copy link
Contributor

This is (probably) the last issue with dev containers, but I have no idea how to fix.

After opening a dev container, running any command that requires the venv to be activated (i.e. have packages in PATH) fails. For example:

vscode ➜ /workspaces/flux-cluster-template (main) $ task configure
Any conflicting config in the root kubernetes and ansible directories will be overwritten... continue? [y/N]
y
task: [configure] ansible-playbook configure.yaml
"ansible-playbook": executable file not found in $PATH
task: Failed to run task "configure": exit status 127

How is that handled in the project? Is the venv activated in task files? Is the path manually set? For the time being I just source .venv/bin/activate before running any task.

@onedr0p
Copy link
Owner

onedr0p commented Dec 28, 2023

task deps should set up the venv and then the taskfiles should have that in the env section that updates PATH with the venv bin path.

@giannoug
Copy link
Contributor Author

This didn't work when I had it setup in Linux too, so it's not a dev container issue. From brew I understand you are on a Mac. I also found this: go-task/task#482

@onedr0p
Copy link
Owner

onedr0p commented Dec 28, 2023

Funny how I was already subscribed to that issue 😂. Yeah I don't have a bunch of systems to test on so many with mac it just works?

@onedr0p
Copy link
Owner

onedr0p commented Dec 28, 2023

Actually come to think of it, maybe it is direnv setting that all up and it's not really needed in the taskfile?

@giannoug
Copy link
Contributor Author

You mean we can set it in .envrc instead of Taskfile.yaml? Not sure, haven't used neither of them. I also discovered that direnv is not installed in dev container, so I might want to check that first.

@onedr0p
Copy link
Owner

onedr0p commented Dec 28, 2023

Installing direnv might be easy, the harder part might be getting it hooked into the zsh shell

https://direnv.net/docs/hook.html#zsh

@giannoug
Copy link
Contributor Author

giannoug commented Dec 28, 2023

Fortunately it's done automatically according to docs:

Installs direnv and sets up hooks

Problem is, the feature I linked above doesn't seem to work in the project 🤔 It breaks upon dev container creation Fixed, I copy-pasted the example in the repo which is missing version number. direnv works now, checking original issue and possible fix with direnv.

@onedr0p
Copy link
Owner

onedr0p commented Dec 28, 2023

maybe we need to remove the task deps from the post install?

@giannoug
Copy link
Contributor Author

Whoops, sorry I edited my comment before your reply. I got it working, I'm now checking the PATH issue!

@giannoug
Copy link
Contributor Author

Yeah, that did it.

vscode ➜ /workspaces/flux-cluster-template (main) $ echo $PATH                      
/workspaces/flux-cluster-template/.venv/bin:/vscode/vscode-server/bin/linux-x64/0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2/bin/remote-cli:/usr/local/python/current/bin:/usr/local/py-utils/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/vscode/.local/bin

Problem is, automatic hooking didn't work even though it's supposed to. I'll open an issue on the feature repo. In the meantime I think we can work on cleaning up Taskfile env declarations and moving them to envrc. It seems that there are variables defined twice (e.g. SOPS_AGE_KEY_FILE) 🤔

Of course, task configure now runs:

vscode ➜ /workspaces/flux-cluster-template (main) $ task configure
Any conflicting config in the root kubernetes and ansible directories will be overwritten... continue? [y/N]
y
task: [configure] ansible-playbook configure.yaml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Cluster Installation] ****************************************************************************************************************************************************************************
^Ctask: Signal received: "interrupt"
 [ERROR]: User interrupted execution
task: Failed to run task "configure": exit status 99

@onedr0p
Copy link
Owner

onedr0p commented Dec 28, 2023

I wonder do you think if we used bash instead of zsh direnv would work?

@giannoug
Copy link
Contributor Author

It doesn't seem to work at all:

vscode ➜ /workspaces/flux-cluster-template (main) $ cat /etc/bash.bashrc | grep direnv 
vscode ➜ /workspaces/flux-cluster-template (main) $ cat /etc/zsh/zshrc | grep direnv

I gave it a try though, just to be sure:

vscode ➜ /workspaces/flux-cluster-template (devcontainer-direnv) $ task configure
Any conflicting config in the root kubernetes and ansible directories will be overwritten... continue? [y/N]
y
task: [configure] ansible-playbook configure.yaml
"ansible-playbook": executable file not found in $PATH
task: Failed to run task "configure": exit status 127
vscode ➜ /workspaces/flux-cluster-template (devcontainer-direnv) $ echo $0
/bin/bash

I've opened an issue on the feature repo and waiting for input

@onedr0p onedr0p changed the title executable file not found in $PATH in dev container direnv not working in devcontainer Jan 23, 2024
@onedr0p
Copy link
Owner

onedr0p commented Jan 23, 2024

I have fixed this in the latest devcontainer, @giannoug I will close this issue. Will reopen if there's more issues.

@onedr0p onedr0p closed this as completed Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants