mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2026-03-04 15:54:48 +01:00
Speed up vm creation
This commit is contained in:
1
tests/vagrant/preloaded/.gitignore
vendored
Normal file
1
tests/vagrant/preloaded/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.box
|
||||
19
tests/vagrant/preloaded/Vagrantfile
vendored
Normal file
19
tests/vagrant/preloaded/Vagrantfile
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
|
||||
config.vm.synced_folder "../../..", "/mailinabox", id: "mailinabox", automount: false
|
||||
|
||||
config.vm.define "preloaded-ubuntu-bionic64" do |m1|
|
||||
m1.vm.box = "ubuntu/bionic64"
|
||||
m1.vm.provision :shell, :inline => <<-SH
|
||||
cd /mailinabox
|
||||
tests/vagrant/preloaded/prepvm.sh --no-dry-run
|
||||
rc=$?
|
||||
echo "$rc" > "tests/vagrant/preloaded/prepcode.txt"
|
||||
[ $rc -gt 0 ] && exit 1
|
||||
exit 0
|
||||
SH
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
25
tests/vagrant/preloaded/create_preloaded.sh
Executable file
25
tests/vagrant/preloaded/create_preloaded.sh
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
vagrant destroy -f
|
||||
rm -f prepcode.txt
|
||||
|
||||
vagrant up preloaded-ubuntu-bionic64
|
||||
upcode=$?
|
||||
prepcode=$(cat "./prepcode.txt")
|
||||
rm -f prepcode.txt
|
||||
echo ""
|
||||
echo "VAGRANT UP RETURNED $upcode"
|
||||
echo "PREPVM RETURNED $prepcode"
|
||||
|
||||
if [ "$prepcode" != "0" -o $upcode -ne 0 ]; then
|
||||
echo "FAILED!!!!!!!!"
|
||||
vagrant destroy -f
|
||||
exit 1
|
||||
fi
|
||||
|
||||
vagrant halt
|
||||
vagrant package
|
||||
rm -f preloaded.box
|
||||
mv package.box preloaded-ubuntu-bionic64.box
|
||||
|
||||
vagrant destroy -f
|
||||
105
tests/vagrant/preloaded/prepvm.sh
Executable file
105
tests/vagrant/preloaded/prepvm.sh
Executable file
@@ -0,0 +1,105 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Run this on a VM to pre-install all the packages, then
|
||||
# take a snapshot - it will greatly speed up subsequent
|
||||
# test installs
|
||||
|
||||
#
|
||||
# What won't be installed:
|
||||
#
|
||||
# Nextcloud and Roundcube are downloaded with wget by the setup
|
||||
# scripts, so they are not included
|
||||
#
|
||||
# postfix, postgrey and slapd because they require terminal input
|
||||
#
|
||||
|
||||
|
||||
if [ ! -d "setup" ]; then
|
||||
echo "Run from the miab root directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
dry_run=true
|
||||
|
||||
if [ "$1" == "--no-dry-run" ]; then
|
||||
dry_run=false
|
||||
fi
|
||||
|
||||
if $dry_run; then
|
||||
echo "WARNING: dry run is TRUE, no changes will be made"
|
||||
fi
|
||||
|
||||
|
||||
remove_line_continuation() {
|
||||
local file="$1"
|
||||
awk '
|
||||
BEGIN { C=0 }
|
||||
C==1 && /[^\\]$/ { C=0; print $0; next }
|
||||
C==1 { printf("%s",substr($0,0,length($0)-1)); next }
|
||||
/\\$/ { C=1; printf("%s",substr($0,0,length($0)-1)); next }
|
||||
{ print $0 }' \
|
||||
"$file"
|
||||
}
|
||||
|
||||
install_packages() {
|
||||
while read line; do
|
||||
pkgs=""
|
||||
case "$line" in
|
||||
apt_install* )
|
||||
pkgs="$(cut -c12- <<<"$line")"
|
||||
;;
|
||||
"apt-get install"* )
|
||||
pkgs="$(cut -c16- <<<"$line")"
|
||||
;;
|
||||
"apt install"* )
|
||||
pkgs="$(cut -c12- <<<"$line")"
|
||||
;;
|
||||
esac
|
||||
|
||||
# don't install postfix - causes problems with setup scripts
|
||||
# and requires user input. exclude postgrey because it will
|
||||
# install postfix as a dependency
|
||||
pkgs="$(sed 's/postgrey//g' <<< "$pkgs")"
|
||||
pkgs="$(sed 's/postfix-[^ $]*//g' <<<"$pkgs")"
|
||||
pkgs="$(sed 's/postfix//g' <<<"$pkgs")"
|
||||
|
||||
# don't install slapd - it requires user input
|
||||
pkgs="$(sed 's/slapd//g' <<< "$pkgs")"
|
||||
|
||||
if [ ! -z "$pkgs" ]; then
|
||||
echo "install: $pkgs"
|
||||
if ! $dry_run; then
|
||||
apt-get install -y -qq $pkgs
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
if ! $dry_run; then
|
||||
apt-get update -y
|
||||
apt-get upgrade -y
|
||||
apt-get autoremove -y
|
||||
fi
|
||||
|
||||
for file in $(ls setup/*.sh); do
|
||||
remove_line_continuation "$file" | install_packages
|
||||
done
|
||||
|
||||
if ! $dry_run; then
|
||||
# bonus
|
||||
apt-get install -y -qq openssh-server
|
||||
apt-get install -y -qq emacs-nox
|
||||
apt-get install -y -qq ntpdate
|
||||
|
||||
# these are added by system-setup scripts and needed for test runner
|
||||
apt-get install -y -qq python3-dnspython jq
|
||||
|
||||
# remove apache, which is what setup will do
|
||||
apt-get -y -qq purge apache2 apache2-\*
|
||||
|
||||
echo ""
|
||||
echo ""
|
||||
echo "Done. Take a snapshot...."
|
||||
echo ""
|
||||
fi
|
||||
Reference in New Issue
Block a user