The bareon.utils.build
Module¶
-
bareon.utils.build.
add_apt_preference
(name, priority, suite, section, chroot, uri)¶
-
bareon.utils.build.
add_apt_source
(name, uri, suite, section, chroot)¶
-
bareon.utils.build.
attach_file_to_free_loop_device
(filename, max_loop_devices_count=255, loop_device_major_number=7, max_attempts=1)¶ Find free loop device and try to attach filename to it.
If attaching fails then retry again. Max allowed attempts is max_attempts.
Returns loop device to which file is attached. Otherwise, raises errors.NoFreeLoopDevices.
-
bareon.utils.build.
attach_file_to_loop
(filename, loop)¶
-
bareon.utils.build.
clean_apt_settings
(chroot, allow_unsigned_file='allow_unsigned_packages', force_ipv4_file='force_ipv4')¶ Cleans apt settings such as package sources and repo pinning.
-
bareon.utils.build.
clean_dirs
(chroot, dirs, delete=False)¶ Removes dirs and recreates them
Parameters: - chroot – Root directory where to look for subdirectories
- dirs – List of directories to clean/remove (Relative to chroot)
- delete – (Boolean) If True, directories will be removed
(Default: False)
-
bareon.utils.build.
containerize
(filename, container, chunk_size=1048576)¶
-
bareon.utils.build.
copy_kernel_initramfs
(chroot, dstdir, clean=False)¶ Copy latest or newest vmlinuz and initrd from chroot
Parameters: - chroot –
- dstdir – copy to folder
- clean – remove all vmlinuzinitrd after done
Returns:
-
bareon.utils.build.
create_sparse_tmp_file
(dir, suffix, size=8192)¶ Creates sparse file.
Creates file which consumes disk space more efficiently when the file itself is mostly empty.
-
bareon.utils.build.
deattach_loop
(loop, check_exit_code=[0])¶
-
bareon.utils.build.
do_post_inst
(chroot, allow_unsigned_file='allow_unsigned_packages', force_ipv4_file='force_ipv4')¶
-
bareon.utils.build.
dump_runtime_uuid
(uuid, config)¶ Save runtime_uuid into yaml file
Simple uuid variable to identify bootstrap. Variable will be hard-coded into config yaml file, in build-time :param uuid: :param config: yaml file :return:
-
bareon.utils.build.
get_free_loop_device
(loop_device_major_number=7, max_loop_devices_count=255)¶ Returns the name of free loop device.
It should return the name of free loop device or raise an exception. Unfortunately, free loop device couldn’t be reversed for the later usage, so we must start to use it as fast as we can. If there’s no free loop it will try to create new one and ask a system for free loop again.
-
bareon.utils.build.
get_installed_packages
(chroot)¶ The packages installed in chroot along with their versions
-
bareon.utils.build.
get_release_file
(uri, suite, section)¶ Download and parse repo’s Release file
It and returns an apt preferences line for specified repo.
Parameters: repo – a repo as dict Returns: a string with apt preferences rules
-
bareon.utils.build.
make_targz
(source_dir, output_name=None)¶ Archive the given directory
Parameters: - source_dir – directory to archive
- output_name – output file name, might be a relative
or an absolute path
-
bareon.utils.build.
mkdtemp_smart
(root_dir, suffix)¶ Create a unique temporary directory in root_dir
Automatically creates root_dir if it does not exist.Otherwise same as tempfile.mkdtemp
-
bareon.utils.build.
parse_release_file
(content)¶ Parse Debian repo’s Release file content.
Parameters: content – a Debian’s Release file content Returns: a dict with repo’s attributes
-
bareon.utils.build.
populate_basic_dev
(chroot)¶ Populates /dev with basic files, links, device nodes.
-
bareon.utils.build.
pre_apt_get
(chroot, allow_unsigned_file='allow_unsigned_packages', force_ipv4_file='force_ipv4', proxies=None, direct_repo_addr=None)¶ It must be called prior run_apt_get.
-
bareon.utils.build.
propagate_host_resolv_conf
(chroot)¶ Copy DNS settings from host system to chroot.
Make a backup of original /etc/resolv.conf and /etc/hosts.
# In case user pass some custom rules in hosts
- esolv.conf.
- opposite to restore_resolv_conf
-
bareon.utils.build.
recompress_initramfs
(chroot, compress='xz', initrd_mask='initrd*')¶ Remove old and rebuild initrd
Parameters: - chroot –
- compress – compression type for initrd
Returns: Initrd_mask: search kernel file by Unix style pathname
-
bareon.utils.build.
remove_files
(chroot, files)¶
-
bareon.utils.build.
restore_resolv_conf
(chroot)¶ Restore hosts/resolv files in chroot
opposite to propagate_host_resolv_conf
-
bareon.utils.build.
rsync_inject
(src, dst)¶ Recursively copy the src to dst using full source paths
Example: suppose the source directory looks like src/etc/myconfig src/usr/bin/myscript
rsync_inject(‘src’, ‘/tmp/chroot’)
copies src/etc/myconfig to /tmp/chroot/etc/myconfig, and src/usr/bin/myscript to /tmp/chroot/usr/bin/myscript, respectively
-
bareon.utils.build.
run_apt_get
(chroot, packages, eatmydata=False, attempts=10)¶ Runs apt-get install <packages>.
Unlike debootstrap, apt-get has a perfect package dependecies resolver under the hood. eatmydata could be used to totally ignore the storm of sync() calls from dpkg/apt-get tools. It’s dangerous, but could decrease package install time in X times.
-
bareon.utils.build.
run_debootstrap
(uri, suite, chroot, arch='amd64', eatmydata=False, attempts=10, proxies=None, direct_repo_addr=None)¶ Builds initial base system.
debootstrap builds initial base system which is capable to run apt-get. debootstrap is well known for its glithcy resolving of package dependecies, so the rest of packages will be installed later by run_apt_get.
-
bareon.utils.build.
run_mksquashfs
(chroot, output_name=None, compression_algorithm='xz')¶ Pack the target system as squashfs using mksquashfs
Parameters: - chroot – chroot system, to be squashfs’d
- output_name – output file name, might be a relative or an absolute path
The kernel squashfs driver has to match with the user space squasfs tools. Use the mksquashfs provided by the target distro to achieve this. (typically the distro maintainers are smart enough to ship the correct version of mksquashfs) Use mksquashfs installed in the target system
1)Mount tmpfs under chroot/mnt 2)run mksquashfs inside a chroot 3)move result files to dstdir
-
bareon.utils.build.
run_script_in_chroot
(chroot, script)¶ Run script inside chroot
1)Copy script file inside chroot 2)Make it executable 3)Run it with bash
-
bareon.utils.build.
set_apt_get_env
()¶
-
bareon.utils.build.
set_apt_proxy
(chroot, proxies, direct_repo_addr=None)¶ Configure proxy for apt-config
direct_repo_addr:: direct apt address: access to it bypass proxies.
-
bareon.utils.build.
shrink_sparse_file
(filename)¶ Shrinks file to its size of actual data. Only ext fs are supported.
-
bareon.utils.build.
stop_chrooted_processes
(chroot, signal=15, attempts=10, attempts_delay=2)¶ Sends signal to all processes, which are running inside chroot.
It tries several times until all processes die. If at some point there are no running processes found, it returns True.
Parameters: - chroot – Process root directory.
- signal – Which signal to send to processes. It must be either
SIGTERM or SIGKILL. (Default: SIGTERM) :param attempts: Number of attempts (Default: 10) :param attempts_delay: Delay between attempts (Default: 2)
-
bareon.utils.build.
strip_filename
(name)¶ Strips filename for apt settings.
The name could only contain alphanumeric, hyphen (-), underscore (_) and period (.) characters.
-
bareon.utils.build.
suppress_services_start
(chroot)¶ Suppresses services start.
Prevents start of any service such as udev/ssh/etc in chrooted environment while image is being built.