Class: Pkgr::Distributions::Debian

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

Direct Known Subclasses

DebianSqueeze, DebianWheezy

Instance Method Summary collapse

Instance Method Details

#build_dependencies(other_dependencies = nil) ⇒ Object



151
152
153
154
# File 'lib/pkgr/distributions/debian.rb', line 151

def build_dependencies(other_dependencies = nil)
  deps = YAML.load_file(File.join(data_dir, "build_dependencies.yml"))
  (deps["default"] || []) | (deps[codename] || []) | (other_dependencies || [])
end

#buildpacks(config) ⇒ Object



108
109
110
111
112
113
114
115
116
# File 'lib/pkgr/distributions/debian.rb', line 108

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



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/pkgr/distributions/debian.rb', line 66

def check(config)
  missing_packages = (build_dependencies(config.build_dependencies) || []).select do |package|
    test_command = "dpkg -s '#{package}' > /dev/null 2>&1"
    Pkgr.debug "sh(#{test_command})"
    ! system(test_command)
  end

  unless missing_packages.empty?
    package_install_command = "sudo apt-get update && sudo apt-get install --force-yes -y #{missing_packages.map{|package| "\"#{package}\""}.join(" ")}"
    if config.auto
      package_install = Mixlib::ShellOut.new(package_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: #{package_install_command}")
    end
  end
end

#codenameObject

Must be subclassed.

Raises:

  • (NotImplementedError)


11
12
13
# File 'lib/pkgr/distributions/debian.rb', line 11

def codename
  raise NotImplementedError, "codename must be set"
end

#data_dirObject



160
161
162
# File 'lib/pkgr/distributions/debian.rb', line 160

def data_dir
  File.join(Pkgr.data_dir, "distributions", "debian")
end

#data_file(name) ⇒ Object



156
157
158
# File 'lib/pkgr/distributions/debian.rb', line 156

def data_file(name)
  File.new(File.join(data_dir, name))
end

#default_buildpack_listObject



118
119
120
# File 'lib/pkgr/distributions/debian.rb', line 118

def default_buildpack_list
  data_file(File.join("buildpacks", "#{osfamily}_#{codename}"))
end

#dependencies(other_dependencies = nil) ⇒ Object



146
147
148
149
# File 'lib/pkgr/distributions/debian.rb', line 146

def dependencies(other_dependencies = nil)
  deps = YAML.load_file(File.join(data_dir, "dependencies.yml"))
  (deps["default"] || []) | (deps[codename] || []) | (other_dependencies || [])
end

#fpm_command(build_dir, config) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/pkgr/distributions/debian.rb', line 86

def fpm_command(build_dir, config)
  %{
    fpm -t deb -s dir  --verbose --force \
    -C "#{build_dir}" \
    -n "#{config.name}" \
    --version "#{config.version}" \
    --iteration "#{config.iteration}" \
    --url "#{config.homepage}" \
    --provides "#{config.name}" \
    --deb-user "root" \
    --deb-group "root" \
    -a "#{config.architecture}" \
    --description "#{config.description}" \
    --maintainer "#{config.maintainer}" \
    --template-scripts \
    --before-install #{preinstall_file(config)} \
    --after-install #{postinstall_file(config)} \
    #{dependencies(config.dependencies).map{|d| "-d '#{d}'"}.join(" ")} \
    .
  }
end

#initializers_for(app_name, procfile_entries) ⇒ Object



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

def initializers_for(app_name, procfile_entries)
  list = []
  procfile_entries.select(&:daemon?).each do |process|
    Pkgr.debug "Adding #{process.inspect} to initialization scripts"
    # sysvinit
    list.push [process, Templates::FileTemplate.new("sysv/#{app_name}", data_file("sysv/master.erb"))]
    list.push [process, Templates::FileTemplate.new("sysv/#{app_name}-#{process.name}", data_file("sysv/process_master.erb"))]
    list.push [process, Templates::FileTemplate.new("sysv/#{app_name}-#{process.name}-PROCESS_NUM", data_file("sysv/process.erb"))]
    # upstart
    list.push [process, Templates::FileTemplate.new("upstart/#{app_name}", data_file("upstart/init.d.sh.erb"))]
    list.push [process, Templates::FileTemplate.new("upstart/#{app_name}.conf", data_file("upstart/master.conf.erb"))]
    list.push [process, Templates::FileTemplate.new("upstart/#{app_name}-#{process.name}.conf", data_file("upstart/process_master.conf.erb"))]
    list.push [process, Templates::FileTemplate.new("upstart/#{app_name}-#{process.name}-PROCESS_NUM.conf", data_file("upstart/process.conf.erb"))]
  end
  list
end

#osfamilyObject



15
16
17
# File 'lib/pkgr/distributions/debian.rb', line 15

def osfamily
  "debian"
end

#postinstall_file(config) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
# File 'lib/pkgr/distributions/debian.rb', line 134

def postinstall_file(config)
  @postinstall_file ||= begin
    source = File.join(data_dir, "hooks", "postinstall.sh")
    file = Tempfile.new("postinstall")
    file.write ERB.new(File.read(source)).result(config.sesame)
    file.rewind
    file
  end

  @postinstall_file.path
end

#preinstall_file(config) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
# File 'lib/pkgr/distributions/debian.rb', line 122

def preinstall_file(config)
  @preinstall_file ||= begin
    source = File.join(data_dir, "hooks", "preinstall.sh")
    file = Tempfile.new("preinstall")
    file.write ERB.new(File.read(source)).result(config.sesame)
    file.rewind
    file
  end

  @preinstall_file.path
end

#slugObject



19
20
21
# File 'lib/pkgr/distributions/debian.rb', line 19

def slug
  [osfamily, codename].join("-")
end

#templates(app_name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pkgr/distributions/debian.rb', line 23

def templates(app_name)
  list = []

  # directories
  [
    "usr/local/bin",
    "opt/#{app_name}",
    "etc/#{app_name}/conf.d",
    "etc/default",
    "etc/init",
    "var/log/#{app_name}"
  ].each{|dir| list.push Templates::DirTemplate.new(dir) }

  # default
  list.push Templates::FileTemplate.new("etc/default/#{app_name}", File.new(File.join(data_dir, "default.erb")))
  # executable
  list.push Templates::FileTemplate.new("usr/local/bin/#{app_name}", File.new(File.join(data_dir, "runner.erb")), mode: 0755)
  # logrotate
  list.push Templates::FileTemplate.new("etc/logrotate.d/#{app_name}", File.new(File.join(data_dir, "logrotate.erb")))

  # NOTE: 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