From 103f48356b1d8dd13294232afb9c1b6e27d6941c Mon Sep 17 00:00:00 2001 From: Matthew Strasiotto <39424834+matthewstrasiotto@users.noreply.github.com> Date: Thu, 24 Sep 2020 05:47:42 +1000 Subject: [PATCH] Add vagrantfile which is rough equivalent to dockerfile, but primarily for bootstrapping dev servers (#11) * added vagrantfile * Add serve script to vagrantfile * Fix heredoc * Finally fixed env escapes * Change to ubuntu, symlink binaries * Fix apt installation for noninteractive ( I think ) * Remove bash from installation, add git * Bind the same port for web interface for guest & host This means the URL given will be accurate. --- vagrantfile | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 vagrantfile diff --git a/vagrantfile b/vagrantfile new file mode 100644 index 0000000..9f5c117 --- /dev/null +++ b/vagrantfile @@ -0,0 +1,45 @@ +Vagrant.configure("2") do |config| + + # Every Vagrant virtual environment requires a box to build off of. + config.vm.box = "ubuntu/focal64" + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. + # By connecting to localhost:8080 from the host, we can access the guest's + # webserver. + + config.vm.network :forwarded_port, guest: 5000, host: 5000 + config.vm.network :forwarded_port, guest: 22, host: 5522 + config.vm.network :forwarded_port, guest: 6543, host: 6543 + + # Forward x11 via ssh. + # Handy if you need to share a clipboard, convey viewport info, etc. + config.ssh.forward_x11 = true + + $install_script = <<-SCRIPT + build_deps="golang make go-dep" + runtime_deps="dumb-init git" + + apt-get update && \ + apt-get install -y $build_deps $runtime_deps && \ + cd /home/vagrant/go/src/github.com/elisescu/tty-server && \ + GOPATH=/home/vagrant/go dep ensure && \ + GOPATH=/home/vagrant/go make all && \ + ln -s /home/vagrant/go/src/github.com/elisescu/tty-server/tty-server /usr/bin/tty-server + SCRIPT + + $serve_script = <<-'SCRIPT' + cat << EOD | sed -e "s#\\\\{#{#g; s#\\\\}#}#g" > /usr/bin/serve +#!/usr/bin/env bash +URL="$\\{1:-http://localhost:5000\\}" +/usr/bin/tty-server -web_address :5000 --sender_address :6543 -url "$\\{URL\\}" +EOD + chmod a+x /usr/bin/serve + SCRIPT + + config.vm.provision "file", source: ".", destination: "$HOME/go/src/github.com/elisescu/tty-server" + # config.vm.provision "shell", inline: 'mv "/home/vagrant/go" "/go"', name: "move_go" + config.vm.provision "shell", inline: $install_script, name: "install" + config.vm.provision "shell", inline: $serve_script, name: "serve" + +end