[RFC] add support for running inside vscode devcontainer

19 views
Skip to first unread message

Felix Moessbauer

unread,
Mar 22, 2024, 3:12:24 PMMar 22
to kas-...@googlegroups.com, jan.k...@siemens.com, Felix Moessbauer, Matthias Schnelte
When running inside a vscode devcontainer, git credential settings are
injected using a modified .gitconfig file. In addition, the injected
credential handler needs access to environment variables like
REMOTE_CONTAINERS_IPC.

As all this is rather undocumented territory, we first detect if we are
running inside a remotecontainers environment and then forward all
REMOTE_CONTAINERS_* variables. This should also enable the use of kas in
the github codespaces (not tested).

Xref: https://patchwork.yoctoproject.org/project/bitbake/patch/20231002064106....@schnelte.de/

Proposed-by: Matthias Schnelte <dev...@schnelte.de>
Signed-off-by: Felix Moessbauer <felix.mo...@siemens.com>
---
kas/context.py | 7 +++++++
kas/libcmds.py | 6 ++++--
2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/kas/context.py b/kas/context.py
index 6ca529151..8ac6205d1 100644
--- a/kas/context.py
+++ b/kas/context.py
@@ -111,6 +111,13 @@ class Context:
if val:
self.environ[key] = val

+ # make remote containers environment available in kas
+ if os.environ.get('REMOTE_CONTAINERS', False) == 'true':
+ logging.debug('Running inside devcontainer environment')
+ for k in os.environ.keys():
+ if k.startswith('REMOTE_CONTAINERS_'):
+ self.environ[k] = os.environ[k]
+
@property
def build_dir(self):
"""
diff --git a/kas/libcmds.py b/kas/libcmds.py
index b64d186a6..955d63ca9 100644
--- a/kas/libcmds.py
+++ b/kas/libcmds.py
@@ -223,9 +223,11 @@ class SetupHome(Command):
gitconfig_host = os.environ.get('GITCONFIG_FILE', False)
gitconfig_kas = self.tmpdirname + '/.gitconfig'

- # when running in the github ci, always try to read the gitconfig
+ # when running in the github ci or a vscode devcontainer,
+ # always try to read the gitconfig
if not gitconfig_host and \
- os.environ.get('GITHUB_ACTIONS', False) == 'true':
+ os.environ.get('GITHUB_ACTIONS', False) == 'true' or \
+ os.environ.get('REMOTE_CONTAINERS', False) == 'true':
gitconfig_host = os.path.expanduser('~/.gitconfig')

if gitconfig_host and os.path.exists(gitconfig_host):
--
2.39.2

Jan Kiszka

unread,
Mar 25, 2024, 11:05:25 AMMar 25
to Felix Moessbauer, kas-...@googlegroups.com, Matthias Schnelte
This should probably also be documented somewhere. Other than that, it
looks good to me. Some further tested-by would still be nice.

Jan

--
Siemens AG, Technology
Linux Expert Center

MOESSBAUER, Felix

unread,
Apr 14, 2024, 8:21:50 AMApr 14
to kas-...@googlegroups.com, dev...@schnelte.de, Kiszka, Jan
On Fri, 2024-03-22 at 20:12 +0100, Felix Moessbauer wrote:
> When running inside a vscode devcontainer, git credential settings
> are
> injected using a modified .gitconfig file. In addition, the injected
> credential handler needs access to environment variables like
> REMOTE_CONTAINERS_IPC.
>
> As all this is rather undocumented territory, we first detect if we
> are
> running inside a remotecontainers environment and then forward all
> REMOTE_CONTAINERS_* variables. This should also enable the use of kas
> in
> the github codespaces (not tested).

@Matthias: Did you find the time to test this? I by myself
unfortunately don't have a vs-devcontainer environment (podman
user...).

Best regards,
Felix
Reply all
Reply to author
Forward
0 new messages