[v4,16/16] isar-bootstrap: Connect to gpg-agent before adding keys

Message ID c5ccdb1e-dd40-8d17-9db9-0641d80d3482@siemens.com
State Superseded, archived
Headers show
Series None | expand

Commit Message

Jan Kiszka Sept. 24, 2020, 1:10 a.m. UTC
From: Jan Kiszka <jan.kiszka@siemens.com>

We have recurring issues in CI with the gpg-agent not being ready when
trying to use apt-key:

gpg: can't connect to the agent: IPC connect call failed

Work around this by connecting upfront to the agent, retrying that in a
bounded loop.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---

This one seems to work fine.

Not sure if killing the agent is needed. In most cases, Isar runs in 
more (VMs) or less (containers) isolated environments anyway. I case it
doesn't, wouldn't killing possibly affects what the user started before 
running Isar?

 meta/recipes-core/isar-bootstrap/isar-bootstrap.inc | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Patch

diff --git a/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc b/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc
index fbfe669d..1c5dba74 100644
--- a/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc
+++ b/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc
@@ -303,10 +303,13 @@  isar_bootstrap() {
                              "${ROOTFSDIR}/etc/apt/apt.conf.d/50isar.conf"
             find ${APT_KEYS_DIR}/ -type f | while read keyfile
             do
-                kfn="$(basename $keyfile)"
+                export kfn="$(basename $keyfile)"
                 cp $keyfile "${ROOTFSDIR}/tmp/$kfn"
-                chroot "${ROOTFSDIR}" /usr/bin/apt-key \
-                   --keyring ${THIRD_PARTY_APT_KEYRING} add "/tmp/$kfn"
+                chroot "${ROOTFSDIR}" sh -c '
+                    for i in $(seq 10); do
+                        /usr/bin/apt-key --keyring ${THIRD_PARTY_APT_KEYRING} add "/tmp/$kfn" && break
+                        sleep 1
+                    done'
                 rm "${ROOTFSDIR}/tmp/$kfn"
             done