olimage build error apt-key adv --keyserver keyserver.ubuntu.com --recv-keys

Started by kimfaint, May 17, 2022, 10:04:46 AM

Previous topic - Next topic

kimfaint

I attempted to use olimage to build an A20 minimal image.

Host machine Ubuntu 20.04 x86_64 , docker 20.10.14.
$ git clone https://github.com/OLIMEX/olimage.git
$ cd olimage/
$ sudo apt-get install qemu-user-static
$ bash run.sh -v image A20-OLinuXino bullseye minimal A20-OLinuXino-bullseye-minimal-$(date +%Y%m%d-%H%M%S).img

It does have a warning not long after starting:
I: Running qemu-debootstrap                                                                                                                                                                                                                     
Running qemu-debootstrap                                                                                                                                                                                                                       
run external command: [['qemu-debootstrap', '--arch=armhf', '--components=main,contrib,non-free', 'bullseye', '/olimage/output/a20-olinuxino/filesystem/bullseye-minimal', 'http://httpredir.debian.org/debian']]                               
I: Running command: debootstrap --arch armhf --foreign --components=main,contrib,non-free bullseye /olimage/output/a20-olinuxino/filesystem/bullseye-minimal http://httpredir.debian.org/debian                                                 
W: Cannot check Release signature; keyring file not available /usr/share/keyrings/debian-archive-keyring.gpg


It eventually fails with:
Setting up gpg-wks-server (2.2.27-2+deb11u1) ...
Setting up gpg-wks-client (2.2.27-2+deb11u1) ...
Setting up gnupg (2.2.27-2+deb11u1) ...
Processing triggers for libc-bin (2.31-13+deb11u3) ...
Processing triggers for ca-certificates (20210119) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
I: Adding: 'http://repository.olimex.com'
run external command: [['install', '-m', '644', '/olimage/overlay/etc/apt/sources.list.d/default.list', '/olimage/output/a20-olinuxino/filesystem/bullseye-minimal/etc/apt/sources.list.d/olimex.list']]
Installing template files: /olimage/output/a20-olinuxino/filesystem/bullseye-minimal/etc/apt/sources.list.d/olimex.list
Generating template file : /olimage/output/a20-olinuxino/filesystem/bullseye-minimal/etc/apt/sources.list.d/olimex.list
run external command: [['chroot', '/olimage/output/a20-olinuxino/filesystem/bullseye-minimal', 'apt-key', 'adv', '--keyserver', 'keyserver.ubuntu.com', '--recv-keys', '23087A958C1908B20B16FDB70BCE9CE97FCB605C']]
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
Executing: /tmp/apt-key-gpghome.SKxyHNvFde/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 23087A958C1908B20B16FDB70BCE9CE97FCB605C
gpg: keyserver receive failed: Server indicated a failure

Command failed: chroot /olimage/output/a20-olinuxino/filesystem/bullseye-minimal apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 23087A958C1908B20B16FDB70BCE9CE97FCB605C
b'Executing: /tmp/apt-key-gpghome.SKxyHNvFde/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 23087A958C1908B20B16FDB70BCE9CE97FCB605C\n'
b'Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).\ngpg: keyserver receive failed: Server indicated a failure\n'
Traceback (most recent call last):
  File "/olimage/olimage/__main__.py", line 119, in <module>
    sys.exit(cli())
  File "/usr/lib/python3/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/olimage/olimage/image/__init__.py", line 28, in build_image
    ctx.invoke(olimage.filesystem.build_filesystem, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/olimage/olimage/filesystem/__init__.py", line 80, in build_filesystem
    method()
  File "/olimage/olimage/filesystem/decorators.py", line 137, in wrapper
    ret = func(*args, **kwargs)
  File "/olimage/olimage/filesystem/decorators.py", line 22, in wrapper
    ret = func(*args, **kwargs)
  File "/olimage/olimage/filesystem/decorators.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "/olimage/olimage/filesystem/variants/minimal.py", line 54, in configure
    Setup.apt(env.options['release'])
  File "/olimage/olimage/core/setup/apt.py", line 35, in setup
    Utils.shell.chroot('apt-key adv --keyserver {} --recv-keys {}'.format(repo.keyserver, repo.key))
  File "/olimage/olimage/core/utils/shell.py", line 97, in chroot
    raise _e
  File "/olimage/olimage/core/utils/shell.py", line 90, in chroot
    Shell.run("chroot {} ".format(path) + command, **kwargs)
  File "/olimage/olimage/core/utils/shell.py", line 46, in run
    raise _e
Exception: Command failed: chroot /olimage/output/a20-olinuxino/filesystem/bullseye-minimal apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 23087A958C1908B20B16FDB70BCE9CE97FCB605C
E: Command failed: chroot /olimage/output/a20-olinuxino/filesystem/bullseye-minimal apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 23087A958C1908B20B16FDB70BCE9CE97FCB605C

Full log here: https://pastes.io/phhuytesal

However if I run that command manually on the docker olimage image, it works:
$ docker run -it olimage bash
root@ac6b45ef31d2:/# apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 23087A958C1908B20B16FDB70BCE9CE97FCB605C
Executing: /tmp/apt-key-gpghome.CKaJRu28ld/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 23087A958C1908B20B16FDB70BCE9CE97FCB605C
gpg: key 0BCE9CE97FCB605C: public key "Olimex Dev team <[email protected]>" imported
gpg: Total number processed: 1
gpg:               imported: 1

LubOlimex

Technical support and documentation manager at Olimex

kimfaint

I was able to get it working with the following patch:
diff --git a/configs/repositories.yaml b/configs/repositories.yaml
index 6770f43..67d24f9 100644
--- a/configs/repositories.yaml
+++ b/configs/repositories.yaml
@@ -11,9 +11,8 @@ repositories:
    components:
      - "main"

-    # Specify key and keyserver for import
-    key: "23087A958C1908B20B16FDB70BCE9CE97FCB605C"
-    keyserver: "keyserver.ubuntu.com"
+    # Specify keyfile for import
+    keyfile: "https://repository.olimex.com/public.key"

    # Should deb-src be included?
    sources: true
@@ -30,9 +29,8 @@ repositories:
    components:
      - "main"

-    # Specify key and keyserver for import
-    key: "23087A958C1908B20B16FDB70BCE9CE97FCB605C"
-    keyserver: "keyserver.ubuntu.com"
+    # Specify keyfile for import
+    keyfile: "https://repository.olimex.com/public.key"

    # Should deb-src be included?
    sources: true
diff --git a/olimage/core/setup/apt.py b/olimage/core/setup/apt.py
index c881a89..eabb551 100644
--- a/olimage/core/setup/apt.py
+++ b/olimage/core/setup/apt.py
@@ -1,3 +1,6 @@
+from urllib.parse import urlparse
+from urllib.request import urlretrieve
+
 import olimage.environment as env

 from olimage.core.io import Console
@@ -35,9 +38,14 @@ class SetupApt(SetupAbstract):
                    Utils.shell.chroot('apt-key adv --keyserver {} --recv-keys {}'.format(repo.keyserver, repo.key))

                elif repo.keyfile:
+                    url = urlparse(repo.keyfile)
+                    if url.scheme:
+                        # Download keyfile
+                        local_filename = 'overlay' + url.path
+                        urlretrieve(repo.keyfile, local_filename)
                    # Import keyfile
-                    Utils.install(repo.keyfile)
-                    Utils.shell.chroot('apt-key add {}'.format(repo.keyfile))
+                    Utils.install(url.path)
+                    Utils.shell.chroot('apt-key add {}'.format(url.path))

        # Update sources
        # It's possible for some repository to have missing release files, so