bixby-provision 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +29 -0
  3. data/Gemfile.lock +192 -0
  4. data/Rakefile +13 -0
  5. data/VERSION +1 -0
  6. data/Vagrantfile +64 -0
  7. data/bin/bixby-provision +6 -0
  8. data/bixby-provision.gemspec +113 -0
  9. data/lib/bixby-provision.rb +2 -0
  10. data/lib/bixby/provision.rb +65 -0
  11. data/lib/bixby/provision/app.rb +34 -0
  12. data/lib/bixby/provision/dsl.rb +23 -0
  13. data/lib/bixby/provision/dsl/base.rb +76 -0
  14. data/lib/bixby/provision/dsl/bundler.rb +18 -0
  15. data/lib/bixby/provision/dsl/config.rb +124 -0
  16. data/lib/bixby/provision/dsl/dir.rb +34 -0
  17. data/lib/bixby/provision/dsl/file.rb +108 -0
  18. data/lib/bixby/provision/dsl/inventory.rb +18 -0
  19. data/lib/bixby/provision/dsl/meteor.rb +30 -0
  20. data/lib/bixby/provision/dsl/nodejs.rb +73 -0
  21. data/lib/bixby/provision/dsl/npm.rb +18 -0
  22. data/lib/bixby/provision/dsl/ntp.rb +41 -0
  23. data/lib/bixby/provision/dsl/packager/apt.rb +46 -0
  24. data/lib/bixby/provision/dsl/packager/base.rb +11 -0
  25. data/lib/bixby/provision/dsl/packager/npm.rb +67 -0
  26. data/lib/bixby/provision/dsl/packager/yum.rb +100 -0
  27. data/lib/bixby/provision/dsl/packager/yum/epel.rb +71 -0
  28. data/lib/bixby/provision/dsl/packager/yum/mongodb.rb +43 -0
  29. data/lib/bixby/provision/dsl/ruby.rb +21 -0
  30. data/lib/bixby/provision/dsl/run_control.rb +49 -0
  31. data/lib/bixby/provision/dsl/scm.rb +34 -0
  32. data/lib/bixby/provision/dsl/scm/base.rb +11 -0
  33. data/lib/bixby/provision/dsl/scm/git.rb +89 -0
  34. data/lib/bixby/provision/dsl/scm/svn.rb +11 -0
  35. data/lib/bixby/provision/dsl/service.rb +56 -0
  36. data/lib/bixby/provision/dsl/services/base.rb +11 -0
  37. data/lib/bixby/provision/dsl/services/init.rb +40 -0
  38. data/lib/bixby/provision/dsl/system.rb +53 -0
  39. data/lib/bixby/provision/dsl/util/file.rb +100 -0
  40. data/lib/bixby/provision/dsl/variable.rb +27 -0
  41. data/lib/bixby/provision/manifest.rb +49 -0
  42. data/lib/bixby/provision/manifest/dsl_proxy.rb +17 -0
  43. data/manifest.rb +31 -0
  44. data/tasks/coverage.rake +2 -0
  45. data/tasks/jeweler.rake +21 -0
  46. data/tasks/test.rake +5 -0
  47. data/tasks/yard.rake +2 -0
  48. metadata +244 -0
@@ -0,0 +1,30 @@
1
+
2
+ module Bixby
3
+ module Provision
4
+
5
+ class Meteor < Base
6
+
7
+ EXPORTS = []
8
+
9
+ def install(opts={})
10
+ if File.exists? "/usr/local/bin/meteor" then
11
+ logger.info "meteor already installed; skipping"
12
+ return
13
+ end
14
+
15
+ logger.info "[meteor] installing meteor"
16
+ logged_systemu("curl -sL https://install.meteor.com | sh")
17
+ end
18
+
19
+ # Run meteorite install
20
+ def mrt(path, opts={})
21
+ logger.info "[meteor] mrt install"
22
+ logged_systemu("mrt install", :cwd => File.expand_path(path))
23
+ end
24
+
25
+ end
26
+
27
+ register_dsl Meteor
28
+
29
+ end
30
+ end
@@ -0,0 +1,73 @@
1
+
2
+ module Bixby
3
+ module Provision
4
+
5
+ class NodeJS < Base
6
+
7
+ EXPORTS = []
8
+
9
+ CURRENT_VERSION = "0.10.26"
10
+
11
+ def install(opts={})
12
+ logger.info "nodejs.install"
13
+
14
+ version = opts.delete(:version) || CURRENT_VERSION
15
+ path = opts.delete(:path) || "/usr/local"
16
+
17
+ if ubuntu? || opts[:tarball] then
18
+ install_from_tarball(version, path)
19
+ elsif amazon? or centos? then
20
+ sys.package "nodejs"
21
+ end
22
+
23
+ end
24
+
25
+
26
+ private
27
+
28
+ def install_from_tarball(version, path)
29
+
30
+ version = "v" + version if version !~ /^v/
31
+
32
+ bin = File.join(path, "bin", "node")
33
+ if File.exists?(bin) then
34
+ installed_ver = systemu("#{bin} --version").stdout.strip
35
+ if SemVer.parse(installed_ver) == SemVer.parse(version) then
36
+ logger.info "nodejs #{version} is already installed at #{path}"
37
+ return
38
+ elsif SemVer.parse(installed_ver) > SemVer.parse(version) then
39
+ logger.info "a newer nodejs (#{version}) is already installed at #{path}"
40
+ return
41
+ else
42
+ logger.info "nodejs #{installed_ver} is currently installed; upgrading to #{version}"
43
+ end
44
+ end
45
+
46
+ url = package_url(version)
47
+ Dir.mktmpdir("bixby-provision") do |dir|
48
+ Dir.chdir(dir) do
49
+ # download
50
+ logger.info "downloading #{url}"
51
+ systemu("wget -nv #{url}")
52
+
53
+ # install
54
+ file = File.basename(url)
55
+ logger.info "installing node-#{version}"
56
+ systemu("tar -xzf #{file}")
57
+ systemu("rm -f *.gz")
58
+ systemu("cd node* && sudo cp -a bin lib include share #{path}/")
59
+ end
60
+ end
61
+ end
62
+
63
+ def package_url(version)
64
+ arch = amd64?() ? "x64" : "x86"
65
+ "http://nodejs.org/dist/v0.10.26/node-#{version}-linux-#{arch}.tar.gz"
66
+ end
67
+
68
+ end
69
+
70
+ register_dsl NodeJS, :nodejs
71
+
72
+ end
73
+ end
@@ -0,0 +1,18 @@
1
+
2
+ module Bixby
3
+ module Provision
4
+
5
+ class NPM < Base
6
+
7
+ EXPORTS = []
8
+
9
+ def install(*packages)
10
+ Packager::NPM.new(self).install(*packages)
11
+ end
12
+
13
+ end
14
+
15
+ register_dsl NPM
16
+
17
+ end
18
+ end
@@ -0,0 +1,41 @@
1
+
2
+ module Bixby
3
+ module Provision
4
+
5
+ class NTP < Base
6
+
7
+ EXPORTS = []
8
+
9
+ DEFAULT_NTP_POOL = "ntp.ubuntu.com"
10
+
11
+ def initialize(*args)
12
+ super
13
+ @service = if ubuntu? then
14
+ "ntp"
15
+ elsif centos? or amazon? then
16
+ "ntpd"
17
+ end
18
+ end
19
+
20
+ def set(server=DEFAULT_NTP_POOL)
21
+ logger.info "ntp.set using #{server}"
22
+ sys.package "ntpdate"
23
+ stop
24
+ logged_sudo("ntpdate #{server}", :env => { "PATH" => PATH } )
25
+ start
26
+ end
27
+
28
+ def start
29
+ service.start @service
30
+ end
31
+
32
+ def stop
33
+ service.stop @service
34
+ end
35
+
36
+ end
37
+
38
+ register_dsl NTP
39
+
40
+ end
41
+ end
@@ -0,0 +1,46 @@
1
+
2
+ module Bixby
3
+ module Provision
4
+ module Packager
5
+
6
+ class Apt < PackagerBase
7
+
8
+ def refresh
9
+ sudo("apt-get -qqy update")
10
+ end
11
+
12
+ def upgrade_system
13
+ logged_sudo('DEBIAN_FRONTEND=noninteractive dpkg-reconfigure grub-pc', :env => env)
14
+ logged_sudo('apt-get -qqy -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade', :env => env)
15
+ logged_sudo('apt-get -qqy autoremove')
16
+ logged_sudo('apt-get -qqy autoclean')
17
+ end
18
+
19
+ def install(*packages)
20
+ packages.flatten!
21
+ logged_sudo("apt-get -qqy install " + packages.join(" "))
22
+ end
23
+
24
+ def install_repo(name, opts={})
25
+ name.downcase!
26
+ if name == "epel" then
27
+ logger.debug "#{name} isn't supported on this distro"
28
+ return
29
+ elsif name =~ /^https?.*\.repo$/ then
30
+ logger.debug "repo files are not supported on this distro: #{name}"
31
+ return
32
+ end
33
+ end
34
+
35
+
36
+ private
37
+
38
+ def env
39
+ { "DEBIAN_FRONTEND" => "noninteractive" }
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,11 @@
1
+
2
+ module Bixby
3
+ module Provision
4
+ module Packager
5
+
6
+ class PackagerBase < Base
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,67 @@
1
+
2
+ module Bixby
3
+ module Provision
4
+ module Packager
5
+
6
+ class NPM < PackagerBase
7
+
8
+ def install(*packages)
9
+ if packages.last.kind_of? Hash then
10
+ opts = packages.pop
11
+ else
12
+ opts = {}
13
+ end
14
+ packages = packages.flatten.sort
15
+
16
+ logger.info "npm install: " + packages.join(" ")
17
+
18
+ installed = query_installed_packages(packages, opts)
19
+ needed = packages.find_all{ |s| !installed.include? s }
20
+ if needed.empty? then
21
+ logger.info "[npm] package(s) already installed"
22
+ return
23
+ end
24
+
25
+ global = opts[:global]
26
+ if global then
27
+ cmd = "npm install -g " + packages.join(" ")
28
+ logged_sudo(cmd, env)
29
+ else
30
+ cmd = "npm install " + packages.join(" ")
31
+ logged_systemu(cmd, env)
32
+ end
33
+ end
34
+
35
+ def installed?(package, opts={})
36
+ query_installed_packages(package, opts).include? package
37
+ end
38
+
39
+ private
40
+
41
+
42
+ # Query NPM DB for presence of given packages. Returns a hash for easy lookup
43
+ #
44
+ # @param [Array<String>] packages
45
+ #
46
+ # @return [Hash<String, 1>]
47
+ def query_installed_packages(packages, opts={})
48
+ packages = [ packages ] if not packages.kind_of? Array
49
+ packages.flatten!
50
+
51
+ g = opts[:global] ? "-g" : ""
52
+
53
+ installed = {}
54
+ systemu("npm #{g} ls --parseable --depth 1 " + packages.join(" "), env).
55
+ stdout.split(/\n/).each{ |s| installed[File.basename(s)] = 1 }
56
+
57
+ return installed
58
+ end
59
+
60
+ def env
61
+ { :env => { "PATH" => Provision::Base::PATH } }
62
+ end
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,100 @@
1
+
2
+ module Bixby
3
+ module Provision
4
+ module Packager
5
+
6
+ class Yum < PackagerBase
7
+
8
+ YUM_REPOS_D = "/etc/yum.repos.d/"
9
+
10
+ REPOS = {}
11
+
12
+ def self.register_plugin(mod, method=nil, name=nil)
13
+ if name.nil? then
14
+ name = mod.name.split(/::/).last.downcase
15
+ end
16
+ if method.nil? then
17
+ method = "install_#{name}".to_sym
18
+ end
19
+ logger.debug "[yum] registered plugin: #{name}"
20
+ REPOS[name] = method
21
+ include(mod)
22
+ end
23
+
24
+ def refresh
25
+ sudo("yum -q clean all")
26
+ sudo("yum -q -y check-update")
27
+ end
28
+
29
+ def upgrade_system
30
+ logged_sudo('yum -q -y upgrade')
31
+ end
32
+
33
+ def install_repo(name, opts={})
34
+ name.downcase!
35
+ if REPOS.include? name then
36
+ return self.send(REPOS[name], opts)
37
+ elsif name =~ /^https?.*\.repo$/ then
38
+ return install_repo_url(name, opts)
39
+ end
40
+ end
41
+
42
+ def install(*packages)
43
+ packages.flatten!
44
+
45
+ # only install missing packages
46
+ installed = query_installed_packages(packages)
47
+ needed = packages.find_all{ |s| !installed.include? s }
48
+ return if needed.empty?
49
+
50
+ logged_sudo("yum -q -y install " + needed.join(" "))
51
+ end
52
+
53
+ def installed?(package)
54
+ query_installed_packages(package).include? package
55
+ end
56
+
57
+
58
+ private
59
+
60
+ # Query RPM DB for presence of given packages. Returns a hash for easy lookup
61
+ #
62
+ # @param [Array<String>] packages
63
+ #
64
+ # @return [Hash<String, 1>]
65
+ def query_installed_packages(packages)
66
+ packages = [ packages ] if not packages.kind_of? Array
67
+ packages.flatten!
68
+
69
+ installed = {}
70
+ systemu("rpm -qa --queryformat '%{NAME}\n' " + packages.join(" ")).
71
+ stdout.split(/\n/).each{ |s| installed[s] = 1 }
72
+
73
+ return installed
74
+ end
75
+
76
+ def install_repo_url(url, opts)
77
+ logger.info "installing repo from #{url}"
78
+
79
+ if File.exists? File.join(YUM_REPOS_D, File.basename(url)) then
80
+ logger.debug "repo already exists"
81
+ return false
82
+ end
83
+
84
+ self.proxy.sys.package "wget"
85
+
86
+ if systemu("wget -q #{url}", :cwd => YUM_REPOS_D).fail? then
87
+ # TODO raise
88
+ end
89
+
90
+ true
91
+ end
92
+
93
+ end # Yum
94
+
95
+ end
96
+ end
97
+ end
98
+
99
+ require "bixby/provision/dsl/packager/yum/epel"
100
+ require "bixby/provision/dsl/packager/yum/mongodb"
@@ -0,0 +1,71 @@
1
+
2
+ module Bixby
3
+ module Provision
4
+ module Packager
5
+ class Yum < PackagerBase
6
+
7
+ module EPEL
8
+
9
+ private
10
+
11
+ def install_epel(opts)
12
+
13
+ if amazon? then
14
+ return install_epel_amazon(opts)
15
+ end
16
+
17
+ if installed? "epel-release" then
18
+ logger.info "epel repo already installed"
19
+ return false
20
+ end
21
+
22
+ logger.info "installing epel repo"
23
+
24
+ url = if centos_version >= SemVer.parse("v6.0.0") && centos_version < SemVer.parse("v7.0.0") then
25
+ "http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm"
26
+ elsif centos_version >= SemVer.parse("v5.0.0") && centos_version < SemVer.parse("v6.0.0") then
27
+ "http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm"
28
+ end
29
+
30
+ Dir.mktmpdir("bixby-provision") do |dir|
31
+ Dir.chdir(dir) do
32
+ logged_sudo("rpm --quiet -iv #{url}")
33
+ end
34
+ end
35
+
36
+ true
37
+ end
38
+
39
+ def install_epel_amazon(opts)
40
+ logger.info "enabling epel on amazon linux"
41
+
42
+ file = "/etc/yum.repos.d/epel.repo"
43
+
44
+ buff = File.read(file)
45
+ out = []
46
+ found = false
47
+ buff.split(/\n/).each do |line|
48
+ if line =~ /^enabled=/ then
49
+ # always enable the first entry only (leave debug and source repos, for now)
50
+ found = true
51
+ out << "enabled=1"
52
+ else
53
+ out << line
54
+ end
55
+ end
56
+
57
+ File.open(file, 'w') do |f|
58
+ f.puts out.join("\n")
59
+ end
60
+
61
+ true
62
+ end
63
+
64
+ end # EPEL
65
+
66
+ Yum.register_plugin(EPEL)
67
+
68
+ end
69
+ end
70
+ end
71
+ end