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

Connect vscode to distroboxes via podman? #883

Closed
castrojo opened this issue Feb 9, 2024 · 6 comments · Fixed by #915
Closed

Connect vscode to distroboxes via podman? #883

castrojo opened this issue Feb 9, 2024 · 6 comments · Fixed by #915

Comments

@castrojo
Copy link
Member

castrojo commented Feb 9, 2024

The gift that keeps on giving! Luca thinks we can use this:

https://github.com/89luca89/distrobox/blob/main/docs/posts/integrate_vscode_distrobox.md#third-step-podman-wrapper

to connect podman to distroboxes, that way people can have their cake and eat it too if they just have to have their distroboxes connected to vscode. We could toss this wrapper on the image somewhere and then have people opt-in or ujust switch to this perhaps as an option?

Leaving this open for discussion and if someone wants to pick it up.

@89luca89
Copy link
Contributor

89luca89 commented Feb 9, 2024

Posting an updated version of the wrapper (will update the docs one day :P)

#!/bin/bash
set -x

# This little workaround is used to ensure
# we use our $USER inside the containers, without
# resorting to creating devcontainer.json or similar stuff
arr=("$@")
id="$( echo "$@" | rev | cut -d' ' -f2 | rev)"
# if exec && distrobox -> use distrobox-enter --
if  [ "$(flatpak-spawn --host podman inspect --type container --format '{{.Config.Labels.manager}}' "${id}")" == "distrobox" ]; then
    for i in "${!arr[@]}"; do
        if [[ ${arr[$i]} == *"root:root"* ]]; then
            arr[$i]="$(echo "${arr[$i]}" | sed "s|root:root|$USER:$USER|g")"
        fi
    done
fi
flatpak-spawn --host podman "${arr[@]}"

It checks for labels in order to do the user-swap only on distroboxes
It should be trivial to add a check for toolbx too, so they can also benefit from this!

@castrojo castrojo linked a pull request Feb 9, 2024 that will close this issue
@castrojo
Copy link
Member Author

castrojo commented Feb 10, 2024

Ok this is on the host now via another PR. I think we need to add the remote vscode extension to the profile (I can work on this), anything else?

@89luca89
Copy link
Contributor

Yes needs the remote extension, and a setting to use this instead of docker

Which I wouldn't do by default I guess

@castrojo
Copy link
Member Author

I added the extension: https://github.com/ublue-os/bluefin/pull/888/files

I'll post on the forum and get feedback before we close this.

@m2Giles
Copy link
Member

m2Giles commented Feb 13, 2024

Can confirm that this works with distrobox. Toolbox did not work with a standard toolbox but worked with a quadlet based one (sorta still connected as root)

Oddities I noticed, since I had setup dotfiles with the dev-containers extension, it pulled in my dotfiles deploy script unexpectedly.

Additionally, it does not fully set-up everything for distrobox and toolbox. You will need to manually setup some environment variables to get distrobox-host-exec to work.

This worked best with distroboxes with their own $HOME.

I like that this is on disk. I'm unsure I would have this be the default experience.

It should be easy to use jq to add the necessary keys to the config.json to automate enabling and disabling this using a just command.

@89luca89
Copy link
Contributor

Additionally, it does not fully set-up everything for distrobox and toolbox. You will need to manually setup some environment variables to get distrobox-host-exec to work.
This worked best with distroboxes with their own $HOME.

Yes because it does not actually do a distrobox enter
It would be better if we manage to do it with distrobox enter, but I didn't manage to do it

Maybe needs more work/testing

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