Skip to content

Instantly share code, notes, and snippets.

@daino3
Last active July 26, 2018 17:22
Show Gist options
  • Save daino3/ecbf386cf40d65c6daf4093edc763446 to your computer and use it in GitHub Desktop.
Save daino3/ecbf386cf40d65c6daf4093edc763446 to your computer and use it in GitHub Desktop.
s3 vagrant images
#!/bin/sh
BOXNAME=`date +'box_%m%d%Y_%H%M%S'`
vagrant destroy --force || exit $?
PACKAGING_BASE_BOX=1 vagrant up || exit $?
PACKAGING_BASE_BOX=1 vagrant halt # Don't exit if this fails; SSH seems screwy on Xenial
PACKAGING_BASE_BOX=1 vagrant package --out "$BOXNAME.box" || exit $?
vagrant box add $BOXNAME "./$BOXNAME.box" || exit $?
aws s3 cp "$BOXNAME.box" "s3://vagrant-boxes/" || exit $?
rm "./$BOXNAME.box"
echo "Set Vagrantfile box target to $BOXNAME and commit changes to VCS"
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# name of virtualbox
config.vm.provider :virtualbox do |vb|
vb.name = "my_vm"
end
# vagrant@salons
config.vm.hostname = "my_vm"
if ENV['PACKAGING_BASE_BOX']
config.vm.box = "bento/ubuntu-16.04"
set_config(config, provision: true)
else
config.vm.box = "s3box"
config.vm.box_url = "https://vagrant-boxes.s3.amazonaws.com/box_07232018_104006.box"
unless Vagrant.has_plugin? 'vagrant-s3auth'
system('vagrant plugin install vagrant-s3auth') || exit!
exit system('vagrant', *ARGV)
end
set_config(config, provision: ARGV[0] == 'provision')
end
config.vm.network "forwarded_port", guest: 8010, host: 8010 # django
config.vm.network "forwarded_port", guest: 3000, host: 3000 # webpack dev server
config.vm.network "forwarded_port", guest: 5432, host: 5400 # psql
config.vm.network "forwarded_port", guest: 15672, host: 15672 # rabbitmq mgmt
end
def set_config(config, provision: false)
config.vm.define :local do |dev|
config.vm.provision "ansible" do |ansible|
ansible.playbook = "provision/local.yml"
ansible.host_key_checking = false
ansible.verbose = 'v'
ansible.groups = {
"local" => ["local"],
"dbservers" => ["local"],
"webservers" => ["local"],
"beatservers" => ["local"]
}
# forward ssh keys for things like pulling from github
ansible.extra_vars = {
ansible_ssh_user: 'vagrant',
ansible_connection: 'ssh',
ansible_ssh_args: '-o ForwardAgent=yes'
}
end if provision
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment