Skip to content

Instantly share code, notes, and snippets.

@pixline
Last active December 15, 2015 15:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pixline/9548934 to your computer and use it in GitHub Desktop.
Save pixline/9548934 to your computer and use it in GitHub Desktop.
Vagrant project setup Makefile
# Digital Ocean Vagrant Makefile
# Based on https://gist.github.com/avalanche123/1297080
# These values are overwriteable by command line.
AUTHOR = SWERgroup Developers <plugins@swergroup.com>
PROJECT = vagrant
CONFDIR = config
PROVDIR = provision
define license
Copyright (c) $(shell date +%Y) $(AUTHOR)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
endef
define vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'yaml'
dir = Dir.pwd
vagrant_dir = File.expand_path(File.dirname(__FILE__))
vconfig = YAML::load_file( vagrant_dir + "/vagrant-config.yml" )
Vagrant.configure("2") do |config|
config.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--memory", 512]
end
vagrant_version = Vagrant::VERSION.sub(/^v/, '')
provision_target = ''
config.ssh.forward_agent = true
config.vm.box = "digital_ocean"
config.vm.box_url = "https://github.com/smdahlen/vagrant-digitalocean/raw/master/box/digital_ocean.box"
config.vm.hostname = vconfig['hostname']
# /srv/config/
# config.vm.synced_folder "config/", "/srv/config"
config.ssh.private_key_path = vconfig['digitalocean']['private_key']
config.vm.provider :digital_ocean do |ocean, override|
ocean.client_id = vconfig['digitalocean']['client_id']
ocean.api_key = vconfig['digitalocean']['api_key']
ocean.image = vconfig['digitalocean']['image']
ocean.region = vconfig['digitalocean']['region']
#ocean.ca_path = vconfig['digitalocean']['ca_path']
end
config.vm.provision :shell, :path => File.join( "provision", "system.sh" ), :args => provision_target
end
endef
define vagrantconf
# Personal settings
hostname: "oceandebrant"
digitalocean:
client_id: ""
api_key: ""
image: "Debian 7.0 x64"
region: "Amsterdam 2"
private_key: "Vagrant"
#ca_path: ""
endef
define provision
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
echo "APT-GET setup"
apt-key adv --keyserver keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A 2>&1 > /dev/null
apt-key adv --keyserver keys.gnupg.net --recv-keys F61E2E7CECDEA787 2>&1 > /dev/null
wget -qO- http://repo.varnish-cache.org/debian/GPG-key.txt | apt-key add -
apt_package_install_list=()
apt_packages_wishlist=(
sudo
vim
zsh
)
for pkg in "$${apt_packages_wishlist[@]}"
do
if dpkg -s $$pkg 2>&1 | grep -q 'Status: install ok installed';
then
echo -e " $$pkg"
else
echo -e "- $$pkg"
apt_package_install_list+=($$pkg)
fi
done
if [ $${apt_package_install_list[@]} = 0 ];
then
echo -e "Nothing to do."
else
echo -e "Installing packages.."
apt-get install --force-yes --assume-yes $${apt_package_install_list[@]}
fi
endef
export license vagrantfile vagrantconf provision
init:
mkdir -p $(PROJECT)/$(CONFDIR)
mkdir -p $(PROJECT)/$(PROVDIR)
echo "$$license" >> $(PROJECT)/LICENSE
echo "$$vagrantfile" >> $(PROJECT)/Vagrantfile
echo "$$vagrantconf" >> $(PROJECT)/vagrant-config.yml
echo "$$provision" >> $(PROJECT)/$(PROVDIR)/system.sh
clean:
rm -Rf $(PROJECT)
help:
@echo ""
@echo "Please use \`make <target>' where <target> is one of"
@echo ""
@echo " init generate barebones Vagrant project."
@echo " destroy remove generated project completely."
@echo ""
@echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment