Skip to content

Instantly share code, notes, and snippets.

@hferentschik
Created March 22, 2016 14:16
Show Gist options
  • Save hferentschik/3daaa9297a90016810f4 to your computer and use it in GitHub Desktop.
Save hferentschik/3daaa9297a90016810f4 to your computer and use it in GitHub Desktop.
Default CDK Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# The private network IP of the VM. You will use this IP to connect to OpenShift.
PUBLIC_ADDRESS="10.1.2.2"
# Number of virtualized CPUs
VM_CPU = ENV['VM_CPU'] || 2
# Amount of available RAM
VM_MEMORY = ENV['VM_MEMORY'] || 3072
# Validate required plugins
REQUIRED_PLUGINS = %w(vagrant-service-manager vagrant-registration)
message = ->(name) { "#{name} plugin is not installed, run `vagrant plugin install #{name}` to install it." }
errors = []
REQUIRED_PLUGINS.each {|plugin| errors << message.call(plugin) unless Vagrant.has_plugin?(plugin) }
msg = errors.size > 1 ? "Errors: \n* #{errors.join("\n* ")}" : "Error: #{errors.first}"
raise Vagrant::Errors::VagrantError.new, msg unless errors.size == 0
Vagrant.configure(2) do |config|
config.vm.box = "cdkv2"
config.vm.provider "virtualbox" do |v, override|
v.memory = VM_MEMORY
v.cpus = VM_CPU
v.customize ["modifyvm", :id, "--ioapic", "on"]
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
config.vm.provider "libvirt" do |v, override|
v.memory = VM_MEMORY
v.cpus = VM_CPU
v.driver = "kvm"
end
config.vm.network "private_network", ip: "#{PUBLIC_ADDRESS}"
if ENV.has_key?('SUB_USERNAME') && ENV.has_key?('SUB_PASSWORD')
cdk.registration.username = ENV['SUB_USERNAME']
cdk.registration.password = ENV['SUB_PASSWORD']
end
config.vm.provision "shell", inline: <<-SHELL
systemctl enable openshift
systemctl start openshift
SHELL
config.vm.provision "shell", inline: <<-SHELL
echo
echo "Successfully started and provisioned VM with #{VM_CPU} cores and #{VM_MEMORY} MB of memory."
echo "To modify the number of cores and/or available memory set the environment variables"
echo "VM_CPU respectively VM_MEMORY."
echo
echo "You can now access the OpenShift console on: https://#{PUBLIC_ADDRESS}:8443/console"
echo
echo "To use OpenShift CLI, run:"
echo "$ vagrant ssh"
echo "$ oc login #{PUBLIC_ADDRESS}:8443"
echo
echo "Configured users are (<username>/<password>):"
echo "openshift-dev/devel"
echo "admin/admin"
echo
echo "If you have the oc client library on your host, you can also login from your host."
echo
SHELL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment