Class: Pkgr::Distributions::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/pkgr/distributions/base.rb

Overview

Base components and behaviors for all distributions.

Direct Known Subclasses

Amazon, Debian, Fedora, Sles

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(release, config = Config.new) ⇒ Base

Returns a new instance of Base.



16
17
18
19
# File 'lib/pkgr/distributions/base.rb', line 16

def initialize(release, config = Config.new)
  @config = config
  @release = release
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



14
15
16
# File 'lib/pkgr/distributions/base.rb', line 14

def config
  @config
end

#releaseObject (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

Parameters:

  • value

    the value to set the attribute runner to.



13
14
15
# File 'lib/pkgr/distributions/base.rb', line 13

def runner=(value)
  @runner = value
end

Instance Method Details

#build_dependencies(other_dependencies = nil) ⇒ Object

def dependencies



93
94
95
96
# File 'lib/pkgr/distributions/base.rb', line 93

def build_dependencies(other_dependencies = nil)
  deps = YAML.load_file(data_file("build_dependencies", "#{os}.yml"))
  (deps["default"] || []) | (deps[slug] || []) | (other_dependencies || [])
end

#buildpacksObject

Returns a list of Buildpack objects



79
80
81
82
83
84
85
# File 'lib/pkgr/distributions/base.rb', line 79

def buildpacks
  if config.buildpacks
    [:custom, config.buildpacks.map { |url| Buildpack.new(url, :custom, config.env) }]
  else
    [:builtin, load_buildpack_list]
  end
end

#checkObject

Check if all build dependencies are present.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/pkgr/distributions/base.rb', line 47

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_dirObject



138
139
140
# File 'lib/pkgr/distributions/base.rb', line 138

def crons_dir
  "etc/cron.d"
end

#default_buildpack_listObject

e.g. data/buildpacks/ubuntu/12.04



74
75
76
# File 'lib/pkgr/distributions/base.rb', line 74

def default_buildpack_list
  data_file(File.join("buildpacks", slug))
end

#dependencies(other_dependencies = nil) ⇒ Object

def buildpacks



87
88
89
90
91
# File 'lib/pkgr/distributions/base.rb', line 87

def dependencies(other_dependencies = nil)
  deps = YAML.load_file(data_file("dependencies", "#{os}.yml"))
  deps = {} if config.skip_default_dependencies?
  (deps["default"] || []) | (deps[slug] || []) | (other_dependencies || [])
end

#initializers_for(app_name, procfile_entries) ⇒ Object

Returns a list of <Process, FileTemplate> tuples.



127
128
129
130
131
132
133
134
135
136
# File 'lib/pkgr/distributions/base.rb', line 127

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_dependenciesObject



162
163
164
# File 'lib/pkgr/distributions/base.rb', line 162

def installer_dependencies
  ["dialog", "bash"]
end

#osObject



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

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/pkgr/distributions/base.rb', line 42

def package_install_command(packages)
  raise NotImplementedError, "package_install_command must be implemented"
end

#package_test_command(package) ⇒ Object

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/pkgr/distributions/base.rb', line 38

def package_test_command(package)
  raise NotImplementedError, "package_test_command must be implemented"
end

#postinstall_fileObject



147
148
149
150
# File 'lib/pkgr/distributions/base.rb', line 147

def postinstall_file
  @postinstall_file ||= generate_hook_file("postinstall.sh")
  @postinstall_file.path
end

#postuninstall_fileObject



157
158
159
160
# File 'lib/pkgr/distributions/base.rb', line 157

def postuninstall_file
  @postuninstall_file ||= generate_hook_file("postuninstall.sh")
  @postuninstall_file.path
end

#preinstall_fileObject



142
143
144
145
# File 'lib/pkgr/distributions/base.rb', line 142

def preinstall_file
  @preinstall_file ||= generate_hook_file("preinstall.sh")
  @preinstall_file.path
end

#preuninstall_fileObject



152
153
154
155
# File 'lib/pkgr/distributions/base.rb', line 152

def preuninstall_file
  @preuninstall_file ||= generate_hook_file("preuninstall.sh")
  @preuninstall_file.path
end

#slugObject

e.g. ubuntu-12.04



26
27
28
# File 'lib/pkgr/distributions/base.rb', line 26

def slug
  [os, release].join("-")
end

#targetObject

def slug



30
31
32
33
34
35
36
# File 'lib/pkgr/distributions/base.rb', line 30

def target
  {
    "centos-6" => "el:6",
    "centos-7" => "el:7",
    "centos-8" => "el:8"
  }.fetch(slug, slug.sub("-", ":"))
end

#templatesObject

Returns a list of file and directory templates.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/pkgr/distributions/base.rb', line 99

def templates
  app_name = config.name
  list = []

  directories = [
    config.home.gsub(/^\//, ""),
    "etc/#{app_name}/conf.d",
    "etc/default",
    "var/log/#{app_name}",
    "var/db/#{app_name}",
    "usr/share/#{app_name}"
  ]

  directories << "usr/bin" if config.cli?
  directories.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



69
70
71
# File 'lib/pkgr/distributions/base.rb', line 69

def verify(output_dir)
  true
end