debian-forge/runners/org.osbuild.rhel82
Christian Kellner cb265e8b58 runners: use platform-python on RHEL
Runner are invoked to prepare the execution of stages and assemblers
inside the container. The setup tasks are specific to the distribution
and maybe the version of it, therefore specific runners are used for
each distribution+version combination.
The build the first (most nested) build root, `/usr` is taken from the
host to bootstrap the container. On RHEL, the python interpreter to be
used for software that belongs to the platform is platform-python, as
it provides a stable API. Therefore the RHEL runners should use that
instead of relying on the presence of /usr/bin/python3.6, which might
not be installed and is indeed not installed by default.
2020-06-19 08:07:07 +02:00

71 lines
2 KiB
Text
Executable file

#!/usr/libexec/platform-python
import os
import subprocess
import sys
from osbuild.util import jsoncomm
def ldconfig():
# ld.so.conf must exist, or `ldconfig` throws a warning
subprocess.run(["touch", "/etc/ld.so.conf"], check=True)
subprocess.run(["ldconfig"], check=True)
def sysusers():
try:
subprocess.run(["systemd-sysusers"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=True)
except subprocess.CalledProcessError as error:
sys.stderr.write(error.stdout)
sys.exit(1)
def tmpfiles():
# Allow systemd-tmpfiles to return non-0. Some packages want to create
# directories owned by users that are not set up with systemd-sysusers.
subprocess.run(["systemd-tmpfiles", "--create"], check=False)
def nsswitch():
# the default behavior is fine, but using nss-resolve does not
# necessarily work in a non-booted container, so make sure that
# is not configured.
try:
os.remove("/etc/nsswitch.conf")
except FileNotFoundError:
pass
def setup_stdio():
with jsoncomm.Socket.new_client("/run/osbuild/api/osbuild") as client:
req = {'method': 'setup-stdio'}
client.send(req)
msg, fds, _ = client.recv()
for io in ['stdin', 'stdout', 'stderr']:
target = getattr(sys, io)
source = fds[msg[io]]
os.dup2(source, target.fileno())
fds.close()
def python_alternatives():
"""/usr/bin/python3 is a symlink to /etc/alternatives/python3, which points
to /usr/bin/python3.6 by default. Recreate the link in /etc, so that
shebang lines in stages and assemblers work.
"""
os.makedirs("/etc/alternatives", exist_ok=True)
try:
os.symlink("/usr/bin/python3.6", "/etc/alternatives/python3")
except FileExistsError:
pass
if __name__ == "__main__":
setup_stdio()
ldconfig()
sysusers()
tmpfiles()
nsswitch()
python_alternatives()
r = subprocess.run(sys.argv[1:], check=False)
sys.exit(r.returncode)