Class: Pkgr::Distributions::Base
- Inherits:
-
Object
- Object
- Pkgr::Distributions::Base
- Defined in:
- lib/pkgr/distributions/base.rb
Overview
Base components and behaviors for all distributions.
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#release ⇒ Object
readonly
Returns the value of attribute release.
-
#runner ⇒ Object
writeonly
Sets the attribute runner.
Instance Method Summary collapse
- #add_addon(addon) ⇒ Object
-
#build_dependencies(other_dependencies = nil) ⇒ Object
def dependencies.
-
#buildpacks ⇒ Object
Returns a list of Buildpack objects.
-
#check ⇒ Object
Check if all build dependencies are present.
- #crons_dir ⇒ Object
-
#default_buildpack_list ⇒ Object
e.g.
-
#dependencies(other_dependencies = nil) ⇒ Object
def buildpacks.
-
#initialize(release, config = Config.new) ⇒ Base
constructor
A new instance of Base.
-
#initializers_for(app_name, procfile_entries) ⇒ Object
Returns a list of <Process, FileTemplate> tuples.
- #installer_dependencies ⇒ Object
- #os ⇒ Object
- #package_install_command(packages) ⇒ Object
-
#package_test_command(package) ⇒ Object
def slug.
- #postinstall_file ⇒ Object
- #postuninstall_file ⇒ Object
- #preinstall_file ⇒ Object
- #preuninstall_file ⇒ Object
-
#slug ⇒ Object
e.g.
-
#templates ⇒ Object
Returns a list of file and directory templates.
-
#verify(output_dir) ⇒ Object
Verifies packages.
Constructor Details
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
14 15 16 |
# File 'lib/pkgr/distributions/base.rb', line 14 def config @config end |
#release ⇒ Object (readonly)
Returns the value of attribute release.
12 13 14 |
# File 'lib/pkgr/distributions/base.rb', line 12 def release @release end |
#runner=(value) ⇒ Object (writeonly)
Sets the attribute runner
13 14 15 |
# File 'lib/pkgr/distributions/base.rb', line 13 def runner=(value) @runner = value end |
Instance Method Details
#add_addon(addon) ⇒ Object
134 135 136 |
# File 'lib/pkgr/distributions/base.rb', line 134 def add_addon(addon) nil end |
#build_dependencies(other_dependencies = nil) ⇒ Object
def dependencies
86 87 88 89 |
# File 'lib/pkgr/distributions/base.rb', line 86 def build_dependencies(other_dependencies = nil) deps = YAML.load_file(data_file("build_dependencies", "#{os}.yml")) (deps["default"] || []) | (deps[slug] || []) | (other_dependencies || []) end |
#buildpacks ⇒ Object
Returns a list of Buildpack objects
71 72 73 74 75 76 77 78 79 |
# File 'lib/pkgr/distributions/base.rb', line 71 def buildpacks custom_buildpack_uri = config.buildpack if custom_buildpack_uri uuid = Digest::SHA1.hexdigest(custom_buildpack_uri) [Buildpack.new(custom_buildpack_uri, :custom, config.env)] else load_buildpack_list end end |
#check ⇒ Object
Check if all build dependencies are present.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/pkgr/distributions/base.rb', line 39 def check missing_packages = (build_dependencies(config.build_dependencies) || []).select do |package| test_command = package_test_command(package) Pkgr.debug "sh(#{test_command})" ! system(test_command) end unless missing_packages.empty? install_command = package_install_command(missing_packages) if config.auto puts "-----> Installing missing build dependencies: #{missing_packages.join(", ")}" package_install = Mixlib::ShellOut.new(install_command) package_install.logger = Pkgr.logger package_install.run_command package_install.error! else Pkgr.warn("Missing build dependencies detected. Run the following to fix: #{install_command}") end end end |
#crons_dir ⇒ Object
130 131 132 |
# File 'lib/pkgr/distributions/base.rb', line 130 def crons_dir "etc/cron.d" end |
#default_buildpack_list ⇒ Object
e.g. data/buildpacks/ubuntu/12.04
66 67 68 |
# File 'lib/pkgr/distributions/base.rb', line 66 def default_buildpack_list data_file(File.join("buildpacks", slug)) end |
#dependencies(other_dependencies = nil) ⇒ Object
def buildpacks
81 82 83 84 |
# File 'lib/pkgr/distributions/base.rb', line 81 def dependencies(other_dependencies = nil) deps = YAML.load_file(data_file("dependencies", "#{os}.yml")) (deps["default"] || []) | (deps[slug] || []) | (other_dependencies || []) end |
#initializers_for(app_name, procfile_entries) ⇒ Object
Returns a list of <Process, FileTemplate> tuples.
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/pkgr/distributions/base.rb', line 119 def initializers_for(app_name, procfile_entries) list = [] procfile_entries.each do |process| Pkgr.debug "Adding #{process.inspect} to initialization scripts" runner.templates(process, app_name).each do |template| list.push [process, template] end end list end |
#installer_dependencies ⇒ Object
158 159 160 |
# File 'lib/pkgr/distributions/base.rb', line 158 def installer_dependencies ["dialog", "bash"] end |
#os ⇒ Object
21 22 23 |
# File 'lib/pkgr/distributions/base.rb', line 21 def os self.class.name.split("::")[-1].downcase end |
#package_install_command(packages) ⇒ Object
34 35 36 |
# File 'lib/pkgr/distributions/base.rb', line 34 def package_install_command(packages) raise NotImplementedError, "package_install_command must be implemented" end |
#package_test_command(package) ⇒ Object
def slug
30 31 32 |
# File 'lib/pkgr/distributions/base.rb', line 30 def package_test_command(package) raise NotImplementedError, "package_test_command must be implemented" end |
#postinstall_file ⇒ Object
143 144 145 146 |
# File 'lib/pkgr/distributions/base.rb', line 143 def postinstall_file @postinstall_file ||= generate_hook_file("postinstall.sh") @postinstall_file.path end |
#postuninstall_file ⇒ Object
153 154 155 156 |
# File 'lib/pkgr/distributions/base.rb', line 153 def postuninstall_file @postuninstall_file ||= generate_hook_file("postuninstall.sh") @postuninstall_file.path end |
#preinstall_file ⇒ Object
138 139 140 141 |
# File 'lib/pkgr/distributions/base.rb', line 138 def preinstall_file @preinstall_file ||= generate_hook_file("preinstall.sh") @preinstall_file.path end |
#preuninstall_file ⇒ Object
148 149 150 151 |
# File 'lib/pkgr/distributions/base.rb', line 148 def preuninstall_file @preuninstall_file ||= generate_hook_file("preuninstall.sh") @preuninstall_file.path end |
#slug ⇒ Object
e.g. ubuntu-12.04
26 27 28 |
# File 'lib/pkgr/distributions/base.rb', line 26 def slug [os, release].join("-") end |
#templates ⇒ Object
Returns a list of file and directory templates.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/pkgr/distributions/base.rb', line 92 def templates app_name = config.name list = [] # directories [ "usr/bin", config.home.gsub(/^\//, ""), "etc/#{app_name}/conf.d", "etc/default", "var/log/#{app_name}", "var/db/#{app_name}", "usr/share/#{app_name}" ].each{|dir| list.push Templates::DirTemplate.new(dir) } list.push Templates::FileTemplate.new("etc/default/#{app_name}", data_file("environment", "default.erb")) list.push Templates::FileTemplate.new("etc/logrotate.d/#{app_name}", data_file("logrotate", "logrotate.erb")) if config.cli? # Put cli in /usr/bin, as redhat based distros don't have /usr/local/bin in their sudo PATH. list.push Templates::FileTemplate.new("usr/bin/#{app_name}", data_file("cli", "cli.sh.erb"), mode: 0755) end list end |
#verify(output_dir) ⇒ Object
Verifies packages
61 62 63 |
# File 'lib/pkgr/distributions/base.rb', line 61 def verify(output_dir) true end |