Created
March 14, 2019 09:07
-
-
Save jahentao/7725a0d7eef202252ca8dcb468d7f5b7 to your computer and use it in GitHub Desktop.
Vagrantfile demo #demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- mode: ruby -*- | |
| # vi: set ft=ruby : | |
| $script = <<SCRIPT | |
| echo "Installing Docker..." | |
| sudo apt-get update | |
| sudo apt-get remove docker docker-engine docker.io | |
| sudo apt-get install apt-transport-https ca-certificates curl software-properties-common -y | |
| sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
| sudo apt-key fingerprint 0EBFCD88 | |
| sudo add-apt-repository \ | |
| "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ | |
| $(lsb_release -cs) \ | |
| stable" | |
| sudo apt-get update | |
| sudo apt-get install -y docker-ce | |
| # Restart docker to make sure we get the latest version of the daemon if there is an upgrade | |
| sudo service docker restart | |
| # Make sure we can actually use docker as the vagrant user | |
| sudo usermod -aG docker vagrant | |
| sudo docker --version | |
| # Packages required for nomad & consul | |
| sudo apt-get install unzip curl vim -y | |
| echo "Installing Nomad..." | |
| NOMAD_VERSION=0.8.6 | |
| cd /tmp/ | |
| curl -sSL https://releases.hashicorp.com/nomad/${NOMAD_VERSION}/nomad_${NOMAD_VERSION}_linux_amd64.zip -o nomad.zip | |
| unzip nomad.zip | |
| sudo install nomad /usr/bin/nomad | |
| sudo mkdir -p /etc/nomad.d | |
| sudo chmod a+w /etc/nomad.d | |
| echo "Installing Consul..." | |
| CONSUL_VERSION=1.4.0 | |
| curl -sSL https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip > consul.zip | |
| unzip /tmp/consul.zip | |
| sudo install consul /usr/bin/consul | |
| ( | |
| cat <<-EOF | |
| [Unit] | |
| Description=consul agent | |
| Requires=network-online.target | |
| After=network-online.target | |
| [Service] | |
| Restart=on-failure | |
| ExecStart=/usr/local/bin/consul agent -dev | |
| ExecReload=/bin/kill -HUP $MAINPID | |
| [Install] | |
| WantedBy=multi-user.target | |
| EOF | |
| ) | sudo tee /etc/systemd/system/consul.service | |
| sudo systemctl enable consul.service | |
| sudo systemctl start consul | |
| for bin in cfssl cfssl-certinfo cfssljson | |
| do | |
| echo "Installing $bin..." | |
| # curl -sSL https://pkg.cfssl.org/R1.2/${bin}_linux-amd64 > /tmp/${bin} | |
| sudo install /vagrant/cfssl/${bin}_linux-amd64 /usr/local/bin/${bin} | |
| done | |
| nomad -autocomplete-install | |
| SCRIPT | |
| Vagrant.configure(2) do |config| | |
| config.vm.box = "bento/ubuntu-16.04" # 16.04 LTS | |
| config.vm.hostname = "nomad" | |
| if Vagrant.has_plugin?("vagrant-proxyconf") | |
| # config.proxy.http = "http://192.168.0.2:3128/" | |
| # config.proxy.https = "http://192.168.0.2:3128/" | |
| # config.proxy.no_proxy = "localhost,127.0.0.1,.example.com" | |
| # config.apt_proxy.http = "socks5://jahen:[email protected]:13090/" | |
| # config.apt_proxy.https = "http://jahen:[email protected]:13090/" | |
| end | |
| config.vm.provision "shell", inline: $script, privileged: false | |
| # config.vm.network :public_network, ip: "192.168.0.119" | |
| # config.vm.network :private_network, ip: "192.168.123.10" | |
| # Expose the nomad api and ui to the host | |
| config.vm.network "forwarded_port", guest: 4646, host: 4646, auto_correct: true | |
| # Increase memory for Parallels Desktop | |
| config.vm.provider "parallels" do |p, o| | |
| p.memory = "1024" | |
| end | |
| # Increase memory for Virtualbox | |
| config.vm.provider "virtualbox" do |vb| | |
| vb.memory = "1024" | |
| end | |
| # Increase memory for VMware | |
| ["vmware_fusion", "vmware_workstation"].each do |p| | |
| config.vm.provider p do |v| | |
| v.vmx["memsize"] = "1024" | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment