dokkaacfg 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 27f436055c2acbf271304227311f1dd0ab97c653
4
+ data.tar.gz: 824e196bf28aed483de2daec3b0832a20ff3945d
5
+ SHA512:
6
+ metadata.gz: 3183966ca0ffe1bdfd57aeb700699e81e8bcec6ef8a78494cf6cc1f96638a80d309ea63045c525b13a42837743d99b73ed74adb0e67c5c262d3a90557f4646f2
7
+ data.tar.gz: 107812cbfc186ffeffb809f523d9c158d21c7d75317b34f40a939695162ba6c4cfe67eecd9f1a6b1a7080233be0a7ea50e1e924d1382d147bcd1b62d25a64d91
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .vagrant
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+
4
+ # Specify your gem's dependencies in dokkaacfg.gemspec
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dokkaacfg (0.0.1)
5
+ barge (~> 0.10)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.3.6)
11
+ barge (0.10.0)
12
+ faraday (~> 0.9)
13
+ faraday_middleware (~> 0.9)
14
+ hashie (~> 3.2)
15
+ crack (0.4.2)
16
+ safe_yaml (~> 1.0.0)
17
+ diff-lcs (1.2.5)
18
+ faraday (0.9.0)
19
+ multipart-post (>= 1.2, < 3)
20
+ faraday_middleware (0.9.1)
21
+ faraday (>= 0.7.4, < 0.10)
22
+ hashie (3.3.1)
23
+ multipart-post (2.0.0)
24
+ rspec (3.1.0)
25
+ rspec-core (~> 3.1.0)
26
+ rspec-expectations (~> 3.1.0)
27
+ rspec-mocks (~> 3.1.0)
28
+ rspec-core (3.1.3)
29
+ rspec-support (~> 3.1.0)
30
+ rspec-expectations (3.1.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.1.0)
33
+ rspec-mocks (3.1.0)
34
+ rspec-support (~> 3.1.0)
35
+ rspec-support (3.1.0)
36
+ safe_yaml (1.0.3)
37
+ webmock (1.18.0)
38
+ addressable (>= 2.3.6)
39
+ crack (>= 0.3.2)
40
+
41
+ PLATFORMS
42
+ ruby
43
+
44
+ DEPENDENCIES
45
+ bundler (~> 1.6)
46
+ dokkaacfg!
47
+ rspec (~> 3.1)
48
+ webmock (~> 1.18)
data/Vagrantfile ADDED
@@ -0,0 +1,101 @@
1
+ # -*- mode: ruby -*-
2
+ # # vi: set ft=ruby :
3
+
4
+ require 'fileutils'
5
+
6
+ Vagrant.require_version ">= 1.6.0"
7
+
8
+ CLOUD_CONFIG_PATH = File.join(File.dirname(__FILE__), "user-data")
9
+ CONFIG = File.join(File.dirname(__FILE__), "config.rb")
10
+
11
+ # Defaults for config options defined in CONFIG
12
+ $num_instances = 1
13
+ $update_channel = "alpha"
14
+ $enable_serial_logging = false
15
+ $vb_gui = false
16
+ $vb_memory = 1024
17
+ $vb_cpus = 1
18
+
19
+ # Attempt to apply the deprecated environment variable NUM_INSTANCES to
20
+ # $num_instances while allowing config.rb to override it
21
+ if ENV["NUM_INSTANCES"].to_i > 0 && ENV["NUM_INSTANCES"]
22
+ $num_instances = ENV["NUM_INSTANCES"].to_i
23
+ end
24
+
25
+ if File.exist?(CONFIG)
26
+ require CONFIG
27
+ end
28
+
29
+ Vagrant.configure("2") do |config|
30
+ config.vm.box = "coreos-%s" % $update_channel
31
+ config.vm.box_version = ">= 308.0.1"
32
+ config.vm.box_url = "http://%s.release.core-os.net/amd64-usr/current/coreos_production_vagrant.json" % $update_channel
33
+
34
+ config.vm.provider :vmware_fusion do |vb, override|
35
+ override.vm.box_url = "http://%s.release.core-os.net/amd64-usr/current/coreos_production_vagrant_vmware_fusion.json" % $update_channel
36
+ end
37
+
38
+ config.vm.provider :virtualbox do |v|
39
+ # On VirtualBox, we don't have guest additions or a functional vboxsf
40
+ # in CoreOS, so tell Vagrant that so it can be smarter.
41
+ v.check_guest_additions = false
42
+ v.functional_vboxsf = false
43
+ end
44
+
45
+ # plugin conflict
46
+ if Vagrant.has_plugin?("vagrant-vbguest") then
47
+ config.vbguest.auto_update = false
48
+ end
49
+
50
+ (1..$num_instances).each do |i|
51
+ config.vm.define vm_name = "core-%02d" % i do |config|
52
+ config.vm.hostname = vm_name
53
+
54
+ if $enable_serial_logging
55
+ logdir = File.join(File.dirname(__FILE__), "log")
56
+ FileUtils.mkdir_p(logdir)
57
+
58
+ serialFile = File.join(logdir, "%s-serial.txt" % vm_name)
59
+ FileUtils.touch(serialFile)
60
+
61
+ config.vm.provider :vmware_fusion do |v, override|
62
+ v.vmx["serial0.present"] = "TRUE"
63
+ v.vmx["serial0.fileType"] = "file"
64
+ v.vmx["serial0.fileName"] = serialFile
65
+ v.vmx["serial0.tryNoRxLoss"] = "FALSE"
66
+ end
67
+
68
+ config.vm.provider :virtualbox do |vb, override|
69
+ vb.customize ["modifyvm", :id, "--uart1", "0x3F8", "4"]
70
+ vb.customize ["modifyvm", :id, "--uartmode1", serialFile]
71
+ end
72
+ end
73
+
74
+ if $expose_docker_tcp
75
+ config.vm.network "forwarded_port", guest: 2375, host: ($expose_docker_tcp + i - 1), auto_correct: true
76
+ end
77
+
78
+ config.vm.provider :vmware_fusion do |vb|
79
+ vb.gui = $vb_gui
80
+ end
81
+
82
+ config.vm.provider :virtualbox do |vb|
83
+ vb.gui = $vb_gui
84
+ vb.memory = $vb_memory
85
+ vb.cpus = $vb_cpus
86
+ end
87
+
88
+ ip = "172.17.8.#{i+100}"
89
+ config.vm.network :private_network, ip: ip
90
+
91
+ # Uncomment below to enable NFS for sharing the host machine into the coreos-vagrant VM.
92
+ #config.vm.synced_folder ".", "/home/core/share", id: "core", :nfs => true, :mount_options => ['nolock,vers=3,udp']
93
+
94
+ if File.exist?(CLOUD_CONFIG_PATH)
95
+ config.vm.provision :file, :source => "#{CLOUD_CONFIG_PATH}", :destination => "/tmp/vagrantfile-user-data"
96
+ config.vm.provision :shell, :inline => "mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/", :privileged => true
97
+ end
98
+
99
+ end
100
+ end
101
+ end
data/bin/dokkaacfg ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path("../../lib/", __FILE__)
4
+
5
+ require 'dokkaacfg'
6
+ require 'optparse'
7
+
8
+ options = {}
9
+ optparse = OptionParser.new
10
+ optparse.on("-p VAL", "--provider=VAL", "Cloud provider name") do |p|
11
+ options[:provider] = p
12
+ end
13
+
14
+ optparse.on("--scale=VAL", "Initial scale") { |s| options[:scale] = s.to_i }
15
+ optparse.on("--region=VAL", "Region") { |r| options[:region] = r }
16
+ optparse.on("--slug=VAL", "Slug") { |s| options[:slug] = s }
17
+ optparse.on("--ssh_key=VAL", "SSH key") { |s| options[:ssh_key] = s }
18
+ optparse.parse!
19
+
20
+ subcmd = ARGV[0]
21
+ args = ARGV[1..-1]
22
+
23
+ provider_name = options.delete :provider
24
+ case provider_name
25
+ when "vagrant"
26
+ require 'dokkaacfg/vagrant'
27
+ provider = DokkaaCfg::Vagrant.new
28
+ when "digitalocean"
29
+ require 'dokkaacfg/digitalocean'
30
+ provider = DokkaaCfg::DigitalOcean.new
31
+ else
32
+ end
33
+
34
+ provider.execute(subcmd, args, options)
data/config.rb ADDED
@@ -0,0 +1,51 @@
1
+
2
+ # To automatically replace the discovery token on 'vagrant up', uncomment
3
+ # the lines below:
4
+ #
5
+ if File.exists?('user-data') && ARGV[0].eql?('up')
6
+ require 'open-uri'
7
+ require 'yaml'
8
+
9
+ token = open('https://discovery.etcd.io/new').read
10
+
11
+ data = YAML.load(IO.readlines('user-data')[1..-1].join)
12
+ data['coreos']['etcd']['discovery'] = token
13
+
14
+ lines = YAML.dump(data).split("\n")
15
+ lines[0] = '#cloud-config'
16
+
17
+ open('user-data', 'r+') do |f|
18
+ f.puts(lines.join("\n"))
19
+ end
20
+ end
21
+
22
+
23
+ # coreos-vagrant is configured through a series of configuration
24
+ # options (global ruby variables) which are detailed below. To modify
25
+ # these options, first copy this file to "config.rb". Then simply
26
+ # uncomment the necessary lines, leaving the $, and replace everything
27
+ # after the equals sign..
28
+
29
+ # Size of the CoreOS cluster created by Vagrant
30
+ $num_instances=2
31
+
32
+ # Official CoreOS channel from which updates should be downloaded
33
+ #$update_channel='alpha'
34
+
35
+ # Log the serial consoles of CoreOS VMs to log/
36
+ # Enable by setting value to true, disable with false
37
+ # WARNING: Serial logging is known to result in extremely high CPU usage with
38
+ # VirtualBox, so should only be used in debugging situations
39
+ #$enable_serial_logging=false
40
+
41
+ # Enable port forwarding of Docker TCP socket
42
+ # Set to the TCP port you want exposed on the *host* machine, default is 2375
43
+ # If 2375 is used, Vagrant will auto-increment (e.g. in the case of $num_instances > 1)
44
+ # You can then use the docker tool locally by setting the following env var:
45
+ # export DOCKER_HOST='tcp://127.0.0.1:2375'
46
+ #$expose_docker_tcp=2375
47
+
48
+ # Setting for VirtualBox VMs
49
+ #$vb_gui = false
50
+ #$vb_memory = 1024
51
+ #$vb_cpus = 1
data/dokkaacfg.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dokkaacfg/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dokkaacfg"
8
+ spec.version = DokkaaCfg::VERSION
9
+ spec.authors = ["Kazunori Kajihiro"]
10
+ spec.email = ["likerichie@gmail.com"]
11
+ spec.summary = 'Configuration management for Dokkaa cluster'
12
+ spec.description = 'Manage dokkaa running on cloud providers'
13
+ spec.homepage = "https://github.com/k2nr/dokkaacfg"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'barge', "~> 0.10"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency 'rspec', "~> 3.1"
25
+ spec.add_development_dependency 'webmock', "~> 1.18"
26
+ end
@@ -0,0 +1,72 @@
1
+ require 'barge'
2
+ require 'optparse'
3
+ require 'dokkaacfg/provider'
4
+ require 'dokkaacfg/user_data'
5
+
6
+ module DokkaaCfg
7
+ class DigitalOcean < Provider
8
+ DROPLET_NAME_PREFIX = 'dokkaa-'
9
+
10
+ def initialize(access_token=nil)
11
+ super()
12
+ access_token ||= ENV["DIGITALOCEAN_ACCESS_TOKEN"]
13
+ @client = Barge::Client.new(access_token: access_token)
14
+ end
15
+
16
+ def up(args, options={})
17
+ options[:scale] ||= 1
18
+ options[:region] ||= 'sfo1'
19
+ options[:slug] ||= '512mb'
20
+ ssh_keys = keys.map do |k|
21
+ if k.name == options[:ssh_key]
22
+ k.id
23
+ end
24
+ end.compact
25
+ user_data = UserData.make_user_data
26
+
27
+ (1..options[:scale]).each do |n|
28
+ name = "#{DROPLET_NAME_PREFIX}#{n}"
29
+ puts "launching #{name}"
30
+ p @client.droplet.create(
31
+ name: name,
32
+ region: options[:region],
33
+ size: options[:slug],
34
+ image: "coreos-alpha",
35
+ ssh_keys: ssh_keys,
36
+ private_networking: true,
37
+ user_data: user_data
38
+ )
39
+ end
40
+ end
41
+
42
+ def scale(args, options=nil)
43
+ end
44
+
45
+ def down(args, options=nil)
46
+ droplets = @client.droplet.all["droplets"]
47
+ r = droplet_regexp
48
+ droplets.each do |d|
49
+ if r.match(d.name)
50
+ p @client.droplet.destroy(d.id)
51
+ end
52
+ end
53
+ end
54
+
55
+ private
56
+ def coreos_user_data
57
+ end
58
+ def droplet_regexp
59
+ Regexp.new("^#{DROPLET_NAME_PREFIX}")
60
+ end
61
+
62
+ def dokkaa_droplets
63
+ droplets = @client.droplet.all["droplets"]
64
+ r = droplet_regexp
65
+ droplets.filter{|d| d.name =~ r}
66
+ end
67
+
68
+ def keys
69
+ @keys ||= @client.key.all["ssh_keys"]
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,14 @@
1
+
2
+ module DokkaaCfg
3
+ class Provider
4
+ def initialize
5
+ end
6
+
7
+ def execute(cmd, args, options)
8
+ cmd = cmd.to_sym
9
+ if self.respond_to?(cmd)
10
+ self.send(cmd, args, options)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ require 'open-uri'
2
+ require 'yaml'
3
+
4
+ module DokkaaCfg
5
+ class UserData
6
+ USER_DATA_PATH = File.join(File.expand_path("../../../", __FILE__), "user-data")
7
+
8
+ def self.make_user_data
9
+ yaml = YAML.load_file(USER_DATA_PATH)
10
+ etcd_token = open('https://discovery.etcd.io/new').read
11
+ yaml['coreos']['etcd']['discovery'] = etcd_token
12
+ lines = YAML.dump(yaml).split("\n")
13
+ lines[0] = '#cloud-config'
14
+ lines.join("\n")
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module DokkaaCfg
2
+ VERSION = "0.0.1"
3
+ end
data/lib/dokkaacfg.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'dokkaacfg/version'
2
+
3
+ module DokkaaCfg
4
+ end
data/user-data ADDED
@@ -0,0 +1,92 @@
1
+ #cloud-config
2
+ coreos:
3
+ etcd:
4
+ addr: $public_ipv4:4001
5
+ peer-addr: $public_ipv4:7001
6
+ discovery: https://discovery.etcd.io/40a854ba6063d605c42571e23dad4e5d
7
+ fleet:
8
+ public-ip: $public_ipv4
9
+ units:
10
+ - name: etcd.service
11
+ command: start
12
+ - name: fleet.service
13
+ command: start
14
+ - name: docker-tcp.socket
15
+ command: start
16
+ enable: true
17
+ content: |
18
+ [Unit]
19
+ Description=Docker Socket for the API
20
+
21
+ [Socket]
22
+ ListenStream=2375
23
+ Service=docker.service
24
+ BindIPv6Only=both
25
+
26
+ [Install]
27
+ WantedBy=sockets.target
28
+ [Socket]
29
+ ListenStream=2375
30
+ Service=docker.service
31
+ BindIPv6Only=both
32
+
33
+ [Install]
34
+ WantedBy=sockets.target
35
+ - name: dokkaa-conductor.service
36
+ command: start
37
+ enable: true
38
+ content: |
39
+ [Unit]
40
+ Description=dokkaa-conductor
41
+ After=docker.service
42
+ Requires=docker.service
43
+
44
+ [Service]
45
+ ExecStartPre=/usr/bin/docker pull k2nr/dokkaa-conductor
46
+ ExecStart=/usr/bin/docker run --name conductor \
47
+ -v /var/run/docker.sock:/var/run/docker.sock \
48
+ -e HOST_IP=$public_ipv4 \
49
+ -e DOCKER_HOST=unix:///var/run/docker.sock \
50
+ -e ETCD_ADDR=$public_ipv4:4001 \
51
+ --restart=always \
52
+ k2nr/dokkaa-conductor
53
+ TimeoutStartSec=30m
54
+ ExecStop=/usr/bin/docker rm -f conductor
55
+ - name: dokkaa-ambassador.service
56
+ command: start
57
+ enable: true
58
+ content: |
59
+ [Unit]
60
+ Description=dokkaa-ambassador
61
+ After=docker.service
62
+ Requires=docker.service
63
+
64
+ [Service]
65
+ ExecStartPre=/usr/bin/docker pull k2nr/dokkaa-ambassador
66
+ ExecStart=/usr/bin/docker run --name ambassador \
67
+ -v /var/run/docker.sock:/var/run/docker.sock \
68
+ -e DOCKER_HOST=unix:///var/run/docker.sock \
69
+ --dns=$public_ipv4 \
70
+ --restart=always \
71
+ k2nr/dokkaa-ambassador
72
+ TimeoutStartSec=30m
73
+ ExecStop=/usr/bin/docker rm -f ambassador
74
+ - name: skydns.service
75
+ command: start
76
+ enable: true
77
+ content: |
78
+ [Unit]
79
+ Description=skydns
80
+ After=docker.service
81
+ Requires=docker.service
82
+
83
+ [Service]
84
+ ExecStartPre=/usr/bin/docker pull k2nr/skydns-docker
85
+ ExecStart=/usr/bin/docker run --name skydns \
86
+ -e ETCD_MACHINES=http://$public_ipv4:4001 \
87
+ -e SKYDNS_ADDR=0.0.0.0:53 \
88
+ -e SKYDNS_NAMESERVERS=8.8.8.8:53,8.8.4.4:53 \
89
+ -p $public_ipv4:53:53/udp \
90
+ k2nr/skydns-docker
91
+ TimeoutStartSec=30m
92
+ ExecStop=/usr/bin/docker rm -f skydns
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dokkaacfg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kazunori Kajihiro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: barge
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.18'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.18'
69
+ description: Manage dokkaa running on cloud providers
70
+ email:
71
+ - likerichie@gmail.com
72
+ executables:
73
+ - dokkaacfg
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - Vagrantfile
81
+ - bin/dokkaacfg
82
+ - config.rb
83
+ - dokkaacfg.gemspec
84
+ - lib/dokkaacfg.rb
85
+ - lib/dokkaacfg/digitalocean.rb
86
+ - lib/dokkaacfg/provider.rb
87
+ - lib/dokkaacfg/user_data.rb
88
+ - lib/dokkaacfg/version.rb
89
+ - user-data
90
+ homepage: https://github.com/k2nr/dokkaacfg
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.2.2
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Configuration management for Dokkaa cluster
114
+ test_files: []