From 4beeb70f71f5f9cf0a70e1c89856f0cc52833796 Mon Sep 17 00:00:00 2001 From: Mohammad Mohsen Date: Wed, 18 Oct 2023 15:14:33 +0330 Subject: [PATCH] vagrant test cluster --- test-cluster/.gitignore | 2 ++ test-cluster/Vagrantfile | 62 +++++++++++++++++++++++++++++++++ test-cluster/commmands.md | 3 ++ test-cluster/wait-for-docker.sh | 5 +++ 4 files changed, 72 insertions(+) create mode 100644 test-cluster/.gitignore create mode 100644 test-cluster/Vagrantfile create mode 100644 test-cluster/commmands.md create mode 100755 test-cluster/wait-for-docker.sh diff --git a/test-cluster/.gitignore b/test-cluster/.gitignore new file mode 100644 index 0000000..c22bcb2 --- /dev/null +++ b/test-cluster/.gitignore @@ -0,0 +1,2 @@ +data +.vagrant \ No newline at end of file diff --git a/test-cluster/Vagrantfile b/test-cluster/Vagrantfile new file mode 100644 index 0000000..af5a7c1 --- /dev/null +++ b/test-cluster/Vagrantfile @@ -0,0 +1,62 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure("2") do |config| + config.vm.define "manager1" do |node| + node.vm.box = "anzz1/boot2docker" + node.vm.box_version = "18.01.0" + node.vm.network :private_network, ip: "10.0.0.10" + node.vm.hostname = "manager1" + + node.vm.synced_folder "./data", "/vagrant_data" + node.vm.provision "shell", path: "wait-for-docker.sh" + node.vm.provision "shell", inline: <<-SHELL + docker swarm init --advertise-addr 10.0.0.10 + docker swarm join-token manager -q > /vagrant_data/swarm-manager-token + docker swarm join-token worker -q > /vagrant_data/swarm-worker-token + SHELL + end + + config.vm.define "manager2" do |node| + node.vm.box = "anzz1/boot2docker" + node.vm.box_version = "18.01.0" + node.vm.network :private_network, ip: "10.0.0.11" + node.vm.hostname = "manager2" + + node.vm.synced_folder "./data", "/vagrant_data" + node.vm.provision "shell", path: "wait-for-docker.sh" + node.vm.provision "shell", inline: <<-SHELL + docker swarm join --token $(cat /vagrant_data/swarm-manager-token) 10.0.0.10:2377 + SHELL + end + + config.vm.define "worker1" do |node| + node.vm.box = "anzz1/boot2docker" + node.vm.box_version = "18.01.0" + node.vm.network :private_network, ip: "10.0.0.21" + node.vm.hostname = "worker1" + + node.vm.synced_folder "./data", "/vagrant_data" + node.vm.provision "shell", path: "wait-for-docker.sh" + node.vm.provision "shell", inline: <<-SHELL + docker swarm join --token $(cat /vagrant_data/swarm-worker-token) 10.0.0.10:2377 + SHELL + end + + config.vm.define "worker2" do |node| + node.vm.box = "anzz1/boot2docker" + node.vm.box_version = "18.01.0" + node.vm.network :private_network, ip: "10.0.0.22" + node.vm.hostname = "worker2" + + node.vm.synced_folder "./data", "/vagrant_data" + node.vm.provision "shell", path: "wait-for-docker.sh" + node.vm.provision "shell", inline: <<-SHELL + docker swarm join --token $(cat /vagrant_data/swarm-worker-token) 10.0.0.10:2377 + SHELL + end + + config.vm.provision "shell", inline: <<-SHELL + echo 'docker:docker' | sudo chpasswd + SHELL +end diff --git a/test-cluster/commmands.md b/test-cluster/commmands.md new file mode 100644 index 0000000..92be344 --- /dev/null +++ b/test-cluster/commmands.md @@ -0,0 +1,3 @@ +vagrant up +vagrant ssh manager1 # password: docker +vagrant destroy -f \ No newline at end of file diff --git a/test-cluster/wait-for-docker.sh b/test-cluster/wait-for-docker.sh new file mode 100755 index 0000000..364acdf --- /dev/null +++ b/test-cluster/wait-for-docker.sh @@ -0,0 +1,5 @@ +until docker info > /dev/null +do + echo "waiting for docker info" + sleep 1 +done \ No newline at end of file