From f744d27d89b890099edd57fa10a6137680c1f3be Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Sun, 21 May 2023 11:50:27 +0200 Subject: [PATCH 1/2] Vagrant: add libvirt config As seems impossible (or at least not easy) to have a single Vagrantfile with suitable configuration for different backends, this commit add two backend-specific Vagrantfile. It's up to the user to choose which to symlink (or copy) to `Vagranfile` before running vagrant. - Rename Vagrantfile to Vagrantfile.vbox - Add Vagrantfile.libvirt - Add libvirt specific provision script - Add 'Vagrantfile' to gitignore --- .gitignore | 3 +- Vagrantfile.libvirt | 46 ++++++++++++++++++++++++++++ Vagrantfile => Vagrantfile.vbox | 4 --- bin/dev/vagrant_libvirt_provision.sh | 16 ++++++++++ 4 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 Vagrantfile.libvirt rename Vagrantfile => Vagrantfile.vbox (95%) create mode 100755 bin/dev/vagrant_libvirt_provision.sh diff --git a/.gitignore b/.gitignore index 3db593f1d4..88b868b0e5 100644 --- a/.gitignore +++ b/.gitignore @@ -45,7 +45,8 @@ Ignore config files from VSCode /proxy/ nbproject -#ignore vagrant dir +#ignore vagrant file and dir +Vagrantfile .vagrant/ #ignore local folder diff --git a/Vagrantfile.libvirt b/Vagrantfile.libvirt new file mode 100644 index 0000000000..092fe7c690 --- /dev/null +++ b/Vagrantfile.libvirt @@ -0,0 +1,46 @@ + +server_memory = "2048" # MB +server_timezone = "UTC" +public_folder = "/vagrant" + +Vagrant.configure(2) do |config| + # Set server to Debian 11 / Bullseye 64bit + config.vm.box = "debian/bullseye64" + + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + config.vm.box_check_update = true + + # Create a hostname, don't forget to put it to the `hosts` file + # This will point to the server's default virtual host + # TO DO: Make this work with virtualhost along-side xip.io URL + config.vm.hostname = "friendica.local" + + config.vm.define "libvirt" do |virt| + virt.vm.synced_folder './', public_folder, id: "vagrant-root", type: '9p', disabled: false, accessmode: "squash" + + + virt.vm.provider :libvirt do |libvirt| + libvirt.uri = "qemu:///session" + libvirt.driver = "kvm" + #libvirt.cpu_model = "qemu64" + #libvirt.cpus = 1 + libvirt.cpu_mode = 'host-passthrough' + libvirt.nested = true + libvirt.disk_bus = "virtio" + libvirt.disk_driver :cache => "writeback" + libvirt.memory = server_memory + libvirt.memorybacking :access, :mode => "shared" + libvirt.nic_model_type = "virtio" + libvirt.numa_nodes = [{ :cpus => "0-0", :memory => server_memory, :memAccess => "shared" }] + libvirt.video_type = "virtio" + end + end + + # Enable provisioning with a shell script. + config.vm.provision "shell", path: "./bin/dev/vagrant_provision.sh", privileged: true + config.vm.provision "shell", path: "./bin/dev/vagrant_libvirt_provision.sh", privileged: true + # run: "always" + # run: "once" +end diff --git a/Vagrantfile b/Vagrantfile.vbox similarity index 95% rename from Vagrantfile rename to Vagrantfile.vbox index 1687351231..85d97aca5a 100644 --- a/Vagrantfile +++ b/Vagrantfile.vbox @@ -41,10 +41,6 @@ Vagrant.configure(2) do |config| end end - config.vm.provider :libvirt do |libvirt| - libvirt.memory = server_memory - end - # Enable provisioning with a shell script. config.vm.provision "shell", path: "./bin/dev/vagrant_provision.sh", privileged: true # run: "always" diff --git a/bin/dev/vagrant_libvirt_provision.sh b/bin/dev/vagrant_libvirt_provision.sh new file mode 100755 index 0000000000..a433960c9a --- /dev/null +++ b/bin/dev/vagrant_libvirt_provision.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# 9p write files as 'vagrant:vagrant' always. +# let's run apache as 'vagrant' user to get around write permissions issues +sed -i 's/www-data/vagrant/g' /etc/apache2/envvars +systemctl restart apache2 + +# I can't find a way to set static ip with libvirt, so configure friendica +# with current ip +MYIP=$(hostname -I | tr -d ' ') +sed -i "s|'url' =>.*|'url' => 'http://$MYIP',|" /var/www/config/local.config.php +echo "########################" +echo +echo " http://$MYIP/" +echo +echo "########################" From 8a48c31be4fbdb923ac71dde5ba7617ae1961a34 Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Sun, 21 May 2023 12:03:26 +0200 Subject: [PATCH 2/2] Add `composer install` to vagrant provisioning script --- bin/dev/vagrant_provision.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/dev/vagrant_provision.sh b/bin/dev/vagrant_provision.sh index 40d08cedb2..e8caa9d2d0 100755 --- a/bin/dev/vagrant_provision.sh +++ b/bin/dev/vagrant_provision.sh @@ -111,6 +111,9 @@ cp /vagrant/.htaccess-dist /vagrant/.htaccess # create the friendica database echo "create database friendica DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" | $MYSQL -u root -proot +# install vendor +bin/composer.phar install + # install friendica bin/console autoinstall -f /vagrant/mods/local.config.vagrant.php