pkgr 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +16 -2
- data/data/build_dependencies/centos.yml +13 -0
- data/{lib/pkgr/data/distributions/debian/build_dependencies.yml → data/build_dependencies/debian.yml} +2 -2
- data/data/build_dependencies/ubuntu.yml +15 -0
- data/data/buildpacks/centos-6 +2 -0
- data/data/buildpacks/debian-6 +2 -0
- data/{lib/pkgr/data/distributions/debian/buildpacks/debian_wheezy → data/buildpacks/debian-7} +1 -1
- data/data/buildpacks/ubuntu-10.04 +2 -0
- data/{lib/pkgr/data/distributions/debian/buildpacks/ubuntu_precise → data/buildpacks/ubuntu-12.04} +1 -1
- data/{lib/pkgr/data/distributions/debian/runner.erb → data/cli/cli.sh.erb} +105 -57
- data/data/dependencies/centos.yml +9 -0
- data/{lib/pkgr/data/distributions/debian/dependencies.yml → data/dependencies/debian.yml} +2 -2
- data/data/dependencies/ubuntu.yml +21 -0
- data/data/environment/default.erb +9 -0
- data/{lib/pkgr/data/distributions/debian → data}/hooks/postinstall.sh +7 -4
- data/data/hooks/preinstall.sh +13 -0
- data/{lib/pkgr/data/distributions/debian/sysv → data/init/sysv/lsb-3.1}/master.erb +0 -0
- data/{lib/pkgr/data/distributions/debian/sysv → data/init/sysv/lsb-3.1}/process.erb +84 -11
- data/{lib/pkgr/data/distributions/debian/sysv → data/init/sysv/lsb-3.1}/process_master.erb +0 -0
- data/{lib/pkgr/data/distributions/debian/upstart → data/init/upstart/1.5}/init.d.sh.erb +0 -0
- data/{lib/pkgr/data/distributions/debian/upstart → data/init/upstart/1.5}/master.conf.erb +0 -0
- data/{lib/pkgr/data/distributions/debian/upstart → data/init/upstart/1.5}/process.conf.erb +0 -0
- data/{lib/pkgr/data/distributions/debian/upstart → data/init/upstart/1.5}/process_master.conf.erb +0 -0
- data/{lib/pkgr/data/distributions/debian → data/logrotate}/logrotate.erb +0 -0
- data/lib/pkgr.rb +1 -1
- data/lib/pkgr/builder.rb +8 -2
- data/lib/pkgr/buildpack.rb +1 -0
- data/lib/pkgr/cli.rb +12 -6
- data/lib/pkgr/config.rb +20 -2
- data/lib/pkgr/distributions.rb +9 -7
- data/lib/pkgr/distributions/base.rb +159 -0
- data/lib/pkgr/distributions/centos.rb +12 -0
- data/lib/pkgr/distributions/debian.rb +39 -163
- data/lib/pkgr/distributions/redhat.rb +51 -0
- data/lib/pkgr/distributions/runner.rb +39 -0
- data/lib/pkgr/distributions/ubuntu.rb +17 -0
- data/lib/pkgr/version.rb +1 -1
- metadata +30 -29
- data/lib/pkgr/app.rb +0 -279
- data/lib/pkgr/data/bin/executable +0 -36
- data/lib/pkgr/data/config/pre_boot.rb +0 -15
- data/lib/pkgr/data/distributions/debian/buildpacks/debian_squeeze +0 -2
- data/lib/pkgr/data/distributions/debian/buildpacks/ubuntu_lucid +0 -2
- data/lib/pkgr/data/distributions/debian/cron.d +0 -4
- data/lib/pkgr/data/distributions/debian/default.erb +0 -12
- data/lib/pkgr/data/distributions/debian/hooks/preinstall.sh +0 -9
- data/lib/pkgr/data/pkgr.yml +0 -32
- data/lib/pkgr/distributions/debian_squeeze.rb +0 -11
- data/lib/pkgr/distributions/debian_wheezy.rb +0 -11
- data/lib/pkgr/distributions/ubuntu_lucid.rb +0 -15
- data/lib/pkgr/distributions/ubuntu_precise.rb +0 -15
@@ -0,0 +1,12 @@
|
|
1
|
+
require "pkgr/distributions/redhat"
|
2
|
+
|
3
|
+
module Pkgr
|
4
|
+
module Distributions
|
5
|
+
# Contains the various components required to make a packaged app integrate well with a CentOS system.
|
6
|
+
class Centos < Redhat
|
7
|
+
def runner
|
8
|
+
@runner ||= Runner.new("upstart", "1.5")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,182 +1,58 @@
|
|
1
1
|
require 'pkgr/buildpack'
|
2
2
|
require 'pkgr/process'
|
3
|
-
require '
|
4
|
-
require 'erb'
|
3
|
+
require 'pkgr/distributions/base'
|
5
4
|
|
6
5
|
module Pkgr
|
7
6
|
module Distributions
|
8
|
-
|
9
|
-
|
10
|
-
#
|
11
|
-
def
|
12
|
-
|
7
|
+
# Contains the various components required to make a packaged app integrate well with a Debian system.
|
8
|
+
class Debian < Base
|
9
|
+
# Only keep major digits
|
10
|
+
def release
|
11
|
+
@release[/^[0-9]+/]
|
13
12
|
end
|
14
13
|
|
15
|
-
def
|
16
|
-
"
|
14
|
+
def runner
|
15
|
+
@runner ||= Runner.new("sysv", "lsb-3.1")
|
17
16
|
end
|
18
17
|
|
19
|
-
def
|
20
|
-
|
18
|
+
def package_test_command(package)
|
19
|
+
"dpkg -s '#{package}' > /dev/null 2>&1"
|
21
20
|
end
|
22
21
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
# directories
|
27
|
-
[
|
28
|
-
"usr/local/bin",
|
29
|
-
"opt/#{app_name}",
|
30
|
-
"etc/#{app_name}/conf.d",
|
31
|
-
"etc/default",
|
32
|
-
"etc/init",
|
33
|
-
"var/log/#{app_name}"
|
34
|
-
].each{|dir| list.push Templates::DirTemplate.new(dir) }
|
35
|
-
|
36
|
-
# default
|
37
|
-
list.push Templates::FileTemplate.new("etc/default/#{app_name}", File.new(File.join(data_dir, "default.erb")))
|
38
|
-
# executable
|
39
|
-
list.push Templates::FileTemplate.new("usr/local/bin/#{app_name}", File.new(File.join(data_dir, "runner.erb")), mode: 0755)
|
40
|
-
# logrotate
|
41
|
-
list.push Templates::FileTemplate.new("etc/logrotate.d/#{app_name}", File.new(File.join(data_dir, "logrotate.erb")))
|
42
|
-
|
43
|
-
# NOTE: conf.d files are no longer installed here, since we don't want to overwrite any pre-existing config.
|
44
|
-
# They're now installed in the postinstall script.
|
45
|
-
|
46
|
-
list
|
47
|
-
end
|
48
|
-
|
49
|
-
def initializers_for(app_name, procfile_entries)
|
50
|
-
list = []
|
51
|
-
procfile_entries.select(&:daemon?).each do |process|
|
52
|
-
Pkgr.debug "Adding #{process.inspect} to initialization scripts"
|
53
|
-
# sysvinit
|
54
|
-
list.push [process, Templates::FileTemplate.new("sysv/#{app_name}", data_file("sysv/master.erb"))]
|
55
|
-
list.push [process, Templates::FileTemplate.new("sysv/#{app_name}-#{process.name}", data_file("sysv/process_master.erb"))]
|
56
|
-
list.push [process, Templates::FileTemplate.new("sysv/#{app_name}-#{process.name}-PROCESS_NUM", data_file("sysv/process.erb"))]
|
57
|
-
# upstart
|
58
|
-
list.push [process, Templates::FileTemplate.new("upstart/#{app_name}", data_file("upstart/init.d.sh.erb"))]
|
59
|
-
list.push [process, Templates::FileTemplate.new("upstart/#{app_name}.conf", data_file("upstart/master.conf.erb"))]
|
60
|
-
list.push [process, Templates::FileTemplate.new("upstart/#{app_name}-#{process.name}.conf", data_file("upstart/process_master.conf.erb"))]
|
61
|
-
list.push [process, Templates::FileTemplate.new("upstart/#{app_name}-#{process.name}-PROCESS_NUM.conf", data_file("upstart/process.conf.erb"))]
|
62
|
-
end
|
63
|
-
list
|
64
|
-
end
|
65
|
-
|
66
|
-
def check(config)
|
67
|
-
missing_packages = (build_dependencies(config.build_dependencies) || []).select do |package|
|
68
|
-
test_command = "dpkg -s '#{package}' > /dev/null 2>&1"
|
69
|
-
Pkgr.debug "sh(#{test_command})"
|
70
|
-
! system(test_command)
|
71
|
-
end
|
72
|
-
|
73
|
-
unless missing_packages.empty?
|
74
|
-
package_install_command = "sudo apt-get update && sudo apt-get install --force-yes -y #{missing_packages.map{|package| "\"#{package}\""}.join(" ")}"
|
75
|
-
if config.auto
|
76
|
-
package_install = Mixlib::ShellOut.new(package_install_command)
|
77
|
-
package_install.logger = Pkgr.logger
|
78
|
-
package_install.run_command
|
79
|
-
package_install.error!
|
80
|
-
else
|
81
|
-
Pkgr.warn("Missing build dependencies detected. Run the following to fix: #{package_install_command}")
|
82
|
-
end
|
83
|
-
end
|
22
|
+
def package_install_command(packages)
|
23
|
+
"sudo apt-get update && sudo apt-get install --force-yes -y #{packages.map{|package| "\"#{package}\""}.join(" ")}"
|
84
24
|
end
|
85
25
|
|
86
26
|
def fpm_command(build_dir, config)
|
87
|
-
%{
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
}
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
else
|
114
|
-
load_buildpack_list(config)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def default_buildpack_list
|
119
|
-
data_file(File.join("buildpacks", "#{osfamily}_#{codename}"))
|
120
|
-
end
|
121
|
-
|
122
|
-
def preinstall_file(config)
|
123
|
-
@preinstall_file ||= begin
|
124
|
-
source = File.join(data_dir, "hooks", "preinstall.sh")
|
125
|
-
file = Tempfile.new("preinstall")
|
126
|
-
file.write ERB.new(File.read(source)).result(config.sesame)
|
127
|
-
file.rewind
|
128
|
-
file
|
129
|
-
end
|
130
|
-
|
131
|
-
@preinstall_file.path
|
132
|
-
end
|
133
|
-
|
134
|
-
def postinstall_file(config)
|
135
|
-
@postinstall_file ||= begin
|
136
|
-
source = File.join(data_dir, "hooks", "postinstall.sh")
|
137
|
-
file = Tempfile.new("postinstall")
|
138
|
-
file.write ERB.new(File.read(source)).result(config.sesame)
|
139
|
-
file.rewind
|
140
|
-
file
|
141
|
-
end
|
142
|
-
|
143
|
-
@postinstall_file.path
|
144
|
-
end
|
145
|
-
|
146
|
-
def dependencies(other_dependencies = nil)
|
147
|
-
deps = YAML.load_file(File.join(data_dir, "dependencies.yml"))
|
148
|
-
(deps["default"] || []) | (deps[codename] || []) | (other_dependencies || [])
|
149
|
-
end
|
150
|
-
|
151
|
-
def build_dependencies(other_dependencies = nil)
|
152
|
-
deps = YAML.load_file(File.join(data_dir, "build_dependencies.yml"))
|
153
|
-
(deps["default"] || []) | (deps[codename] || []) | (other_dependencies || [])
|
154
|
-
end
|
155
|
-
|
156
|
-
def data_file(name)
|
157
|
-
File.new(File.join(data_dir, name))
|
158
|
-
end
|
159
|
-
|
160
|
-
def data_dir
|
161
|
-
File.join(Pkgr.data_dir, "distributions", "debian")
|
162
|
-
end
|
163
|
-
|
164
|
-
protected
|
165
|
-
|
166
|
-
def load_buildpack_list(config)
|
167
|
-
file = config.buildpack_list || default_buildpack_list
|
168
|
-
return [] if file.nil?
|
169
|
-
|
170
|
-
File.read(file).split("\n").map do |line|
|
171
|
-
url, *raw_env = line.split(",")
|
172
|
-
buildpack_env = (config.env || Env.new).merge(Env.new(raw_env))
|
173
|
-
Buildpack.new(url, :builtin, buildpack_env)
|
174
|
-
end
|
27
|
+
%{fpm #{fpm_args(build_dir, config).join(" ")} .}
|
28
|
+
end
|
29
|
+
|
30
|
+
def fpm_args(build_dir, config)
|
31
|
+
args = []
|
32
|
+
args << "-t deb"
|
33
|
+
args << "-s dir"
|
34
|
+
args << "--verbose"
|
35
|
+
args << "--force"
|
36
|
+
args << %{-C "#{build_dir}"}
|
37
|
+
args << %{-n "#{config.name}"}
|
38
|
+
args << %{--version "#{config.version}"}
|
39
|
+
args << %{--iteration "#{config.iteration}"}
|
40
|
+
args << %{--url "#{config.homepage}"}
|
41
|
+
args << %{--provides "#{config.name}"}
|
42
|
+
args << %{--deb-user "root"}
|
43
|
+
args << %{--deb-group "root"}
|
44
|
+
args << %{--license "#{config.license}"} unless config.license.nil?
|
45
|
+
args << %{-a "#{config.architecture}"}
|
46
|
+
args << %{--description "#{config.description}"}
|
47
|
+
args << %{--maintainer "#{config.maintainer}"}
|
48
|
+
args << %{--template-scripts}
|
49
|
+
args << %{--before-install #{preinstall_file(config)}}
|
50
|
+
args << %{--after-install #{postinstall_file(config)}}
|
51
|
+
dependencies(config.dependencies).each{|d| args << "-d '#{d}'"}
|
52
|
+
args
|
175
53
|
end
|
176
54
|
end
|
177
55
|
end
|
178
56
|
end
|
179
57
|
|
180
|
-
|
181
|
-
require "pkgr/distributions/#{distro}"
|
182
|
-
end
|
58
|
+
require 'pkgr/distributions/ubuntu'
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'pkgr/buildpack'
|
2
|
+
require 'pkgr/process'
|
3
|
+
require 'pkgr/distributions/base'
|
4
|
+
|
5
|
+
module Pkgr
|
6
|
+
module Distributions
|
7
|
+
# Contains the various components required to make a packaged app integrate well with a Debian system.
|
8
|
+
class Redhat < Base
|
9
|
+
# Only keep major adigits
|
10
|
+
def release
|
11
|
+
@release[/^[0-9]+/]
|
12
|
+
end
|
13
|
+
|
14
|
+
def runner
|
15
|
+
@runner ||= Runner.new("sysv", "lsb-3.1")
|
16
|
+
end
|
17
|
+
|
18
|
+
def package_test_command(package)
|
19
|
+
"rpm -qa '#{package}' | grep '#{package}' > /dev/null 2>&1"
|
20
|
+
end
|
21
|
+
|
22
|
+
def package_install_command(packages)
|
23
|
+
"sudo yum check-update && sudo yum install -y #{packages.map{|package| "\"#{package}\""}.join(" ")}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def fpm_command(build_dir, config)
|
27
|
+
%{
|
28
|
+
fpm -t rpm -s dir --verbose --force \
|
29
|
+
-C "#{build_dir}" \
|
30
|
+
-n "#{config.name}" \
|
31
|
+
--version "#{config.version}" \
|
32
|
+
--iteration "#{config.iteration}" \
|
33
|
+
--url "#{config.homepage}" \
|
34
|
+
--provides "#{config.name}" \
|
35
|
+
--deb-user "root" \
|
36
|
+
--deb-group "root" \
|
37
|
+
-a "#{config.architecture}" \
|
38
|
+
--description "#{config.description}" \
|
39
|
+
--maintainer "#{config.maintainer}" \
|
40
|
+
--template-scripts \
|
41
|
+
--before-install #{preinstall_file(config)} \
|
42
|
+
--after-install #{postinstall_file(config)} \
|
43
|
+
#{dependencies(config.dependencies).map{|d| "-d '#{d}'"}.join(" ")} \
|
44
|
+
.
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
require 'pkgr/distributions/centos'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Pkgr
|
2
|
+
module Distributions
|
3
|
+
class Runner < Struct.new(:type, :version)
|
4
|
+
def sysv?
|
5
|
+
type == "sysv"
|
6
|
+
end
|
7
|
+
|
8
|
+
def upstart?
|
9
|
+
type == "upstart"
|
10
|
+
end
|
11
|
+
|
12
|
+
def templates(process, app_name)
|
13
|
+
send("templates_#{type}", process, app_name)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def templates_sysv(process, app_name)
|
18
|
+
[
|
19
|
+
Templates::FileTemplate.new("sysv/#{app_name}", data_file("master.erb")),
|
20
|
+
Templates::FileTemplate.new("sysv/#{app_name}-#{process.name}", data_file("process_master.erb")),
|
21
|
+
Templates::FileTemplate.new("sysv/#{app_name}-#{process.name}-PROCESS_NUM", data_file("process.erb")),
|
22
|
+
]
|
23
|
+
end
|
24
|
+
|
25
|
+
def templates_upstart(process, app_name)
|
26
|
+
[
|
27
|
+
Templates::FileTemplate.new("upstart/#{app_name}", data_file("init.d.sh.erb")),
|
28
|
+
Templates::FileTemplate.new("upstart/#{app_name}.conf", data_file("master.conf.erb")),
|
29
|
+
Templates::FileTemplate.new("upstart/#{app_name}-#{process.name}.conf", data_file("process_master.conf.erb")),
|
30
|
+
Templates::FileTemplate.new("upstart/#{app_name}-#{process.name}-PROCESS_NUM.conf", data_file("process.conf.erb"))
|
31
|
+
]
|
32
|
+
end
|
33
|
+
|
34
|
+
def data_file(name)
|
35
|
+
File.new(File.join(Pkgr.data_dir, "init", type, version, name))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "pkgr/distributions/debian"
|
2
|
+
|
3
|
+
module Pkgr
|
4
|
+
module Distributions
|
5
|
+
# Contains the various components required to make a packaged app integrate well with a Ubuntu system.
|
6
|
+
class Ubuntu < Debian
|
7
|
+
# Keep everything
|
8
|
+
def release
|
9
|
+
@release
|
10
|
+
end
|
11
|
+
|
12
|
+
def runner
|
13
|
+
@runner ||= Runner.new("upstart", "1.5")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/pkgr/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pkgr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-05-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -135,39 +135,17 @@ extra_rdoc_files:
|
|
135
135
|
- LICENSE
|
136
136
|
- README.md
|
137
137
|
files:
|
138
|
-
- lib/pkgr/app.rb
|
139
138
|
- lib/pkgr/builder.rb
|
140
139
|
- lib/pkgr/buildpack.rb
|
141
140
|
- lib/pkgr/cli.rb
|
142
141
|
- lib/pkgr/config.rb
|
143
|
-
- lib/pkgr/data/bin/executable
|
144
|
-
- lib/pkgr/data/config/pre_boot.rb
|
145
|
-
- lib/pkgr/data/distributions/debian/build_dependencies.yml
|
146
|
-
- lib/pkgr/data/distributions/debian/buildpacks/debian_squeeze
|
147
|
-
- lib/pkgr/data/distributions/debian/buildpacks/debian_wheezy
|
148
|
-
- lib/pkgr/data/distributions/debian/buildpacks/ubuntu_lucid
|
149
|
-
- lib/pkgr/data/distributions/debian/buildpacks/ubuntu_precise
|
150
|
-
- lib/pkgr/data/distributions/debian/cron.d
|
151
|
-
- lib/pkgr/data/distributions/debian/default.erb
|
152
|
-
- lib/pkgr/data/distributions/debian/dependencies.yml
|
153
|
-
- lib/pkgr/data/distributions/debian/hooks/postinstall.sh
|
154
|
-
- lib/pkgr/data/distributions/debian/hooks/preinstall.sh
|
155
|
-
- lib/pkgr/data/distributions/debian/logrotate.erb
|
156
|
-
- lib/pkgr/data/distributions/debian/runner.erb
|
157
|
-
- lib/pkgr/data/distributions/debian/sysv/master.erb
|
158
|
-
- lib/pkgr/data/distributions/debian/sysv/process.erb
|
159
|
-
- lib/pkgr/data/distributions/debian/sysv/process_master.erb
|
160
|
-
- lib/pkgr/data/distributions/debian/upstart/init.d.sh.erb
|
161
|
-
- lib/pkgr/data/distributions/debian/upstart/master.conf.erb
|
162
|
-
- lib/pkgr/data/distributions/debian/upstart/process.conf.erb
|
163
|
-
- lib/pkgr/data/distributions/debian/upstart/process_master.conf.erb
|
164
|
-
- lib/pkgr/data/pkgr.yml
|
165
142
|
- lib/pkgr/dispatcher.rb
|
143
|
+
- lib/pkgr/distributions/base.rb
|
144
|
+
- lib/pkgr/distributions/centos.rb
|
166
145
|
- lib/pkgr/distributions/debian.rb
|
167
|
-
- lib/pkgr/distributions/
|
168
|
-
- lib/pkgr/distributions/
|
169
|
-
- lib/pkgr/distributions/
|
170
|
-
- lib/pkgr/distributions/ubuntu_precise.rb
|
146
|
+
- lib/pkgr/distributions/redhat.rb
|
147
|
+
- lib/pkgr/distributions/runner.rb
|
148
|
+
- lib/pkgr/distributions/ubuntu.rb
|
171
149
|
- lib/pkgr/distributions.rb
|
172
150
|
- lib/pkgr/env.rb
|
173
151
|
- lib/pkgr/git.rb
|
@@ -176,6 +154,29 @@ files:
|
|
176
154
|
- lib/pkgr/templates/file_template.rb
|
177
155
|
- lib/pkgr/version.rb
|
178
156
|
- lib/pkgr.rb
|
157
|
+
- data/build_dependencies/centos.yml
|
158
|
+
- data/build_dependencies/debian.yml
|
159
|
+
- data/build_dependencies/ubuntu.yml
|
160
|
+
- data/buildpacks/centos-6
|
161
|
+
- data/buildpacks/debian-6
|
162
|
+
- data/buildpacks/debian-7
|
163
|
+
- data/buildpacks/ubuntu-10.04
|
164
|
+
- data/buildpacks/ubuntu-12.04
|
165
|
+
- data/cli/cli.sh.erb
|
166
|
+
- data/dependencies/centos.yml
|
167
|
+
- data/dependencies/debian.yml
|
168
|
+
- data/dependencies/ubuntu.yml
|
169
|
+
- data/environment/default.erb
|
170
|
+
- data/hooks/postinstall.sh
|
171
|
+
- data/hooks/preinstall.sh
|
172
|
+
- data/init/sysv/lsb-3.1/master.erb
|
173
|
+
- data/init/sysv/lsb-3.1/process.erb
|
174
|
+
- data/init/sysv/lsb-3.1/process_master.erb
|
175
|
+
- data/init/upstart/1.5/init.d.sh.erb
|
176
|
+
- data/init/upstart/1.5/master.conf.erb
|
177
|
+
- data/init/upstart/1.5/process.conf.erb
|
178
|
+
- data/init/upstart/1.5/process_master.conf.erb
|
179
|
+
- data/logrotate/logrotate.erb
|
179
180
|
- LICENSE
|
180
181
|
- README.md
|
181
182
|
- bin/pkgr
|
data/lib/pkgr/app.rb
DELETED
@@ -1,279 +0,0 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'erb'
|
3
|
-
require 'pkgr/version'
|
4
|
-
require 'yaml'
|
5
|
-
|
6
|
-
module Pkgr
|
7
|
-
class App
|
8
|
-
include RakeFileUtils
|
9
|
-
attr_reader :root
|
10
|
-
attr_reader :errors
|
11
|
-
attr_reader :config
|
12
|
-
|
13
|
-
# +root+: the root directory of the app.
|
14
|
-
# +config+ a Configuration object, hosting the parameters defined in `config/pkgr.yml`.
|
15
|
-
def initialize(root, config_path)
|
16
|
-
@root = root
|
17
|
-
load_config(config_path)
|
18
|
-
@errors = []
|
19
|
-
end
|
20
|
-
|
21
|
-
def load_config(path)
|
22
|
-
@config = YAML::load_file(path)
|
23
|
-
raise ArgumentError, "The given configuration file at '#{path}' is not a well-formed YAML file. Please fix it or remove it and run 'rake pkgr:setup'" unless @config.kind_of?(Hash)
|
24
|
-
@config['_path'] = path
|
25
|
-
normalize_name!
|
26
|
-
end
|
27
|
-
|
28
|
-
def write_config
|
29
|
-
File.open(@config['_path'] || raise("Don't know where to save myself!"), "w+") {|f|
|
30
|
-
YAML.dump(@config.reject{|k,v| k == '_path'}, f)
|
31
|
-
}
|
32
|
-
end
|
33
|
-
|
34
|
-
# Returns true if the app is correctly configured. Else otherwise.
|
35
|
-
def valid?
|
36
|
-
@errors.clear
|
37
|
-
@errors.push("is not a valid git repository") unless File.exist?(File.join(@root, ".git", "HEAD"))
|
38
|
-
@errors.push("must have a name") unless @config.fetch('name')
|
39
|
-
@errors.push("must have a valid name ([a-zA-Z0-9_-])") unless @config.fetch('name').scan(/[^a-z0-9\_\-]/i)
|
40
|
-
@errors.push("must have a version") unless @config.fetch('version')
|
41
|
-
@errors.push("must have a valid target architecture") unless @config.fetch('architecture')
|
42
|
-
@errors.empty?
|
43
|
-
end
|
44
|
-
|
45
|
-
def generate_required_files
|
46
|
-
setup_debian
|
47
|
-
setup_binary
|
48
|
-
end
|
49
|
-
|
50
|
-
def git_ref
|
51
|
-
@config.fetch('git_ref') { 'HEAD' }
|
52
|
-
end
|
53
|
-
|
54
|
-
def prefix
|
55
|
-
@config.fetch('prefix') { "/opt/local" }
|
56
|
-
end
|
57
|
-
|
58
|
-
def author_name
|
59
|
-
@author_name ||= `git config --get user.name`.chomp
|
60
|
-
end
|
61
|
-
|
62
|
-
def author_email
|
63
|
-
@author_email ||= `git config --get user.email`.chomp
|
64
|
-
end
|
65
|
-
|
66
|
-
def name
|
67
|
-
@config['name']
|
68
|
-
end
|
69
|
-
|
70
|
-
def description
|
71
|
-
@config['description'] || ""
|
72
|
-
end
|
73
|
-
|
74
|
-
def debian_build_dependencies(installable_only = false)
|
75
|
-
deps = @config['debian_build_dependencies'] || []
|
76
|
-
if installable_only
|
77
|
-
deps = deps.reject{|d| d =~ /[\$\{\}]/}.map{|d| d.split(/\s/)[0]}
|
78
|
-
end
|
79
|
-
deps
|
80
|
-
end
|
81
|
-
|
82
|
-
def debian_runtime_dependencies(installable_only = false)
|
83
|
-
deps = @config['debian_runtime_dependencies'] || []
|
84
|
-
if installable_only
|
85
|
-
deps = deps.reject{|d| d =~ /[\$\{\}]/}.map{|d| d.split(/\s/)[0]}
|
86
|
-
end
|
87
|
-
deps
|
88
|
-
end
|
89
|
-
|
90
|
-
def architecture
|
91
|
-
@config['architecture'] || "all"
|
92
|
-
end
|
93
|
-
|
94
|
-
def homepage
|
95
|
-
@config['homepage'] || ""
|
96
|
-
end
|
97
|
-
|
98
|
-
def config_files
|
99
|
-
@config['config_files'] || []
|
100
|
-
end
|
101
|
-
|
102
|
-
def version
|
103
|
-
@config['version']
|
104
|
-
end
|
105
|
-
|
106
|
-
def user
|
107
|
-
@config.fetch('user') { name }
|
108
|
-
end
|
109
|
-
|
110
|
-
def group
|
111
|
-
@config.fetch('group') { name }
|
112
|
-
end
|
113
|
-
|
114
|
-
# prefix without the leading slash.
|
115
|
-
def pkg_prefix
|
116
|
-
prefix[1..-1]
|
117
|
-
end
|
118
|
-
|
119
|
-
def setup_debian
|
120
|
-
target = File.join(root, Pkgr::DEBIAN_DIR)
|
121
|
-
Pkgr.mkdir(target)
|
122
|
-
|
123
|
-
Dir[File.expand_path("../data/debian/*", __FILE__)].each do |file|
|
124
|
-
case File.extname(file)
|
125
|
-
when ".erb"
|
126
|
-
file_target = File.join(target, File.basename(file, ".erb"))
|
127
|
-
File.open(file_target, "w+") do |f|
|
128
|
-
f << ERB.new(File.read(file)).result(binding)
|
129
|
-
end
|
130
|
-
else
|
131
|
-
file_target = File.join(target, File.basename(file))
|
132
|
-
if File.exist?(file_target)
|
133
|
-
puts "File #{file_target} already exists. Skipped."
|
134
|
-
else
|
135
|
-
FileUtils.cp(file, file_target, :verbose => true)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
puts "Correctly set up debian files."
|
141
|
-
end
|
142
|
-
|
143
|
-
# Creates an executable file for easy launch of the server/console/rake tasks once it is installed.
|
144
|
-
# E.g. /usr/bin/my-app console, /usr/bin/my-app server start -p 8080
|
145
|
-
def setup_binary
|
146
|
-
target = File.join(root, "bin", name)
|
147
|
-
Pkgr.mkdir(File.dirname(target))
|
148
|
-
FileUtils.cp(File.expand_path("../data/bin/executable", __FILE__), target, :verbose => true)
|
149
|
-
FileUtils.chmod 0755, target, :verbose => true
|
150
|
-
puts "Correctly set up executable file. Try running './bin/#{name} console'."
|
151
|
-
end
|
152
|
-
|
153
|
-
# FIXME: this is ugly
|
154
|
-
def bump!(version_index = :patch, new_version = nil)
|
155
|
-
unless version_index == :custom
|
156
|
-
indices = [:major, :minor, :patch]
|
157
|
-
index = indices.index(version_index) || raise(ArgumentError, "The given version index is not valid (#{version_index})")
|
158
|
-
fragments = version.split(".")
|
159
|
-
fragments[index] = fragments[index].to_i+1
|
160
|
-
((index+1)..2).each{|i|
|
161
|
-
fragments[i] = 0
|
162
|
-
}
|
163
|
-
new_version = fragments.join(".")
|
164
|
-
else
|
165
|
-
raise ArgumentError, "new_version must not be nil when bumping with a :custom version" if new_version.nil?
|
166
|
-
end
|
167
|
-
|
168
|
-
changelog = File.read(debian_file("changelog"))
|
169
|
-
dist = (changelog.scan(/#{name} \(#{new_version}-(\d+)\)/).flatten[0].to_i)
|
170
|
-
dist += 1 if new_version == version
|
171
|
-
dist = 1 if dist == 0
|
172
|
-
|
173
|
-
last_commit = changelog.scan(/\s+\* ([a-z0-9]{7}) /).flatten[0]
|
174
|
-
|
175
|
-
cmd = "git log --oneline"
|
176
|
-
cmd << " #{last_commit}..#{git_ref}" unless last_commit.nil?
|
177
|
-
result = %x{#{cmd}}
|
178
|
-
ok = $?.exitstatus == 0
|
179
|
-
if !ok
|
180
|
-
raise "Command failed. Aborting."
|
181
|
-
else
|
182
|
-
content_changelog = [
|
183
|
-
"#{name} (#{new_version}-#{dist}) unstable; urgency=low",
|
184
|
-
"",
|
185
|
-
result.split("\n").reject{|l| l =~ / v#{version}/}.map{|l| " * #{l}"}.join("\n"),
|
186
|
-
"",
|
187
|
-
" -- #{author_name} <#{author_email}> #{Time.now.strftime("%a, %d %b %Y %H:%M:%S %z")}",
|
188
|
-
"",
|
189
|
-
changelog
|
190
|
-
].join("\n")
|
191
|
-
|
192
|
-
File.open(debian_file("changelog"), "w+") do |f|
|
193
|
-
f << content_changelog
|
194
|
-
end
|
195
|
-
|
196
|
-
@config['version'] = new_version
|
197
|
-
write_config
|
198
|
-
|
199
|
-
puts "Committing changelog and version file..."
|
200
|
-
files_to_commit = [debian_file('changelog'), @config['_path']]
|
201
|
-
sh "git add #{files_to_commit.join(" ")} && git commit -m '[pkgr] v#{new_version}-#{dist}' #{files_to_commit.join(" ")}"
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
def build_debian_package(host)
|
206
|
-
puts "Building debian package on '#{host}'..."
|
207
|
-
Dir.chdir(root) do
|
208
|
-
Pkgr.mkdir("pkg")
|
209
|
-
archive = "#{name}-#{version}"
|
210
|
-
sh "scp #{File.expand_path("../data/config/pre_boot.rb", __FILE__)} #{host}:/tmp/"
|
211
|
-
cmd = %Q{
|
212
|
-
git archive #{git_ref} --prefix=#{archive}/ | ssh #{host} 'cat - > /tmp/#{archive}.tar &&
|
213
|
-
set -x && rm -rf /tmp/#{archive} &&
|
214
|
-
cd /tmp && tar xf #{archive}.tar && cd #{archive} &&
|
215
|
-
cat config/boot.rb >> /tmp/pre_boot.rb && cp -f /tmp/pre_boot.rb config/boot.rb &&
|
216
|
-
#{debian_steps.join(" &&\n")}'
|
217
|
-
}
|
218
|
-
sh cmd
|
219
|
-
# Fetch all package files, and put it in the `pkg` directory
|
220
|
-
sh "scp #{host}:/tmp/#{name}_#{version}* pkg/"
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
def debian_steps
|
225
|
-
target_vendor = "vendor/bundle/ruby/1.9.1"
|
226
|
-
[
|
227
|
-
# "sudo apt-get install #{debian_runtime_dependencies(true).join(" ")} -y",
|
228
|
-
"sudo apt-get install #{debian_build_dependencies(true).join(" ")} -y",
|
229
|
-
# Vendor bundler
|
230
|
-
"gem1.9.1 install bundler --no-ri --no-rdoc --version #{bundler_version} -i #{target_vendor}",
|
231
|
-
"GEM_HOME='#{target_vendor}' #{target_vendor}/bin/bundle install --deployment --without test development",
|
232
|
-
"rm -rf #{target_vendor}/{cache,doc}",
|
233
|
-
"dpkg-buildpackage -us -uc -d"
|
234
|
-
]
|
235
|
-
end
|
236
|
-
|
237
|
-
def release_debian_package(host, apt_directory = nil)
|
238
|
-
apt_directory ||= "/var/www/#{name}"
|
239
|
-
latest = Dir[File.join(root, "pkg", "*.deb")].find{|file| file =~ /#{version}/}
|
240
|
-
raise "No .deb available in pkg/" if latest.nil?
|
241
|
-
latest_name = File.basename(latest)
|
242
|
-
sh "scp #{latest} #{host}:/tmp/"
|
243
|
-
sh "ssh #{host} 'sudo mkdir -p #{apt_directory} && sudo chown $USER #{apt_directory} && mv /tmp/#{latest_name} #{apt_directory} && cd #{apt_directory} && ( which dpkg-scanpackages || sudo apt-get update && sudo apt-get install dpkg-dev -y ) && dpkg-scanpackages . | gzip -f9 > Packages.gz'"
|
244
|
-
puts "****"
|
245
|
-
puts "Now you just need to serve the '#{apt_directory}' directory over HTTP, and add a new source to your APT configuration on the production server:"
|
246
|
-
puts "$ cat /etc/apt/sources.list.d/#{name}.list"
|
247
|
-
puts "deb http://apt-server.ltd/#{name} /"
|
248
|
-
puts
|
249
|
-
puts "And then:"
|
250
|
-
puts "$ sudo apt-get update && sudo apt-get install #{name}"
|
251
|
-
puts "****"
|
252
|
-
end
|
253
|
-
|
254
|
-
private
|
255
|
-
def bundler_version
|
256
|
-
@config.fetch('bundler_version') { '1.3.5' }
|
257
|
-
end
|
258
|
-
|
259
|
-
def debian_file(filename)
|
260
|
-
file = File.join(root, Pkgr::DEBIAN_DIR, filename)
|
261
|
-
raise "The debian/changelog file does not exist. Please generate it first." unless File.exist?(file)
|
262
|
-
file
|
263
|
-
end
|
264
|
-
|
265
|
-
def normalize_name!
|
266
|
-
# debian packages can not contain capitalized letters nor underscores
|
267
|
-
if (raw_name = @config.fetch('name', '')) =~ /[A-Z_-]/
|
268
|
-
normalized_name = raw_name.
|
269
|
-
gsub(/[A-Z]/) { |m| "_#{m.downcase}" }. # underscore each word
|
270
|
-
gsub(/[_-]+/, '-'). # normalize underscores/dashes
|
271
|
-
sub(/^-/, '') # strip leading dash
|
272
|
-
puts "Normalized application name to %s (original: %s)." % [
|
273
|
-
normalized_name.inspect, raw_name.inspect
|
274
|
-
] unless normalized_name == raw_name
|
275
|
-
@config['name'] = normalized_name
|
276
|
-
end
|
277
|
-
end
|
278
|
-
end
|
279
|
-
end
|