So, you have the situation where you need to pack a newer charm that uses the latest and greatest bells and whistles
Python provides, but the default Python on CentOS 7 (Python 3.6 to be exact) is too old? This quick guide will tell you
how to get a CentOS 7 packer instance up and running using libvirt/kvm
packing charms before you know it.
Originally I was going to use a CentOS 7 virtual machine with LXD, but it was having consistent connectivity issues. Even though the virtual machine had an IP address, lxc was incapable of reaching. Also, the virtual machine struggled to connect to the internet after it was first started, requiring an IP address to be manually assigned with
dhclient -v
First, you need to set up your workstation to be able to launch the CentOS 7 virtual machine. I am assuming that you are on Ubuntu 22.04 LTS, but these commands should be transferable to other popular Linux distributions. Use the following commands to install virt-manager and libvirt/kvm on your workstation:
apt update
apt install virt-manager wget
adduser $(id -un) libvirt
adduser $(id -un) kvm
IMAGE_ROOT=/var/lib/libvirt/images
wget http://mirror.cs.pitt.edu/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-NetInstall-2009.iso -P $IMAGE_ROOT
systemctl reboot #=> Log out and log back in so new groups take effect.
You can use virt-install
to create the CentOS 7 virtual machine, but instead we are going to use the graphical front-end
instead. Here are the following steps you need to follow:
- Start "Virtual Machine Manager".
- Click "Create a new virtual machine".
- Select "Local install media (ISO image or CDROM)".
- Select CentOS 7 NetInstaller ISO as the install media.
- Enter
centos7.0
as the operating system that you are installing. - Allocate memory and CPUs to the virtual machine.
- Enable storage and create disk for the machine.
- Enter name for your new virtual machine.
- Click "Finish".
Now you will be taken to the CentOS 7 installation screen. Select "Install CentOS 7" to continue to the Anaconda installer. Now follow the following steps:
- Activate Ethernet. You can find the activation screen by clicking "Network & Hostname"
- Specifiy installation source in "Installation Source". I used the Pittsburgh mirror http://mirror.cs.pitt.edu/centos/7.9.2009/os/x86_64/, but the install will go faster if you use a mirror closer to your current location.
- Select to only install "Core".
- Set a default user and password. I just used the "root" user and "centos" as the password.
- Wait for CentOS 7 to finish installing.
After CentOS 7 has finished installing, we need to do some patchwork to get it ready for packing charms. Use the following commands to install charmcraft and its dependencies on CentOS 7:
yum install dnf #=> I install dnf because it is faster than yum
dnf install epel-release
dnf install gcc git openssl11-devel bzip2-devel libffi-devel zlib-devel xz-devel sqlite nano wget
wget https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tgz
tar -xzvf Python-3.10.6.tgz
cd Python-3.10.6
sed -i 's/PKG_CONFIG openssl /PKG_CONFIG openssl11 /g' configure
./configure --enable-optimizations
make -j $(nproc) altinstall
cd .. && rm -rf Python-3.10.6 Python-3.10.6.tgz
ln -s $(which python3.10) /usr/local/bin/python3
dnf install snapd
systemctl enable --now snapd.socket
ln -s /var/lib/snapd/snap /snap
systemctl reboot #=> The virtual machine needs to reboot so that snap will work.
...
# After virtual machine is done rebooting
snap install charmcraft --classic
charmcraft version #=> Verify that charmcraft snap was installed successfully.
Now it is time to pack our CentOS 7 charm!
git clone https://github.com/omnivector-solutions/slurmd-operator.git
cd slurmd-operator && nano charmcraft.yaml #=> Change name in `build-on` to centos and channel to 7.
charmcraft -v --destructive pack
After a few minutes, your CentOS 7 charm should be packed!
There are multiple ways to download the built charm back from the CentOS 7 virtual machine. In my case, I used wormhole. Here are the following commands you can use to install wormhole and send the charm back to your host machine:
# On your host machine
snap install wormhole
# On the CentOS 7 virtual machine
snap install wormhole
wormhole send slurmd_ubuntu-20.04-amd64_centos-7-amd64.charm
# Back on your host system
wormhole receive 7-suspicious-spigot
Congratulations, you now have your charm that you successfully packed on CentOS 7. The best part? You can continue to use this virtual machine to pack CentOS 7 charms until you do not need to anymore!