mock
mock copied to clipboard
Run install from within mock shell
Very often, when debugging a problem in mock shell, I find myself in a situation when I need to install an additional package into that mock. Since most of the times, I don't have dnf in there, I cannot use it. Hence I need to run mock ... install ...
form outside the shell. Since mock won't run any action like this when the shell is open, I need to exit the shell, install the package and run the shell again. When I run the shell again, I need to cd to the folder I was in, su to the user I was, set any environment variables I had previously set...
This is tedious.
I would appreciate if I could install a package to the mock, when in shell, via some "magic" command. For example in IPython, magic commands are prefixed with %. My idea is something liek this:
$ mock -r fedora-rawhide-x86_64 init
...
Finish: chroot init
Finish: run
$ mock -r fedora-rawhide-x86_64 shell
INFO: mock.py version 2.9 starting (python version = 3.9.2, NVR = mock-2.9-1.fc33)...
Start(bootstrap): init plugins
INFO: selinux enabled
Finish(bootstrap): init plugins
Start: init plugins
INFO: selinux enabled
Finish: init plugins
INFO: Signal handler active
Start: run
Start(bootstrap): chroot init
INFO: calling preinit hooks
INFO: enabled root cache
INFO: enabled package manager cache
Start(bootstrap): cleaning package manager metadata
Finish(bootstrap): cleaning package manager metadata
INFO: enabled HW Info plugin
Finish(bootstrap): chroot init
Start: chroot init
INFO: calling preinit hooks
INFO: enabled root cache
INFO: enabled package manager cache
Start: cleaning package manager metadata
Finish: cleaning package manager metadata
INFO: enabled HW Info plugin
sFinish: chroot init
Start: shell
<mock-chroot> sh-5.1# su mockbuild
<mock-chroot> bash-5.1$ cd /tmp
<mock-chroot> bash-5.1$ export FOO=bar
<mock-chroot> bash-5.1$ %install python3
INFO: installing package(s): python3
No matches found for the following disable plugin patterns: local, spacewalk
fedora 71 kB/s | 5.0 kB 00:00
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
python3 x86_64 3.9.2-1.fc35 fedora 28 k
Installing dependencies:
gdbm-libs x86_64 1:1.19-2.fc34 fedora 54 k
python-pip-wheel noarch 21.0.1-1.fc35 fedora 1.3 M
python-setuptools-wheel noarch 53.0.0-1.fc34 fedora 470 k
python3-libs x86_64 3.9.2-1.fc35 fedora 7.4 M
Transaction Summary
================================================================================
Install 5 Packages
Total size: 9.2 M
Installed size: 33 M
Downloading Packages:
[SKIPPED] gdbm-libs-1.19-2.fc34.x86_64.rpm: Already downloaded
[SKIPPED] python-pip-wheel-21.0.1-1.fc35.noarch.rpm: Already downloaded
[SKIPPED] python-setuptools-wheel-53.0.0-1.fc34.noarch.rpm: Already downloaded
[SKIPPED] python3-3.9.2-1.fc35.x86_64.rpm: Already downloaded
[SKIPPED] python3-libs-3.9.2-1.fc35.x86_64.rpm: Already downloaded
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : python-setuptools-wheel-53.0.0-1.fc34.noarch 1/5
Installing : python-pip-wheel-21.0.1-1.fc35.noarch 2/5
Installing : gdbm-libs-1:1.19-2.fc34.x86_64 3/5
Installing : python3-3.9.2-1.fc35.x86_64 4/5
Installing : python3-libs-3.9.2-1.fc35.x86_64 5/5
Running scriptlet: python3-libs-3.9.2-1.fc35.x86_64 5/5
Verifying : gdbm-libs-1:1.19-2.fc34.x86_64 1/5
Verifying : python-pip-wheel-21.0.1-1.fc35.noarch 2/5
Verifying : python-setuptools-wheel-53.0.0-1.fc34.noarch 3/5
Verifying : python3-3.9.2-1.fc35.x86_64 4/5
Verifying : python3-libs-3.9.2-1.fc35.x86_64 5/5
Installed:
gdbm-libs-1:1.19-2.fc34.x86_64
python-pip-wheel-21.0.1-1.fc35.noarch
python-setuptools-wheel-53.0.0-1.fc34.noarch
python3-3.9.2-1.fc35.x86_64
python3-libs-3.9.2-1.fc35.x86_64
Complete!
INFO:
Finish: run
<mock-chroot> bash-5.1$ pwd
/tmp
<mock-chroot> bash-5.1$ whoami
mockbuild
<mock-chroot> bash-5.1$ echo $FOO
bar
Is this even remotely possible?
Alternatively, instead of % a key sequence could initiate an internal command promt.
Note that this would be an non-issue if I could remain in the shell and run install from another terminal.
I would love to do that, but I have no idea how to technically do that.
/me thinks of all that mounts and nspawn isolation.
Can we consider this to be a duplicate to #627?
Possibly. If #627 works, I'd still consider this useful, but not that much needed.
Work-around is to use mock --no-bootstrap-chroot --install <pkgname>
from s separate terminal.
This is an extraordinarily dangerous feature to enable. Since many pieces of build software, such as pip, cpan, maven, ant, and gradle will all reach out to the Internet to pull in dependencies in distinct and arbitrary fashion, deliberately limiting outbound requests is a modest step to limiting accidental introduction of unexpected third party dependencies.
One of the reasons yum or dnf don't work this way is the deliberately restricted network environment inside the mock environment. Working around that..... well, if you need that kind of development flexibility, you may just be better off doing some testing in a podman environment, not in a mock based cage.
There is some misunderstanding here. We don't enable any dangerous feature here, there's some bug that makes mock mounting two separate filesystems instead of one (but mounted twice).
You want to run "yum install" from within the mock chroot, right? That generally means enabling network access to third party repositories. That means that pip can accidentally reach out to pypi.org for missing dependencies. And that's ignoring the various RPM setups external to the mock chroot cage itself. It seems like a fraught sort of operation.
You want to run "yum install" from within the mock chroot, right?
No.