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
-
#release ⇒ Object
readonly
Returns the value of attribute release.
-
#runner ⇒ Object
writeonly
Sets the attribute runner.
Instance Method Summary collapse
-
#build_dependencies(other_dependencies = nil) ⇒ Object
def dependencies.
-
#buildpacks(config) ⇒ Object
Returns a list of Buildpack objects.
-
#check(config) ⇒ Object
Check if all build dependencies are present.
-
#default_buildpack_list ⇒ Object
e.g.
-
#dependencies(other_dependencies = nil) ⇒ Object
def buildpacks.
-
#initialize(release) ⇒ Base
constructor
A new instance of Base.
-
#initializers_for(app_name, procfile_entries) ⇒ Object
Returns a list of <Process, FileTemplate> tuples.
- #os ⇒ Object
- #package_install_command(packages) ⇒ Object
-
#package_test_command(package) ⇒ Object
def slug.
- #postinstall_file(config) ⇒ Object
- #preinstall_file(config) ⇒ Object
-
#slug ⇒ Object
e.g.
-
#templates(config) ⇒ Object
Returns a list of file and directory templates.
Constructor Details
#initialize(release) ⇒ Base
Returns a new instance of Base.
13 14 15 |
# File 'lib/pkgr/distributions/base.rb', line 13 def initialize(release) @release = release end |
Instance Attribute Details
#release ⇒ Object (readonly)
Returns the value of attribute release.
10 11 12 |
# File 'lib/pkgr/distributions/base.rb', line 10 def release @release end |
#runner=(value) ⇒ Object (writeonly)
Sets the attribute runner
11 12 13 |
# File 'lib/pkgr/distributions/base.rb', line 11 def runner=(value) @runner = value end |
Instance Method Details
#build_dependencies(other_dependencies = nil) ⇒ Object
def dependencies
76 77 78 79 |
# File 'lib/pkgr/distributions/base.rb', line 76 def build_dependencies(other_dependencies = nil) deps = YAML.load_file(data_file("build_dependencies", "#{os}.yml")) (deps["default"] || []) | (deps[slug] || []) | (other_dependencies || []) end |
#buildpacks(config) ⇒ Object
Returns a list of Buildpack objects
61 62 63 64 65 66 67 68 69 |
# File 'lib/pkgr/distributions/base.rb', line 61 def buildpacks(config) 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(config) end end |
#check(config) ⇒ Object
Check if all build dependencies are present.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pkgr/distributions/base.rb', line 35 def check(config) 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 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 |
#default_buildpack_list ⇒ Object
e.g. data/buildpacks/ubuntu/12.04
56 57 58 |
# File 'lib/pkgr/distributions/base.rb', line 56 def default_buildpack_list data_file(File.join("buildpacks", slug)) end |
#dependencies(other_dependencies = nil) ⇒ Object
def buildpacks
71 72 73 74 |
# File 'lib/pkgr/distributions/base.rb', line 71 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.
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/pkgr/distributions/base.rb', line 108 def initializers_for(app_name, procfile_entries) list = [] procfile_entries.select(&:daemon?).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 |
#os ⇒ Object
17 18 19 |
# File 'lib/pkgr/distributions/base.rb', line 17 def os self.class.name.split("::")[-1].downcase end |
#package_install_command(packages) ⇒ Object
30 31 32 |
# File 'lib/pkgr/distributions/base.rb', line 30 def package_install_command(packages) raise NotImplementedError, "package_install_command must be implemented" end |
#package_test_command(package) ⇒ Object
def slug
26 27 28 |
# File 'lib/pkgr/distributions/base.rb', line 26 def package_test_command(package) raise NotImplementedError, "package_test_command must be implemented" end |
#postinstall_file(config) ⇒ Object
124 125 126 127 |
# File 'lib/pkgr/distributions/base.rb', line 124 def postinstall_file(config) @postinstall_file ||= generate_hook_file("postinstall.sh", config) @postinstall_file.path end |
#preinstall_file(config) ⇒ Object
119 120 121 122 |
# File 'lib/pkgr/distributions/base.rb', line 119 def preinstall_file(config) @preinstall_file ||= generate_hook_file("preinstall.sh", config) @preinstall_file.path end |
#slug ⇒ Object
e.g. ubuntu-12.04
22 23 24 |
# File 'lib/pkgr/distributions/base.rb', line 22 def slug [os, release].join("-") end |
#templates(config) ⇒ Object
Returns a list of file and directory templates.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/pkgr/distributions/base.rb', line 82 def templates(config) app_name = config.name list = [] # directories [ "usr/bin", config.home.gsub(/^\//, ""), "etc/#{app_name}/conf.d", "etc/default", "etc/init", "var/log/#{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")) # 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) # NOTE: /etc/appname/conf.d/* files are no longer installed here, since we don't want to overwrite any pre-existing config. # They're now installed in the postinstall script. list end |