Loading...
 

Vagrant

Information

Vagrant is used for managing virtual machines on different providers (e.g. VirtualBox (default) AWS, VMWare, Joyent-plugin) and allows management and configuration that will work independent of the environment.
 

Vagrantfile

The Vagrantfile is key to defining the machines you want to spin up. When using Docker as the provider on Mac and Windows, Vagrant will spin up a local Linux VM running Docker Engine and spin up containers on that. An example Docker Vagrantfile is below

Vagrantfile
VAGRANTFILE_API_VERSION = "2"
MEMORY = 2048


ENV['VAGRANT_NO_PARALLEL'] = 'yes' # this doesn't set the environment variables for the build and must be set in the shell running "vagrant up". You may also want VAGRANT_DEFAULT_PROVIDER=docker if still receiving provider failures. Although Vagrant should work it out https://www.vagrantup.com/docs/providers/basic_usage.html


ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'


Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
      config.vm.synced_folder ".", "/vagrant", disabled: true # used to not sync files
      config.vm.network :forwarded_port, guest: 8001, host: ENV['KONG_ADMIN_PORT'] || 8001
      config.vm.provider "docker" do |docker|
        docker.image = "cassandra"
        docker.name = "kong-database"
        docker.has_ssh = true
        docker.remains_running = true
        docker.ports = "9042:9042"
      end


      config.vm.provider "docker" do |docker|
        docker.image = "kong"
        docker.name = "kong"
        docker.has_ssh = true
        docker.remains_running = true
        docker.link "kong-database:kong-database"
        docker.ports =
            "7946:7946/udp",
            "8000:8000",
            "8001:8001",
            "8443:8443"
            "7946:7946",
            "7946:7946/udp",
            "8000:8000",
            "8001:8001",
            "8443:8443"
        docker.env = {
            "KONG_DATABASE" => "cassandra",
            "KONG_CASSANDRA_CONTACT_POINTS" => "kong-database",
            "KONG_PG_HOST" => "kong-database"
        }
      end
end

 

Configuration Management

Vagrant can be used with CM tools like Ansible (also see Ansible docs), Puppet, etc and provides details of setting them up. You’d use different provisioners to ensure that the machine deployed is configured how you want it to be after being deployed with the resources you want it to have.

It can also be used to deploy a VM with Ansible installed and for automatically installing Docker if it isn’t already (this could be useful for quick local machine set up when applying {{ docker_host }} dependency in Ansible playbook).