Refactoring VagrantFile and add test section to README
* nodes are set in an array * add ext4 nodes in addition to btrfs nodes * run bats test from nodes
This commit is contained in:
parent
8bfa8e18dd
commit
bde8072941
24
README.md
24
README.md
|
@ -67,6 +67,30 @@ Add this ligne
|
|||
> If you want mutiples backups in a day (1 by hour maximum) you can run `bkctld inc` multiples times
|
||||
> If you want keep incremental backup **for ever**, you just need don't run `bkctld rm`
|
||||
|
||||
## Test
|
||||
|
||||
You can deploy tests environmments with Vagrant :
|
||||
|
||||
~~~
|
||||
vagrant up
|
||||
~~~
|
||||
|
||||
### Deployment
|
||||
|
||||
Launch rsync-auto in a terminal for automatic synchronisation of your local code with Vagrant VM :
|
||||
|
||||
~~~
|
||||
vagrant rsync-auto
|
||||
~~~
|
||||
|
||||
### Bats
|
||||
|
||||
You can run [bats](https://github.com/sstephenson/bats) test with *test* provisionner :
|
||||
|
||||
~~~
|
||||
vagrant provision --provision-with test
|
||||
~~~
|
||||
|
||||
## Usage
|
||||
|
||||
~~~
|
||||
|
|
75
Vagrantfile
vendored
75
Vagrantfile
vendored
|
@ -8,58 +8,61 @@ vagrantfile = File.join("#{Dir.home}", '.VagrantFile')
|
|||
load File.expand_path(vagrantfile) if File.exists?(vagrantfile)
|
||||
|
||||
Vagrant.configure('2') do |config|
|
||||
config.vm.synced_folder "./vagrant_share/", "/vagrant", disabled: true
|
||||
config.vm.synced_folder "./", "/vagrant", type: "rsync", rsync__exclude: [ '.vagrant', '.git' ]
|
||||
|
||||
config.vm.provider :libvirt do |libvirt|
|
||||
libvirt.storage :file, :size => '10G', :device => 'vdb'
|
||||
end
|
||||
|
||||
$install = <<SCRIPT
|
||||
ln -fs /vagrant/bkctld /usr/sbin/bkctld
|
||||
ln -fs /vagrant/tpl /usr/share/bkctld
|
||||
ln -fs /vagrant/bash_completion /usr/share/bash-completion/completions/bkctld
|
||||
ln -fs /vagrant/bkctld.conf /etc/default/bkctld
|
||||
SCRIPT
|
||||
|
||||
$deps = <<SCRIPT
|
||||
DEBIAN_FRONTEND=noninteractive apt-get -yq install openssh-server btrfs-tools rsync lsb-base coreutils sed dash mount openssh-sftp-server libc6 bash-completion
|
||||
SCRIPT
|
||||
|
||||
$part = <<SCRIPT
|
||||
$pre_part = <<SCRIPT
|
||||
lsof|awk '/backup/ { print $2 }'| xargs --no-run-if-empty kill -9
|
||||
grep -q /backup /proc/mounts && umount -R /backup
|
||||
mkfs.btrfs -f /dev/vdb
|
||||
exit 0
|
||||
SCRIPT
|
||||
|
||||
$post_part = <<SCRIPT
|
||||
mkdir -p /backup
|
||||
mount /dev/vdb /backup
|
||||
SCRIPT
|
||||
|
||||
config.vm.define :jessie do |node|
|
||||
node.vm.hostname = "bkctld-jessie"
|
||||
node.vm.box = "debian/jessie64"
|
||||
config.vm.provision "backports", type: "shell" do |s|
|
||||
s.inline = "echo 'deb http://deb.debian.org/debian jessie-backports main' > /etc/apt/sources.list.d/backports.list && apt-get update"
|
||||
nodes = [
|
||||
{ :version => "jessie", :fs => "btrfs" },
|
||||
{ :version => "jessie", :fs => "ext4" },
|
||||
{ :version => "stretch", :fs => "btrfs" },
|
||||
{ :version => "stretch", :fs => "ext4" }
|
||||
]
|
||||
|
||||
nodes.each do |i|
|
||||
config.vm.define "#{i[:version]}-#{i[:fs]}" do |node|
|
||||
node.vm.hostname = "bkctld-#{i[:version]}-#{i[:fs]}"
|
||||
node.vm.box = "debian/#{i[:version]}64"
|
||||
config.vm.provision "deps", type: "shell", :inline => $deps
|
||||
if ("#{i[:version]}" == "jessie") then
|
||||
config.vm.provision "backports", type: "shell" do |s|
|
||||
s.inline = "echo 'deb http://deb.debian.org/debian jessie-backports main' > /etc/apt/sources.list.d/backports.list && apt-get update"
|
||||
end
|
||||
config.vm.provision "bats", type: "shell", :inline => "DEBIAN_FRONTEND=noninteractive apt-get -yq install -t jessie-backports bats"
|
||||
else
|
||||
config.vm.provision "bats", type: "shell", :inline => "DEBIAN_FRONTEND=noninteractive apt-get -yq install bats"
|
||||
end
|
||||
config.vm.provision "install", type: "shell", :inline => $install
|
||||
config.vm.provision "pre_part", type: "shell", :inline => $pre_part
|
||||
config.vm.provision "part", type: "shell", :inline => "mkfs.btrfs -f /dev/vdb" if "#{i[:fs]}" == "btrfs"
|
||||
config.vm.provision "part", type: "shell", :inline => "mkfs.ext4 -q -F /dev/vdb" if "#{i[:fs]}" == "ext4"
|
||||
config.vm.provision "post_part", type: "shell", :inline => $post_part
|
||||
config.vm.provision "test", type: "shell", :inline => "bats /vagrant/test/*.bats"
|
||||
end
|
||||
config.vm.provision "deps", type: "shell", :inline => $deps
|
||||
config.vm.provision "bats", type: "shell", :inline => "DEBIAN_FRONTEND=noninteractive apt-get -yq install -t jessie-backports bats"
|
||||
config.vm.provision "part", type: "shell", :inline => $part
|
||||
config.vm.provision "test", type: "shell", :path => "./test/main.bats"
|
||||
end
|
||||
|
||||
config.vm.define :stretch do |node|
|
||||
node.vm.hostname = "bkctld-stretch"
|
||||
node.vm.box = "debian/stretch64"
|
||||
config.vm.provision "deps", type: "shell", :inline => $deps
|
||||
config.vm.provision "bats", type: "shell", :inline => "DEBIAN_FRONTEND=noninteractive apt-get -yq install bats"
|
||||
config.vm.provision "part", type: "shell", :inline => $part
|
||||
config.vm.provision "test", type: "shell", :path => "./test/main.bats"
|
||||
end
|
||||
|
||||
config.vm.provision "copy", type: "file" do |f|
|
||||
f.source = "./"
|
||||
f.destination = "~/bkctld/"
|
||||
end
|
||||
|
||||
$install = <<SCRIPT
|
||||
ln -fs /home/vagrant/bkctld/bkctld /usr/sbin/bkctld
|
||||
ln -fs /home/vagrant/bkctld/tpl /usr/share/bkctld
|
||||
ln -fs /home/vagrant/bkctld/bash_completion /usr/share/bash-completion/completions/bkctld
|
||||
ln -fs /home/vagrant/bkctld/bkctld.conf /etc/default/bkctld
|
||||
SCRIPT
|
||||
|
||||
config.vm.provision "install", type: "shell" do |s|
|
||||
s.inline = $install
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue