From a3f62cf101ffd8fa49d3b9f6c14679259d80e628 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Wed, 19 Jan 2022 08:49:50 +0100 Subject: [PATCH] Add script to run package check via Vagrant in a VirtualBox --- .gitignore | 6 ++- README.md | 7 ++++ vagrant/README.md | 75 ++++++++++++++++++++++++++++++++++++ vagrant/Vagrantfile | 25 ++++++++++++ vagrant/run_package_check.sh | 22 +++++++++++ vagrant/scripts/provision.sh | 22 +++++++++++ vagrant/scripts/run.sh | 16 ++++++++ 7 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 vagrant/README.md create mode 100644 vagrant/Vagrantfile create mode 100755 vagrant/run_package_check.sh create mode 100755 vagrant/scripts/provision.sh create mode 100755 vagrant/scripts/run.sh diff --git a/.gitignore b/.gitignore index 1e9a510..71b6f00 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.* *.swp *~ Notes @@ -10,4 +11,7 @@ config *.log curl_print -*.lock \ No newline at end of file +*.lock + +vagrant/repos/ +!vagrant/repos/.gitkeep \ No newline at end of file diff --git a/README.md b/README.md index 1260aae..0648eed 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,13 @@ Then test your packages : ./package_check.sh your_app_ynh ``` +## Run package check in a VirtualBox VM via Vagrant + +We add script to run package check in a VirtualBox. More information here: + +* [vagrant/README.md](https://github.com/YunoHost/package_check/tree/master/vagrant) + + ## You can start a container on a different architecture with some hacks Install the package `qemu-user-static` and `binfmt-support`, then list of all available images : diff --git a/vagrant/README.md b/vagrant/README.md new file mode 100644 index 0000000..1cb87e1 --- /dev/null +++ b/vagrant/README.md @@ -0,0 +1,75 @@ +# "package check" via Vagrant + +Run [package check](https://github.com/YunoHost/package_check) in a [VirtualBox](https://www.virtualbox.org/) VM by using [Vagrant](https://www.vagrantup.com/). + +## prepare + +install VirtualBox and Vagrant: + +``` +sudo apt install virtualbox vagrant +``` + +Directory overview: +``` +~$ tree package_check/ -dA +package_check/ +├── lib +└── vagrant <<< main directory to setup/start package check via Vagrant + ├── repos <<< clone your YunoHost apps here + │ └── pyinventory_ynh <<< just a clone example + │ ├── conf + │ ├── scripts + │ └── tests + └── scripts +``` + +Startup, e.g.: +``` +# Clone package check: +~$ git clone https://github.com/YunoHost/package_check.git + +# Clone the YunoHost app that you would like to ckec into "repos": +~$ cd package_check/vagrant/repos +~/package_check/vagrant/repos$ git clone https://github.com/YunoHost-Apps/pyinventory_ynh.git + +# Start the VirtualBox VM anr run the check: +~/package_check/vagrant$ ./run_package_check.sh repos/pyinventory_ynh/ +``` + +## update + +Quick update can look like: +``` +# Update package check: +~$ cd package_check +~/package_check$ git pull origin master + +# quick update the VM: +~$ cd package_check/vagrant +~/package_check/vagrant$ vagrant reload --provision +``` + +To get everything completely fresh: destroy the VM and recreate it, e.g.: + +``` +~$ cd package_check/vagrant +~/package_check/vagrant$ vagrant destroy --force + +# Just recreate the VM by run the check, e.g.: +~/package_check/vagrant$ ./run_package_check.sh repos/pyinventory_ynh/ +``` + +## uninstall/cleanup + +To remove the VM, just destroy it, e.g.: + +``` +~$ cd package_check/vagrant +~/package_check/vagrant$ vagrant destroy --force +``` + +## Links + +* Vagrant docs: https://docs.vagrantup.com +* YunoHost "package check": https://github.com/YunoHost/package_check \ No newline at end of file diff --git a/vagrant/Vagrantfile b/vagrant/Vagrantfile new file mode 100644 index 0000000..c81e9db --- /dev/null +++ b/vagrant/Vagrantfile @@ -0,0 +1,25 @@ +# https://docs.vagrantup.com +# https://github.com/YunoHost/package_check + + +Vagrant.configure("2") do |config| + + # https://app.vagrantup.com/ubuntu/boxes/focal64 + config.vm.box = "ubuntu/focal64" + + config.vm.provider "virtualbox" do |vb| + vb.name = "package_check" + vb.cpus = 4 + vb.memory = "2048" + end + + # https://www.vagrantup.com/docs/synced-folders/basic_usage + config.vm.synced_folder "../", "/home/vagrant/package_check/" + + # https://www.vagrantup.com/docs/provisioning/shell + config.vm.provision "shell", inline: <<-SHELL + pwd + id + ./package_check/vagrant/scripts/provision.sh + SHELL +end diff --git a/vagrant/run_package_check.sh b/vagrant/run_package_check.sh new file mode 100755 index 0000000..1794924 --- /dev/null +++ b/vagrant/run_package_check.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +if [ "$1" == "" ]; then + echo "ERROR: Missing repro name as argument!" + echo "e.g.:" + echo "~$ cd package_check/vagrant/repos" + echo "~/package_check/vagrant/repos$ git clone https://github.com/YunoHost-Apps/pyinventory_ynh.git" + echo "~/package_check/vagrant/repos$ cd .." + echo "~/package_check/vagrant$ ./run_package_check.sh repos/pyinventory_ynh" + exit -1 +fi + +echo "Package check: '${1}'" +if [ ! -d "${1}" ]; then + echo "ERROR: Repro '${1}' not found !" + exit -1 +fi + +set -x + +vagrant up +vagrant ssh -c "/home/vagrant/package_check/vagrant/scripts/run.sh ${1}" \ No newline at end of file diff --git a/vagrant/scripts/provision.sh b/vagrant/scripts/provision.sh new file mode 100755 index 0000000..727d3ff --- /dev/null +++ b/vagrant/scripts/provision.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -x + +apt-get update +apt-get dist-upgrade + +apt-get install -y python3-pip git snapd lynx jq + +snap install core +snap refresh lxd + +ln -sf /snap/bin/lxc /usr/local/bin/lxc +ln -sf /snap/bin/lxd /usr/local/bin/lxd + +gpasswd -a vagrant lxd + +lxd init --auto + +lxc remote add yunohost https://devbaseimgs.yunohost.org --public --accept-certificate + +exit 0 \ No newline at end of file diff --git a/vagrant/scripts/run.sh b/vagrant/scripts/run.sh new file mode 100755 index 0000000..1c1f50a --- /dev/null +++ b/vagrant/scripts/run.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +cd /home/vagrant/package_check/vagrant/ + +echo "Package check: '${1}'" + +if [ ! -d "${1}" ]; then + echo "ERROR: Repro '${1}' not found!" + exit -1 +fi + +set -x + +lxd init --auto + +/home/vagrant/package_check/package_check.sh "${1}"