Skip to content

Instantly share code, notes, and snippets.

@marcdomain
Last active March 21, 2020 09:20
Show Gist options
  • Save marcdomain/411b02b347c83108bcff76cbc498eee1 to your computer and use it in GitHub Desktop.
Save marcdomain/411b02b347c83108bcff76cbc498eee1 to your computer and use it in GitHub Desktop.
Creating a network of multiple virtual machine with Vagrant
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.define "api-vm" do |api|
api.vm.hostname = "api-vm"
api.vm.box = "ubuntu/bionic64"
api.vm.network "private_network", ip: "10.0.0.10"
api.vm.network "forwarded_port", guest: 80, host: 5030
api.vm.synced_folder ".", "/home/vagrant/project-api", owner: "postgres",
group: "vagrant", mount_options:["dmode=775,fmode=664"]
api.vm.provider "virtualbox" do |vb|
vb.name = "api-vm"
vb.gui = false
vb.memory = "1024"
vb.cpus = 3
end
api.vm.provision "shell", run: "always", inline: <<-SHELL
apt-get update
apt-get install git
sudo apt install curl
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo npm install -y node-gyp -g
apt-get install -y postgresql postgresql-contrib
git clone https://github.com/marcdomain/Fast-Food-Fast.git
cd Fast-Food-Fast
sudo npm install
source .env
npm run createTables
npm start
echo "API VM is up and running"
SHELL
end
config.vm.define "client-vm" do |client|
client.vm.hostname = "client-vm"
client.vm.box = "bento/ubuntu-16.04"
client.vm.network "private_network", ip: "10.0.0.20"
client.vm.network "forwarded_port", guest: 80, host: 5020
client.vm.synced_folder ".", "/home/vagrant/bootcamp-project", owner: "vagrant",
group: "vagrant", mount_options:["dmode=775,fmode=664"]
client.vm.provider "virtualbox" do |vb|
vb.name = "client-vm"
vb.gui = false
vb.memory = "1024"
vb.cpus = 2
end
client.vm.provision "shell", run: "always", inline: <<-SHELL
apt-get update
apt-get install -y make git curl nfs-common build-essential
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo npm install -y node-gyp -g
git clone https://github.com/marcdomain/REACTJS-Fast-Food-Fast.git
cd REACTJS-Fast-Food-Fast
sudo npm install
npm run build
npm start
echo "Client VM is up and running"
SHELL
end
# Install avahi on all machines (for newtwoking purpose)
config.vm.provision "shell", run: "always", inline: <<-SHELL
sudo apt-get install -y avahi-daemon libnss-mdns
SHELL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment