Closed nishakm closed 6 years ago
Our working branch is https://github.com/vmware/tern/tree/layer-debug
It's up to a point where I can do this using the sample Dockerfile: https://github.com/vmware/tern/tree/layer-debug/samples/photon_3_layers:
First build the Docker image:
$ cd samples/photon_3_layers
$ docker build -t photon:3layers .
In the python interpreter:
>>> full_cmd = 'tdnf check-update > /dev/null && tdnf list installed | cut -f1 -d"."' (the command to run in chroot)
>>> from classes.docker_image import DockerImage
>>> d = DockerImage('photon:3layers')
>>> d.load_image() (loads all the metadata)
[sudo] password for nisha: (I run Docker without elevated permissions)
>>> from utils import rootfs
>>> rootfs.mount_base_layer(d.layers[0].tar_file)
>>> result1 = rootfs.run_chroot_command(full_cmd, 'usr/bin/bash')
>>> result1 (all the packages that the base layer contains)
b'bash\nbzip2-libs\nca-certificates\nca-certificates-pki\ncurl\ncurl-libs\ne2fsprogs-libs\nelfutils-libelf\nexpat-libs\nfilesystem\nglibc\nhawkey\nkrb5\nlibcap\nlibdb\nlibgcc\nlibsolv\nlibssh2\nncurses-libs\nnspr\nnss-libs\nopenssl\nphoton-release\nphoton-repos\npopt\nreadline\nrpm-libs\nsqlite-libs\ntdnf\ntoybox\nxz-libs\nzlib\n'
>>> rootfs.mount_diff_layer(d.layers[1].tar_file)
>>> result2 = rootfs.run_chroot_command(full_cmd, 'usr/bin/bash')
>>> result2 (all the packages that the base + diff layer contains)
b'bash\nbzip2-libs\nca-certificates\nca-certificates-pki\ncurl\ncurl-libs\ne2fsprogs-libs\nelfutils-libelf\nexpat\nexpat-libs\nfilesystem\ngdbm\ngit\nglibc\nhawkey\nkrb5\nlibcap\nlibdb\nlibffi\nlibgcc\nlibsolv\nlibssh2\nncurses\nncurses-libs\nnspr\nnss-libs\nopenssl\nperl\nperl-CGI\nperl-DBI\nperl-YAML\nphoton-release\nphoton-repos\npopt\npython3\npython3-libs\nreadline\nrpm-libs\nsqlite-libs\ntdnf\ntoybox\nxz\nxz-libs\nzlib\n'
>>> rootfs.mount_diff_layer(d.layers[2].tar_file)
>>> result3 = rootfs.run_chroot_command(full_cmd, 'usr/bin/bash')
>>> result3 (all the packages that layer1 + layer2 + layer3 contain)
b'bash\nbzip2-libs\nca-certificates\nca-certificates-pki\ncurl\ncurl-libs\ne2fsprogs-libs\nelfutils-libelf\nexpat\nexpat-libs\nfilesystem\ngdbm\ngit\nglibc\nhawkey\nkrb5\nlibcap\nlibdb\nlibffi\nlibgcc\nlibsolv\nlibssh2\nncurses\nncurses-libs\nnspr\nnss-libs\nopenssl\nperl\nperl-CGI\nperl-DBI\nperl-YAML\nphoton-release\nphoton-repos\npopt\npython3\npython3-libs\nreadline\nrpm-libs\nsqlite-libs\ntdnf\ntoybox\nvim\nxz\nxz-libs\nzlib\n'
>>> rootfs.unwind_mount() <--- this is not working
>>> result_list1 = result1.decode('utf-8').split('\n')
>>> result_list1
['bash', 'bzip2-libs', 'ca-certificates', 'ca-certificates-pki', 'curl', 'curl-libs', 'e2fsprogs-libs', 'elfutils-libelf', 'expat-libs', 'filesystem', 'glibc', 'hawkey', 'krb5', 'libcap', 'libdb', 'libgcc', 'libsolv', 'libssh2', 'ncurses-libs', 'nspr', 'nss-libs', 'openssl', 'photon-release', 'photon-repos', 'popt', 'readline', 'rpm-libs', 'sqlite-libs', 'tdnf', 'toybox', 'xz-libs', 'zlib', '']
>>> result_list2 = result2.decode('utf-8').split('\n')
>>> result_list3 = result3.decode('utf-8').split('\n')
>>> list(set(result_list2) - set(result_list1))
['perl-CGI', 'gdbm', 'perl-DBI', 'expat', 'perl-YAML', 'python3-libs', 'perl', 'python3', 'ncurses', 'xz', 'libffi', 'git'] <--- all the packages that were installed with 'tdnf install git'
>>> list(set(result_list3) - set(result_list2))
['vim'] <--- all the packages that were installed with 'tdnf install vim'
Helpful awk for looking at mounts grep temp/mergedir /proc/mounts | awk '{ print $2 }'
Resolved in #56. Thanks everyone for participating the the PyCon2018 developer sprint! It means a lot :)
Currently, Tern is heavily dependent on Docker to run shell scripts against a given root filesystem. It does:
This isn't very effective as we ultimately want to reference the packages that came with every diff filesystem. It's clunky to use Docker or any other existing tool to disentangle a container image, so let's try to use some rudimentary Linux Kernel system calls to do it instead.
Here is a shell proof of concept that we can use to accomplish this using overlay, unshare and chroot:
To resolve issue:
This issue is reserved for PyCon 2018 sprint participants. Some issues may be spun off from this main one during the sprint. After the sprint ends, anyone can work either with me on this issue or independently on a sub-issue.
The current development branch for this issue is: https://github.com/vmware/tern/tree/layer-debug