Skip to content

Instantly share code, notes, and snippets.

@mmguero
Created December 8, 2021 18:19
Show Gist options
  • Save mmguero/7b54a54ceb03cf416b7e643067aac225 to your computer and use it in GitHub Desktop.
Save mmguero/7b54a54ceb03cf416b7e643067aac225 to your computer and use it in GitHub Desktop.
Vagrantfile for Debian 11 with podman
unless Vagrant.has_plugin?("vagrant-sshfs")
raise 'vagrant-sshfs plugin is not installed!'
end
unless Vagrant.has_plugin?("vagrant-reload")
raise 'vagrant-reload plugin is not installed!'
end
# hack: https://github.com/hashicorp/vagrant/issues/8878#issuecomment-345112810
class VagrantPlugins::ProviderVirtualBox::Action::Network
def dhcp_server_matches_config?(dhcp_server, config)
true
end
end
Vagrant.configure("2") do |config|
config.vm.box = "bento/debian-11"
config.vm.network "private_network", type: "dhcp"
config.vm.synced_folder '.', '/vagrant', disabled: true
if Vagrant.has_plugin?("vagrant-vbguest")
config.vbguest.auto_update = false
end
config.vm.provider "virtualbox" do |vb|
vb.memory = "8192"
vb.cpus = 4
end
config.vm.provider "libvirt" do |lv|
lv.memory = "8192"
lv.cpus = 4
end
config.vm.provision "shell", inline: <<-STEP1
dpkg-reconfigure debconf -f noninteractive -p critical
export DEBIAN_FRONTEND=noninteractive
sed -i "s/main/main contrib non-free/g" /etc/apt/sources.list
echo "deb http://httpredir.debian.org/debian/ bullseye-backports main contrib non-free" >> /etc/apt/sources.list
echo "deb-src http://httpredir.debian.org/debian/ bullseye-backports main contrib non-free" >> /etc/apt/sources.list
apt-get -qqy update
apt-get -t bullseye-backports -y install \
linux-headers-amd64 dkms build-essential gcc \
jq bc rsync git bat moreutils iptables tmux libcap2-bin \
apt-transport-https ca-certificates \
curl gnupg2 software-properties-common \
uidmap fuse-overlayfs podman
ln -s -r /usr/bin/batcat /usr/bin/bat
sed -i 's/^GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="random.trust_cpu=on elevator=deadline cgroup_enable=memory swapaccount=1 cgroup.memory=nokmem systemd.unified_cgroup_hierarchy=0"/' /etc/default/grub
update-grub
echo "kernel.unprivileged_userns_clone=1" >> /etc/sysctl.conf
echo 'net.ipv4.ip_unprivileged_port_start = 443' >> /etc/sysctl.conf
echo "options overlay permit_mounts_in_userns=1" >> /etc/modprobe.d/podman.conf
touch /etc/containers/nodocker
mkdir -p /etc/systemd/system/[email protected]
echo -e "[Service]\\nDelegate=cpu cpuset io memory pids" >> /etc/systemd/system/[email protected]/delegate.conf
touch /etc/subuid
touch /etc/subgid
if ! grep --quiet vagrant /etc/subuid; then
usermod --add-subuids 200000-265535 vagrant
fi
if ! grep --quiet vagrant /etc/subgid; then
usermod --add-subgids 200000-265535 vagrant
fi
loginctl enable-linger vagrant
usermod -a -G systemd-journal vagrant
touch /root/.hushlogin
echo "set nocompatible" > /root/.vimrc
STEP1
config.vm.provision :reload
config.vm.provision "shell", privileged: false, inline: <<-STEP3
mkdir -p /home/vagrant/.config/systemd/user /home/vagrant/.local/bin /home/vagrant/tmp
git clone --recursive --single-branch --depth 1 https://github.com/mmguero/config /home/vagrant/.config/mmguero.config
touch /home/vagrant/.hushlogin
echo "set nocompatible" > /home/vagrant/.vimrc
rm -f /home/vagrant/.bashrc
ln -s -f -r /home/vagrant/.config/mmguero.config/bash/rc /home/vagrant/.bashrc
ln -s -f -r /home/vagrant/.config/mmguero.config/bash/rc.d /home/vagrant/.bashrc.d
ln -s -f -r /home/vagrant/.config/mmguero.config/bash/aliases /home/vagrant/.bash_aliases
ln -s -f -r /home/vagrant/.config/mmguero.config/bash/functions /home/vagrant/.bash_functions
ln -s -f -r /home/vagrant/.config/mmguero.config/bash/context-color/context-color /home/vagrant/.local/bin/context-color
ln -s -f -r /home/vagrant/.config/mmguero.config/bash/development_setup.sh /home/vagrant/.local/bin/development_setup.sh
ln -s -f -r /home/vagrant/.config/mmguero.config/linux/tmux/tmux.conf /home/vagrant/.tmux.conf
ln -s -f -r /home/vagrant/.config/mmguero.config/git/gitconfig /home/vagrant/.gitconfig
curl -fsSL "https://raw.githubusercontent.com/containers/podman-compose/devel/podman_compose.py" -o /home/vagrant/.local/bin/podman-compose
ln -s -f -r /home/vagrant/.local/bin/podman-compose /home/vagrant/.local/bin/docker-compose
chmod 755 /home/vagrant/.local/bin/podman-compose
ln -s -f $(which podman) /home/vagrant/.local/bin/docker
STEP3
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment