TL;DR#
docker image の unstable とかをむやみに使うな
内容#
自宅サーバー用に https://apt.llvm.org/llvm.sh というのを使って C++環境をセットアップしていたのだがこれを走らせていた Docker 上でエラーが出た
10.89 File "/usr/bin/add-apt-repository", line 361, in <module>
10.89 addaptrepo = AddAptRepository()
10.89 ^^^^^^^^^^^^^^^^^^
10.89 File "/usr/bin/add-apt-repository", line 37, in __init__
10.89 self.distro = get_distro()
10.89 ^^^^^^^^^^^^
10.89 File "/usr/lib/python3/dist-packages/aptsources/distro.py", line 547, in get_distro
10.89 release = os_release["VERSION_ID"]
10.89 ~~~~~~~~~~^^^^^^^^^^^^^^
10.89 KeyError: 'VERSION_ID'
llvm.sh
のソースコードを見てみると
add-apt-repository -y "${REPO_NAME}"
という形で使われていた。
add-apt-repository
自体のソースコードは以下に見つかった1
https://git.launchpad.net/software-properties/tree/add-apt-repository?id=3bab9302813c894ff851cb576e69ff686c793195
addaptrepo = AddAptRepository()
get_distro
関数は以下で見つかった
https://salsa.debian.org/apt-team/python-apt/-/blob/main/aptsources/distro.py?ref_type=heads
os_release = platform.freedesktop_os_release()
id = os_release["ID"]
codename = os_release["VERSION_CODENAME"]
description = os_release["PRETTY_NAME"]
release = os_release["VERSION_ID"]
is_like = os_release.get("ID_LIKE", [])
この中で platform.freedesktop_os_release()が使われているがこれは python の標準ライブラリの一部である
https://docs.python.org/3/library/platform.html#platform.freedesktop_os_release
/etc/os-release
を読んでいるらしいので中身を見てみると2
#95 7.666 PRETTY_NAME="Debian GNU/Linux trixie/sid"
#95 7.666 NAME="Debian GNU/Linux"
#95 7.666 VERSION_CODENAME=trixie
#95 7.666 ID=debian
#95 7.666 HOME_URL="https://www.debian.org/"
#95 7.666 SUPPORT_URL="https://www.debian.org/support"
#95 7.666 BUG_REPORT_URL="https://bugs.debian.org/"
たしかにVERSION_ID
がない。
man ページに os-release の説明が合ったので読んでいると以下の記述を発見 https://www.man7.org/linux/man-pages/man5/os-release.5.html
VERSION_ID=
A lower-case string (mostly numeric, no spaces or other
characters outside of 0–9, a–z, ".", "_" and "-") identifying
the operating system version, excluding any OS name
information or release code name, and suitable for processing
by scripts or usage in generated filenames. This field is
optional.
Examples: "VERSION_ID=17", "VERSION_ID=11.04".
This field is optional.
…はっもしやと
Dockerfile を見てみるとFROM debian:unstable-slim
との記述が….
latest
と直したところこのエラーは出なくなった。
結論#
unstable
バージョンは unstable なのでちゃんと調べてから使うか
大人しく安定バージョンを使いましょう。