From bf54398176822943653aaec8ec25a4f4e17f123f Mon Sep 17 00:00:00 2001 From: Aidan Gallagher Date: Wed, 2 Oct 2024 12:23:21 +0100 Subject: [PATCH] Run: Fix problem where ~/.config wasn't being mounted --- debpic/python/debpic_test.py | 6 +++--- debpic/python/run.py | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/debpic/python/debpic_test.py b/debpic/python/debpic_test.py index 775be79..05299af 100644 --- a/debpic/python/debpic_test.py +++ b/debpic/python/debpic_test.py @@ -65,14 +65,14 @@ def test_run_container(self): assert self.cli_commands.pop(0) == "gpgconf --list-dir homedir" assert ( self.cli_commands.pop(0) - == """docker run --mount type=bind,src=${PWD},dst=/workspaces/code --mount type=volume,src=debpic_cache,dst=/home/docker/.cache --user 1000:$(id -g 1000) --network host --tty --rm --env DEB_BUILD_OPTIONS="" test_name /bin/bash -c 'if [[ -x /usr/bin/hook ]]; then /usr/bin/hook; fi && dpkg-buildpackage && mv-debs && dpkg-buildpackage --target=clean'""" + == """docker run --mount type=bind,src=${PWD},dst=/workspaces/code --mount type=volume,src=debpic_cache,dst=/home/docker/.cache --mount type=bind,src=$HOME/.config,dst=/home/docker/.config,readonly --user 1000:$(id -g 1000) --network host --tty --rm --env DEB_BUILD_OPTIONS="" test_name /bin/bash -c 'if [[ -x /usr/bin/hook ]]; then /usr/bin/hook; fi && dpkg-buildpackage && mv-debs && dpkg-buildpackage --target=clean'""" ) run.run_container("test_name", "echo I'm a test command") assert self.cli_commands.pop(0) == "gpgconf --list-dirs agent-socket" assert self.cli_commands.pop(0) == "gpgconf --list-dir homedir" assert ( self.cli_commands.pop(0) - == """docker run --mount type=bind,src=${PWD},dst=/workspaces/code --mount type=volume,src=debpic_cache,dst=/home/docker/.cache --user 1000:$(id -g 1000) --network host --tty --rm --env DEB_BUILD_OPTIONS=\"\" test_name /bin/bash -c 'if [[ -x /usr/bin/hook ]]; then /usr/bin/hook; fi && echo I'm a test command'""" + == """docker run --mount type=bind,src=${PWD},dst=/workspaces/code --mount type=volume,src=debpic_cache,dst=/home/docker/.cache --mount type=bind,src=$HOME/.config,dst=/home/docker/.config,readonly --user 1000:$(id -g 1000) --network host --tty --rm --env DEB_BUILD_OPTIONS=\"\" test_name /bin/bash -c 'if [[ -x /usr/bin/hook ]]; then /usr/bin/hook; fi && echo I'm a test command'""" ) run.run_container("test_name", "", "", "--interactive") @@ -80,5 +80,5 @@ def test_run_container(self): assert self.cli_commands.pop(0) == "gpgconf --list-dir homedir" assert ( self.cli_commands.pop(0) - == """docker run --mount type=bind,src=${PWD},dst=/workspaces/code --mount type=volume,src=debpic_cache,dst=/home/docker/.cache --user 1000:$(id -g 1000) --network host --tty --rm --env DEB_BUILD_OPTIONS="" --interactive test_name """ + == """docker run --mount type=bind,src=${PWD},dst=/workspaces/code --mount type=volume,src=debpic_cache,dst=/home/docker/.cache --mount type=bind,src=$HOME/.config,dst=/home/docker/.config,readonly --user 1000:$(id -g 1000) --network host --tty --rm --env DEB_BUILD_OPTIONS="" --interactive test_name """ ) diff --git a/debpic/python/run.py b/debpic/python/run.py index 09af216..476fb16 100644 --- a/debpic/python/run.py +++ b/debpic/python/run.py @@ -50,7 +50,8 @@ def run_container( --mount type=bind,src={gpg_home}/trustdb.gpg,dst=/home/docker/.gnupg/trustdb.gpg,readonly""" config_mount_cmd = "" - if os.path.exists("$HOME/.config"): + home = os.path.expanduser("~") + if os.path.exists(f"{home}/.config"): config_mount_cmd = ( "--mount type=bind,src=$HOME/.config,dst=/home/docker/.config,readonly" )