6fe2ba99 |
# -*- mode: ruby -*-
# vi: set ft=ruby :
|
cfbb85e2 |
# This Vagrantfile provides a simple default configuration using VirtualBox.
# For any other configuration, create a configuration in .vagrant-openshift.json
# using the vagrant-openshift plugin (https://github.com/openshift/vagrant-openshift)
# as an alternative to editing this file.
# Specific providers may use further configuration from provider-specific files -
# consult the provider definitions below for specifics.
|
6fe2ba99 |
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
|
16aecd47 |
# Require a recent version of vagrant otherwise some have reported errors setting host names on boxes
Vagrant.require_version ">= 1.6.2"
|
5c6fcb42 |
def pre_vagrant_171
@pre_vagrant_171 ||= begin
req = Gem::Requirement.new("< 1.7.1")
if req.satisfied_by?(Gem::Version.new(Vagrant::VERSION))
true
else
false
end
end
end
|
cfbb85e2 |
def full_provision(vm, username = [])
if pre_vagrant_171
vm.provision "shell", path: "hack/vm-provision-full.sh", args: username, id: "setup"
else
vm.provision "setup", type: "shell", path: "hack/vm-provision-full.sh", args: username
end
end |
69950ed8 |
# @param tgt [Hash] target hash that we will be **altering**
# @param src [Hash] read from this source hash
# @return the modified target hash
# @note this one does not merge Array elements
def hash_deep_merge!(tgt_hash, src_hash)
tgt_hash.merge!(src_hash) { |key, oldval, newval|
if oldval.kind_of?(Hash) && newval.kind_of?(Hash)
hash_deep_merge!(oldval, newval)
else
newval
end
}
end
|
cfbb85e2 |
class VFLoadError < Vagrant::Errors::VagrantError
def error_message; @parserr; end
def initialize(message, *args)
@parserr = message
super(*args)
end
end
OPENSTACK_CRED_FILE = "~/.openstackcred"
OPENSTACK_BOX_URL = "https://github.com/cloudbau/vagrant-openstack-plugin/raw/master/dummy.box"
AWS_CRED_FILE = "~/.awscred"
AWS_BOX_URL = "https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box" |
54df3379 |
VM_NAME_PREFIX = ENV['OPENSHIFT_VM_NAME_PREFIX'] || "" |
cfbb85e2 |
|
6fe2ba99 |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| |
fa936680 |
|
69950ed8 |
# these are the default settings, overrides are in .vagrant-openshift.json
vagrant_openshift_config = {
"instance_name" => "origin-dev",
"os" => "fedora",
"dev_cluster" => false,
"insert_key" => true,
"num_minions" => ENV['OPENSHIFT_NUM_MINIONS'] || 2,
"rebuild_yum_cache" => false,
"cpus" => ENV['OPENSHIFT_NUM_CPUS'] || 2,
"memory" => ENV['OPENSHIFT_MEMORY'] || 1024,
"virtualbox" => {
"box_name" => "fedora_inst",
"box_url" => "https://mirror.openshift.com/pub/vagrant/boxes/openshift3/fedora_virtualbox_inst.box"
},
"vmware" => {
"box_name" => "fedora_inst",
"box_url" => "http://opscode-vm-bento.s3.amazonaws.com/vagrant/vmware/opscode_fedora-20_chef-provisionerless.box"
},
"libvirt" => {
"box_name" => "fedora_inst",
"box_url" => "https://mirror.openshift.com/pub/vagrant/boxes/openshift3/fedora_libvirt_inst.box"
},
"aws" => {
"_see_also_" => AWS_CRED_FILE,
"box_name" => "aws-dummy-box",
"box_url" => AWS_BOX_URL,
"ami" => "<AMI>",
"ami_region" => "<AMI_REGION>",
"ssh_user" => "<SSH_USER>",
},
"openstack" => {
'_see_also_' => OPENSTACK_CRED_FILE,
'box_name' => "openstack-dummy-box",
'box_url' => OPENSTACK_BOX_URL,
'flavor' => "m1.tiny",
'image' => "Fedora",
'ssh_user' => "root",
},
}
|
cfbb85e2 |
# attempt to read config in this repo's .vagrant-openshift.json if present |
7bedcca1 |
if File.exist?('.vagrant-openshift.json')
json = File.read('.vagrant-openshift.json') |
cfbb85e2 |
begin |
69950ed8 |
hash_deep_merge!(vagrant_openshift_config, JSON.parse(json)) |
cfbb85e2 |
rescue JSON::ParserError => e
raise VFLoadError.new "Error parsing .vagrant-openshift.json:\n#{e}"
end |
7bedcca1 |
end
|
5dd883ac |
dev_cluster = vagrant_openshift_config['dev_cluster'] || ENV['OPENSHIFT_DEV_CLUSTER']
if dev_cluster |
16aecd47 |
# Start an OpenShift cluster |
cfbb85e2 |
# Currently this only works with the (default) VirtualBox provider.
|
62e93890 |
# The number of minions to provision. |
7bedcca1 |
num_minion = (vagrant_openshift_config['num_minions'] || ENV['OPENSHIFT_NUM_MINIONS'] || 2).to_i |
16aecd47 |
# IP configuration |
fec26965 |
master_ip = "10.245.2.2" |
16aecd47 |
minion_ip_base = "10.245.2." |
fec26965 |
minion_ips = num_minion.times.collect { |n| minion_ip_base + "#{n+3}" } |
16aecd47 |
minion_ips_str = minion_ips.join(",")
# Determine the OS platform to use |
7bedcca1 |
kube_os = vagrant_openshift_config['os'] || "fedora" |
16aecd47 |
# OS platform to box information
kube_box = {
"fedora" => { |
69ecca8e |
"name" => "fedora_deps",
"box_url" => "https://mirror.openshift.com/pub/vagrant/boxes/openshift3/fedora_virtualbox_deps.box" |
16aecd47 |
}
} |
fa936680 |
|
16aecd47 |
# OpenShift master |
54df3379 |
config.vm.define "#{VM_NAME_PREFIX}master" do |config| |
16aecd47 |
config.vm.box = kube_box[kube_os]["name"]
config.vm.box_url = kube_box[kube_os]["box_url"] |
168f6beb |
config.vm.provision "shell", inline: "/vagrant/vagrant/provision-master.sh #{master_ip} #{num_minion} #{minion_ips_str} #{ENV['OPENSHIFT_SDN']}" |
16aecd47 |
config.vm.network "private_network", ip: "#{master_ip}"
config.vm.hostname = "openshift-master"
end
# OpenShift minion
num_minion.times do |n| |
54df3379 |
config.vm.define "#{VM_NAME_PREFIX}minion-#{n+1}" do |minion| |
16aecd47 |
minion_index = n+1
minion_ip = minion_ips[n]
minion.vm.box = kube_box[kube_os]["name"]
minion.vm.box_url = kube_box[kube_os]["box_url"] |
168f6beb |
minion.vm.provision "shell", inline: "/vagrant/vagrant/provision-minion.sh #{master_ip} #{num_minion} #{minion_ips_str} #{minion_ip} #{minion_index} #{ENV['OPENSHIFT_SDN']}" |
16aecd47 |
minion.vm.network "private_network", ip: "#{minion_ip}"
minion.vm.hostname = "openshift-minion-#{minion_index}"
end
end |
cfbb85e2 |
else # Single VM dev environment |
9482a0b5 |
sync_from = vagrant_openshift_config['sync_from'] || ENV["VAGRANT_SYNC_FROM"] || '.'
sync_to = vagrant_openshift_config['sync_to'] || ENV["VAGRANT_SYNC_TO"] || "/data/src/github.com/openshift/origin"
|
cfbb85e2 |
##########################
# define settings for the single VM being created. |
54df3379 |
config.vm.define "#{VM_NAME_PREFIX}openshiftdev", primary: true do |config| |
cfbb85e2 |
config.vm.hostname = "openshiftdev.local"
if vagrant_openshift_config['rebuild_yum_cache']
config.vm.provision "shell", inline: "yum clean all && yum makecache"
end
if pre_vagrant_171
config.vm.provision "shell", path: "hack/vm-provision.sh", id: "setup"
else
config.vm.provision "setup", type: "shell", path: "hack/vm-provision.sh"
end |
47ff3d70 |
|
cfbb85e2 |
config.vm.synced_folder ".", "/vagrant", disabled: true |
47ff3d70 |
|
d8db9f0b |
unless vagrant_openshift_config['no_synced_folders'] |
47ff3d70 |
config.vm.synced_folder sync_from, sync_to, rsync__args: %w(--verbose --archive --delete)
end
|
cfbb85e2 |
config.vm.network "forwarded_port", guest: 80, host: 1080 |
47ff3d70 |
config.vm.network "forwarded_port", guest: 443, host: 1443 |
cfbb85e2 |
config.vm.network "forwarded_port", guest: 8080, host: 8080
config.vm.network "forwarded_port", guest: 8443, host: 8443
end
end # vm definition(s)
# #########################################
# provider-specific settings defined below:
# ################################ |
16aecd47 |
# Set VirtualBox provider settings
config.vm.provider "virtualbox" do |v, override| |
5dd883ac |
override.vm.box = vagrant_openshift_config['virtualbox']['box_name'] unless dev_cluster
override.vm.box_url = vagrant_openshift_config['virtualbox']['box_url'] unless dev_cluster |
b6fa6eb3 |
override.ssh.insert_key = vagrant_openshift_config['insert_key'] |
88c99530 |
|
f6543be2 |
v.memory = vagrant_openshift_config['memory'].to_i
v.cpus = vagrant_openshift_config['cpus'].to_i
v.customize ["modifyvm", :id, "--cpus", vagrant_openshift_config['cpus'].to_s] |
9911d615 |
# to make the ha-proxy reachable from the host, you need to add a port forwarding rule from 1080 to 80, which
# requires root privilege. Use iptables on linux based or ipfw on BSD based OS: |
fec26965 |
# sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 1080 |
9911d615 |
# sudo ipfw add 100 fwd 127.0.0.1,1080 tcp from any to any 80 in |
af0d0ee4 |
end if vagrant_openshift_config['virtualbox'] |
6fe2ba99 |
|
cfbb85e2 |
# ################################
# Set libvirt provider settings |
88c99530 |
config.vm.provider "libvirt" do |libvirt, override|
override.vm.box = vagrant_openshift_config['libvirt']['box_name']
override.vm.box_url = vagrant_openshift_config['libvirt']['box_url'] |
b6fa6eb3 |
override.ssh.insert_key = vagrant_openshift_config['insert_key'] |
88c99530 |
libvirt.driver = 'kvm' |
f6543be2 |
libvirt.memory = vagrant_openshift_config['memory'].to_i
libvirt.cpus = vagrant_openshift_config['cpus'].to_i |
cfbb85e2 |
full_provision(override.vm) |
af0d0ee4 |
end if vagrant_openshift_config['libvirt'] |
88c99530 |
|
cfbb85e2 |
# ################################### |
16aecd47 |
# Set VMware Fusion provider settings
config.vm.provider "vmware_fusion" do |v, override| |
88c99530 |
override.vm.box = vagrant_openshift_config['vmware']['box_name'] |
7bedcca1 |
override.vm.box_url = vagrant_openshift_config['vmware']['box_url'] |
b6fa6eb3 |
override.ssh.insert_key = vagrant_openshift_config['insert_key'] |
88c99530 |
v.vmx["memsize"] = vagrant_openshift_config['memory'].to_s
v.vmx["numvcpus"] = vagrant_openshift_config['cpus'].to_s
v.gui = false |
cfbb85e2 |
full_provision(override.vm) |
af0d0ee4 |
end if vagrant_openshift_config['vmware'] |
6fe2ba99 |
|
cfbb85e2 |
# ###############################
# Set OpenStack provider settings
config.vm.provider "openstack" do |os, override|
# load creds file, which you should really have
creds_file_path = [nil, ''].include?(ENV['OPENSTACK_CREDS']) ? OPENSTACK_CRED_FILE : ENV['OPENSTACK_CREDS']
# read in all the lines that look like FOO=BAR as a hash
creds = File.exist?(creds_file_path = File.expand_path(creds_file_path)) ?
Hash[*(File.open(creds_file_path).readlines.map{ |l| l.strip!; l.split('=') }.flatten)] : {}
voc = vagrant_openshift_config['openstack']
override.vm.box = voc["box_name"] || "openstack-dummy-box"
override.vm.box_url = voc["box_url"] || OPENSTACK_BOX_URL
# Make sure the private key from the key pair is provided
override.ssh.private_key_path = creds['OSPrivateKeyPath'] || "~/.ssh/id_rsa"
os.endpoint = ENV['OS_AUTH_URL'] ? "#{ENV['OS_AUTH_URL']}/tokens" : creds['OSEndpoint']
os.tenant = ENV['OS_TENANT_NAME'] || creds['OSTenant']
os.username = ENV['OS_USERNAME'] || creds['OSUsername']
os.api_key = ENV['OS_PASSWORD'] || creds['OSAPIKey']
os.keypair_name = voc['key_pair'] || creds['OSKeyPairName'] || "<OSKeypair>" # as stored in Nova
os.flavor = voc['flavor'] || creds['OSFlavor'] || /m1.small/ # Regex or String
os.image = voc['image'] || creds['OSImage'] || /Fedora/ # Regex or String
os.ssh_username = user = voc['ssh_user']|| creds['OSSshUser'] || "root" # login for the VM instance
os.server_name = ENV['OS_HOSTNAME'] || vagrant_openshift_config['instance_name'] # name for the instance created
full_provision(override.vm, user) |
f07b4a8d |
# floating ip usually needed for accessing machines
floating_ip = creds['OSFloatingIP'] || ENV['OS_FLOATING_IP']
os.floating_ip = floating_ip == ":auto" ? :auto : floating_ip
floating_ip_pool = creds['OSFloatingIPPool'] || ENV['OS_FLOATING_IP_POOL']
os.floating_ip_pool = floating_ip_pool == "false" ? false : floating_ip_pool |
cfbb85e2 |
end if vagrant_openshift_config['openstack']
# ######################### |
7bedcca1 |
# Set AWS provider settings
config.vm.provider :aws do |aws, override| |
cfbb85e2 |
creds_file_path = ENV['AWS_CREDS'].nil? || ENV['AWS_CREDS'] == '' ? AWS_CRED_FILE : ENV['AWS_CREDS'] |
9482a0b5 |
if File.exist?(File.expand_path(creds_file_path))
aws_creds_file = Pathname.new(File.expand_path(creds_file_path)) |
fa4579e3 |
aws_creds = aws_creds_file.exist? ? Hash[*(File.open(aws_creds_file.to_s).readlines.map{ |l| l.strip!
l.split('=') }.flatten)] : {} |
7bedcca1 |
|
cfbb85e2 |
voc = vagrant_openshift_config['aws']
override.vm.box = voc['box_name'] || "aws-dummy-box"
override.vm.box_url = voc['box_url'] || AWS_BOX_URL
override.vm.synced_folder sync_from, sync_to, disabled: true # rsyncing to public cloud not a great experience, use git |
7bedcca1 |
override.ssh.username = vagrant_openshift_config['aws']['ssh_user']
override.ssh.private_key_path = aws_creds["AWSPrivateKeyPath"] || "PATH TO AWS KEYPAIR PRIVATE KEY" |
b6fa6eb3 |
override.ssh.insert_key = true |
7bedcca1 |
aws.access_key_id = aws_creds["AWSAccessKeyId"] || "AWS ACCESS KEY"
aws.secret_access_key = aws_creds["AWSSecretKey"] || "AWS SECRET KEY"
aws.keypair_name = aws_creds["AWSKeyPairName"] || "AWS KEYPAIR NAME" |
cfbb85e2 |
aws.ami = voc['ami']
aws.region = voc['ami_region']
aws.instance_type = voc['instance_type'] || "c3.large" |
7bedcca1 |
aws.instance_ready_timeout = 240 |
cfbb85e2 |
aws.tags = { "Name" => ENV['AWS_HOSTNAME'] || vagrant_openshift_config['instance_name'] } |
7bedcca1 |
aws.user_data = %{
#cloud-config
growpart:
mode: auto
devices: ['/']
runcmd: |
ff389dc0 |
- [ sh, -xc, "sed -i s/^Defaults.*requiretty/\#Defaults\ requiretty/g /etc/sudoers"] |
7bedcca1 |
}
aws.block_device_mapping = [
{
"DeviceName" => "/dev/sda1",
"Ebs.VolumeSize" => 25, |
98f44ebe |
"Ebs.VolumeType" => "gp2" |
7bedcca1 |
}
] |
5c6fcb42 |
end |
cfbb85e2 |
#full_provision(override.vm)
end if vagrant_openshift_config['aws'] |
6fe2ba99 |
end |