Skip to content

Commit

Permalink
Port provision shell scripts to Ansible playbooks
Browse files Browse the repository at this point in the history
  • Loading branch information
stevelorenz committed Apr 23, 2022
1 parent 900cb1c commit 1fb869f
Show file tree
Hide file tree
Showing 9 changed files with 348 additions and 248 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ jobs:
sudo apt-get remove -q -y docker docker-engine docker.io containerd runc
# The CI VM can not resolve the runc and containerd dependency of docker.io automatically... I don't know the detailed reason yet...
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y runc containerd
PYTHON=python3 ./util/install.sh -a
PYTHON=python3 ./util/install.sh -d
bash ./util/install.sh -a
- name: Run core tests
run: |
Expand Down
78 changes: 39 additions & 39 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ BOX_LIBVIRT = "generic/ubuntu2004"

# Common bootstrap
$bootstrap= <<-SCRIPT
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
DEBIAN_FRONTEND=noninteractive apt-get update
DEBIAN_FRONTEND=noninteractive apt-get upgrade -y
APT_PKGS=(
ansible
bash-completion
dfc
gdb
Expand All @@ -45,44 +46,30 @@ APT_PKGS=(
sudo
tmux
)
apt-get install -y --no-install-recommends "${APT_PKGS[@]}"
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends "${APT_PKGS[@]}"
SCRIPT

$setup_x11_server= <<-SCRIPT
apt-get install -y --no-install-recommends xorg openbox
APT_PKGS=(
openbox
xauth
xorg
xterm
)
DEBIAN_FRONTEND=noninteractive apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y "${APT_PKGS[@]}"
SCRIPT

# Ubuntu 20.04 LTS uses v5.4 LTS, EOL: Dec, 2025
# This script is uncommented and used when there's a requirement to manually install a special Linux kernel
# A special kernel (version) is needed sometimes for special latest kernel features (e.g. eBPF, AF_XDP)

# $install_kernel= <<-SCRIPT
# # Install libssl1.1 from https://packages.ubuntu.com/bionic/amd64/libssl1.1/download
# echo "deb http://cz.archive.ubuntu.com/ubuntu bionic main" | tee -a /etc/apt/sources.list > /dev/null
# apt update
# apt install -y libssl1.1
# cd /tmp || exit
# wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.4.70/amd64/linux-headers-5.4.70-050470_5.4.70-050470.202010070732_all.deb
# wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.4.70/amd64/linux-headers-5.4.70-050470-generic_5.4.70-050470.202010070732_amd64.deb
# wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.4.70/amd64/linux-image-unsigned-5.4.70-050470-generic_5.4.70-050470.202010070732_amd64.deb
# wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.4.70/amd64/linux-modules-5.4.70-050470-generic_5.4.70-050470.202010070732_amd64.deb
# dpkg -i *.deb
# update-initramfs -u -k 5.4.70-050470-generic
# update-grub
# SCRIPT

$setup_comnetsemu= <<-SCRIPT
# Apply Xterm profile, looks nicer.
# Apply a custom Xterm profile that looks better than the default.
cp /home/vagrant/comnetsemu/util/Xresources /home/vagrant/.Xresources
# xrdb can not run directly during vagrant up. Auto-works after reboot.
xrdb -merge /home/vagrant/.Xresources
cd /home/vagrant/comnetsemu/util || exit
PYTHON=python3 ./install.sh -a
# Install development tools
PYTHON=python3 ./install.sh -d
bash ./install.sh -a
# Run the customization shell script (for distribution $BOX) if it exits.
# Run the custom shell script, if it exists.
cd /home/vagrant/comnetsemu/util || exit
if [ -f "./vm_customize.sh" ]; then
echo "*** Run VM customization script."
Expand All @@ -91,14 +78,20 @@ fi
SCRIPT

$post_installation= <<-SCRIPT
# Allow vagrant user to use Docker without sudo
# Allow the vagrant user to use Docker without sudo.
usermod -aG docker vagrant
if [ -d /home/vagrant/.docker ]; then
chown -R vagrant:vagrant /home/vagrant/.docker
fi
DEBIAN_FRONTEND=noninteractive apt-get autoclean -y
DEBIAN_FRONTEND=noninteractive apt-get autoremove -y
SCRIPT

apt-get autoclean -y
apt-get autoremove -y
$setup_libvirt_vm_always= <<-SCRIPT
# Configure the SSH server to allow X11 forwarding with sudo
# This is needed to use the Xterm feature of ComNetsEmu with libvirt/KVM
cp /home/vagrant/comnetsemu/util/sshd_config /etc/ssh/sshd_config
systemctl restart sshd.service
SCRIPT

####################
Expand All @@ -113,7 +106,7 @@ Vagrant.configure("2") do |config|
comnetsemu.vm.synced_folder ".", "/vagrant", disabled: true
comnetsemu.vm.synced_folder ".", "/home/vagrant/comnetsemu"

# For virtualbox provider
# For Virtualbox provider
comnetsemu.vm.provider "virtualbox" do |vb|
vb.name = VM_NAME
vb.cpus = CPUS
Expand All @@ -127,6 +120,7 @@ Vagrant.configure("2") do |config|
comnetsemu.vm.provider "libvirt" do |libvirt, override|
# Overrides are used to modify default options that do not work for libvirt provider.
override.vm.box = BOX_LIBVIRT
override.vm.synced_folder ".", "/home/vagrant/comnetsemu", type: "nfs", nfs_version: 3

libvirt.driver = "kvm"
libvirt.cpus = CPUS
Expand All @@ -136,21 +130,27 @@ Vagrant.configure("2") do |config|
comnetsemu.vm.hostname = "comnetsemu"
comnetsemu.vm.box_check_update = true
comnetsemu.vm.post_up_message = '
VM already started! Run "$ vagrant ssh comnetsemu" to ssh into the runnung VM.
The VM is up! Run "$ vagrant ssh comnetsemu" to ssh into the running VM.
**IMPORTANT!!!**: For all ComNetsEmu users and developers:
IMPORTANT! For all ComNetsEmu users and developers:
**Please** run the upgrade process described [here](https://git.comnets.net/public-repo/comnetsemu#upgrade-comnetsemu-and-dependencies) when there is a new release
published [here](https://git.comnets.net/public-repo/comnetsemu/-/tags).
New features, fixes and other improvements require run the upgrade script **manually**.
But the script will check and perform upgrade automatically and it does not take much time if you have a good network connection.
When a new version is released (https://git.comnets.net/public-repo/comnetsemu/-/tags),
please run the upgrade process described [here](https://git.comnets.net/public-repo/comnetsemu#upgrade-comnetsemu-and-dependencies).
New features, fixes and other improvements require **manually** running the upgrade script.
But the script will automatically check and perform the upgrade, and if you have a good internet connection,
it will not take much time.
'

comnetsemu.vm.provision :shell, inline: $bootstrap, privileged: true
comnetsemu.vm.provision :shell, inline: $setup_x11_server, privileged: true
comnetsemu.vm.provision :shell, inline: $setup_comnetsemu, privileged: false
comnetsemu.vm.provision :shell, inline: $setup_comnetsemu, privileged: false, reboot: true
comnetsemu.vm.provision :shell, inline: $post_installation, privileged: true

comnetsemu.vm.provider "libvirt" do |libvirt, override|
override.vm.provision :shell, inline: $setup_libvirt_vm_always, privileged: true, run: "always"
end
comnetsemu.vm.provision :shell, privileged:false, run: "always", path: "./util/echo_banner.sh"

# VM networking
comnetsemu.vm.network "forwarded_port", guest: 8888, host: 8888, host_ip: "127.0.0.1"
comnetsemu.vm.network "forwarded_port", guest: 8082, host: 8082
Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions util/echo_banner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -Eeuo pipefail

echo ""
cat <<"EOF"
██████╗ ██████╗ ███╗ ███╗███╗ ██╗███████╗████████╗███████╗███████╗███╗ ███╗██╗ ██╗
██╔════╝██╔═══██╗████╗ ████║████╗ ██║██╔════╝╚══██╔══╝██╔════╝██╔════╝████╗ ████║██║ ██║
██║ ██║ ██║██╔████╔██║██╔██╗ ██║█████╗ ██║ ███████╗█████╗ ██╔████╔██║██║ ██║
██║ ██║ ██║██║╚██╔╝██║██║╚██╗██║██╔══╝ ██║ ╚════██║██╔══╝ ██║╚██╔╝██║██║ ██║
╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ╚████║███████╗ ██║ ███████║███████╗██║ ╚═╝ ██║╚██████╔╝
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝
EOF
Loading

0 comments on commit 1fb869f

Please sign in to comment.