Skip to content

Commit

Permalink
use fleet metadata for nginx, appside and devside
Browse files Browse the repository at this point in the history
  • Loading branch information
vbanthia committed Nov 9, 2015
1 parent ccaa189 commit 362d5b1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 68 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.vagrant
user-data_*
69 changes: 41 additions & 28 deletions coreos/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,34 @@
# -*- coding: utf-8 -*-

require 'fileutils'

require './coreos_config.rb'
require 'open-uri'
require 'yaml'

Vagrant.require_version '>= 1.6.0'

CLOUD_CONFIG_PATH = File.join(File.dirname(__FILE__), 'user-data')

update_channel = 'alpha'
image_version = 'current'
vm_memory = 512
vm_cpus = 1

cluster = [
{ name: 'core-01', hostname: 'core-01', ip: '172.17.8.101', metadata: 'role=nginx' },
{ name: 'core-02', hostname: 'core-02', ip: '172.17.8.102', metadata: 'role=appside' },
{ name: 'core-03', hostname: 'core-03', ip: '172.17.8.103', metadata: 'role=devside' }
]

# Used to fetch a new discovery token for a cluster of size 3
new_discovery_url = "https://discovery.etcd.io/new?size=#{ cluster.size }"
token = open(new_discovery_url).read

Vagrant.configure('2') do |config|
# always use Vagrants insecure key
config.ssh.insert_key = false

config.vm.box = "coreos-%s" % $update_channel
if $image_version != 'current'
config.vm.box_version = $image_version
end
config.vm.box_url = "http://%s.release.core-os.net/amd64-usr/%s/coreos_production_vagrant.json" % [$update_channel, $image_version]
config.vm.box = "coreos-%s" % update_channel
config.vm.box_url = "http://%s.release.core-os.net/amd64-usr/%s/coreos_production_vagrant.json" % [update_channel, image_version]

config.vm.provider :virtualbox do |v|
# On VirtualBox, we don't have guest additions or a functional vboxsf
Expand All @@ -26,33 +38,34 @@ Vagrant.configure('2') do |config|
v.functional_vboxsf = false
end

(1..$num_instances).each do |i|
config.vm.define vm_name = "%s-%02d" % [$instance_name_prefix, i] do |config|
config.vm.hostname = vm_name

if $enable_serial_logging
logdir = File.join(File.dirname(__FILE__), 'log')
FileUtils.mkdir_p(logdir)

serialFile = File.join(logdir, "%s-serial.txt" % vm_name)
FileUtils.touch(serialFile)
end

$forwarded_ports.each do |guest, host|
config.vm.network 'forwarded_port', guest: guest, host: host, auto_correct: true
end
cluster.each do |node|
config.vm.define node[:name] do |config|
config.vm.hostname = node[:hostname]

config.vm.provider :virtualbox do |v|
v.name = vm_name
v.memory = $vm_memory
v.cpus = $vm_cpus
v.name = node[:name]
v.memory = vm_memory
v.cpus = vm_cpus
end

ip = "172.17.8.#{ i+100 }"
config.vm.network :private_network, ip: ip
config.vm.network :private_network, ip: node[:ip]

# cloudconfig-init
config.vm.provision :file, :source => "#{ CLOUD_CONFIG_PATH }", :destination => '/tmp/vagrantfile-user-data'
data = YAML.load(IO.readlines('user-data')[1..-1].join)

# Add discovery url
data['coreos']['etcd2']['discovery'] = token

# Add metadata
data['coreos']['fleet']['metadata'] = node[:metadata]

yaml = YAML.dump(data)

source_file = File.join(File.dirname(__FILE__), "user-data_#{ node[:name] }")
FileUtils.rm source_file if File.exists?(source_file)
File.open(source_file, 'w') { |file| file.write("#cloud-config\n\n#{ yaml }") }

config.vm.provision :file, :source => source_file, :destination => '/tmp/vagrantfile-user-data'
config.vm.provision :shell, :inline => 'mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/', :privileged => true
end
end
Expand Down
40 changes: 0 additions & 40 deletions coreos/coreos_config.rb

This file was deleted.

1 change: 1 addition & 0 deletions coreos/user-data
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ coreos:
discovery: https://discovery.etcd.io/<token>
fleet:
public-ip: $public_ipv4
metadata: <metadata>
flannel:
interface: $public_ipv4
units:
Expand Down

0 comments on commit 362d5b1

Please sign in to comment.