Skip to content

Commit

Permalink
Run: Only mount gpg if gpg is installed and files exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Aidan Gallagher committed Aug 5, 2024
1 parent eaed231 commit d21de60
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion checks.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ else
SUFFIX := "
endif

all: black mypy pytest package lintian clean
all: black isort mypy pytest package lintian clean
@echo SUCCESS

black:
Expand Down
6 changes: 3 additions & 3 deletions debpic/python/debpic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,21 @@ 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 --mount type=bind,src=/run/user/1000/gnupg/S.gpg-agent,dst=/home/docker/.gnupg/S.gpg-agent,readonly --mount type=bind,src=/home/debpic_user/.gnupg/pubring.kbx,dst=/home/docker/.gnupg/pubring.kbx,readonly --mount type=bind,src=/home/debpic_user/.gnupg/trustdb.gpg,dst=/home/docker/.gnupg/trustdb.gpg,readonly --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'"""
== """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 --mount type=bind,src=/run/user/1000/gnupg/S.gpg-agent,dst=/home/docker/.gnupg/S.gpg-agent,readonly --mount type=bind,src=/home/debpic_user/.gnupg/pubring.kbx,dst=/home/docker/.gnupg/pubring.kbx,readonly --mount type=bind,src=/home/debpic_user/.gnupg/trustdb.gpg,dst=/home/docker/.gnupg/trustdb.gpg,readonly --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'"
== """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")
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 --mount type=bind,src=/run/user/1000/gnupg/S.gpg-agent,dst=/home/docker/.gnupg/S.gpg-agent,readonly --mount type=bind,src=/home/debpic_user/.gnupg/pubring.kbx,dst=/home/docker/.gnupg/pubring.kbx,readonly --mount type=bind,src=/home/debpic_user/.gnupg/trustdb.gpg,dst=/home/docker/.gnupg/trustdb.gpg,readonly --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 '
== """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 """
)
20 changes: 14 additions & 6 deletions debpic/python/run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import os.path
import subprocess
import sys
from shutil import which

import common

Expand Down Expand Up @@ -35,18 +37,24 @@ def run_container(

deb_build_options = os.environ.get("DEB_BUILD_OPTIONS", "")

# TODO: If the host doesn't have gpg installed then skip this.
gpg_socket = common.run("gpgconf --list-dirs agent-socket").strip()
gpg_home = common.run("gpgconf --list-dir homedir").strip()
gpg_mount_cmds = ""
if which("gpg") is not None:
gpg_socket = common.run("gpgconf --list-dirs agent-socket").strip()
gpg_home = common.run("gpgconf --list-dir homedir").strip()

if os.path.exists(f"{gpg_home}/pubring.kbx"):
if os.path.exists(f"{gpg_home}/trustdb.gpg"):
gpg_mount_cmds = f"""\
--mount type=bind,src={gpg_socket},dst=/home/docker/.gnupg/S.gpg-agent,readonly
--mount type=bind,src={gpg_home}/pubring.kbx,dst=/home/docker/.gnupg/pubring.kbx,readonly
--mount type=bind,src={gpg_home}/trustdb.gpg,dst=/home/docker/.gnupg/trustdb.gpg,readonly"""

run_cmd = f"""\
docker run
--mount type=bind,src=${{PWD}},dst=/workspaces/code
--mount type=volume,src=debpic_cache,dst=/home/docker/.cache
--mount type=bind,src={gpg_socket},dst=/home/docker/.gnupg/S.gpg-agent,readonly
--mount type=bind,src={gpg_home}/pubring.kbx,dst=/home/docker/.gnupg/pubring.kbx,readonly
--mount type=bind,src={gpg_home}/trustdb.gpg,dst=/home/docker/.gnupg/trustdb.gpg,readonly
--mount type=bind,src=$HOME/.config,dst=/home/docker/.config,readonly
{gpg_mount_cmds}
--user {common.get_uid()}:$(id -g {common.get_uid()})
--network host
--tty
Expand Down

0 comments on commit d21de60

Please sign in to comment.