Class: Pkgr::Distributions::Debian

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ Debian

Returns a new instance of Debian.



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

def initialize(version)
  @version = version
end

Instance Attribute Details

#versionObject (readonly)

Returns the value of attribute version.



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

def version
  @version
end

Instance Method Details

#build_dependencies(other_dependencies = nil) ⇒ Object



149
150
151
152
# File 'lib/pkgr/distributions/debian.rb', line 149

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

#buildpacks(custom_buildpack_uri = nil) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/pkgr/distributions/debian.rb', line 94

def buildpacks(custom_buildpack_uri = nil)
  if custom_buildpack_uri
    uuid = Digest::SHA1.hexdigest(custom_buildpack_uri)
    [Buildpack.new(custom_buildpack_uri, :custom)]
  else
    case version
    when "ubuntu-precise", "debian-wheezy", "ubuntu-lucid", "debian-squeeze"
      %w{
        https://github.com/heroku/heroku-buildpack-ruby.git
        https://github.com/heroku/heroku-buildpack-nodejs.git
        https://github.com/heroku/heroku-buildpack-java.git
        https://github.com/heroku/heroku-buildpack-play.git
        https://github.com/heroku/heroku-buildpack-python.git
        https://github.com/heroku/heroku-buildpack-php.git
        https://github.com/heroku/heroku-buildpack-clojure.git
        https://github.com/kr/heroku-buildpack-go.git
        https://github.com/miyagawa/heroku-buildpack-perl.git
        https://github.com/heroku/heroku-buildpack-scala
        https://github.com/igrigorik/heroku-buildpack-dart.git
        https://github.com/rhy-jot/buildpack-nginx.git
        https://github.com/Kloadut/heroku-buildpack-static-apache.git
      }.map{|url| Buildpack.new(url)}
    end
  end
end

#check(config) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/pkgr/distributions/debian.rb', line 53

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

  unless missing_packages.empty?
    package_install_command = "sudo apt-get install -y #{missing_packages.map{|package| "\"#{package}\""}.join(" ")}"
    if config.auto
      Pkgr.debug "Running command: #{package_install_command}"
      package_install = Mixlib::ShellOut.new(package_install_command)
      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

#data_dirObject



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

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

#data_file(name) ⇒ Object



154
155
156
# File 'lib/pkgr/distributions/debian.rb', line 154

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

#dependencies(other_dependencies = nil) ⇒ Object



144
145
146
147
# File 'lib/pkgr/distributions/debian.rb', line 144

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

#fpm_command(build_dir, config) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/pkgr/distributions/debian.rb', line 73

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}" \
    --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



43
44
45
46
47
48
49
50
51
# File 'lib/pkgr/distributions/debian.rb', line 43

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

#postinstall_file(config) ⇒ Object



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

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



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

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

#templates(app_name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pkgr/distributions/debian.rb', line 15

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")))
  # upstart master
  list.push Templates::FileTemplate.new("etc/init/#{app_name}.conf", data_file("upstart/master.conf.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