pkgr 1.5.1 → 1.6.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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +2 -2
  3. data/README.md +20 -9
  4. data/data/build_dependencies/debian.yml +12 -2
  5. data/data/buildpacks/amazon-2014 +2 -2
  6. data/data/buildpacks/amazon-2015 +2 -2
  7. data/data/buildpacks/centos-6 +2 -2
  8. data/data/buildpacks/centos-7 +2 -2
  9. data/data/buildpacks/debian-6 +1 -1
  10. data/data/buildpacks/debian-7 +2 -2
  11. data/data/buildpacks/debian-8 +2 -2
  12. data/data/buildpacks/debian-9 +4 -0
  13. data/data/buildpacks/fedora-20 +2 -2
  14. data/data/buildpacks/sles-11 +2 -2
  15. data/data/buildpacks/sles-12 +2 -2
  16. data/data/buildpacks/ubuntu-10.04 +1 -1
  17. data/data/buildpacks/ubuntu-12.04 +2 -2
  18. data/data/buildpacks/ubuntu-14.04 +2 -2
  19. data/data/buildpacks/ubuntu-16.04 +2 -2
  20. data/data/cli/cli.sh.erb +176 -57
  21. data/data/dependencies/debian.yml +15 -4
  22. data/data/dependencies/sles.yml +1 -1
  23. data/data/hooks/postinstall.sh +2 -1
  24. data/data/hooks/postuninstall.sh +1 -1
  25. data/data/hooks/preinstall.sh +1 -1
  26. data/data/hooks/preuninstall.sh +1 -1
  27. data/data/init/systemd/default/process.service.erb +1 -1
  28. data/data/init/sysv/lsb-3.1/process.erb +3 -4
  29. data/data/init/upstart/1.5/process.conf.erb +1 -1
  30. data/lib/pkgr/builder.rb +31 -22
  31. data/lib/pkgr/buildpack.rb +17 -5
  32. data/lib/pkgr/cli.rb +7 -3
  33. data/lib/pkgr/config.rb +10 -0
  34. data/lib/pkgr/distributions/amazon.rb +38 -1
  35. data/lib/pkgr/distributions/base.rb +9 -9
  36. data/lib/pkgr/distributions/debian.rb +1 -1
  37. data/lib/pkgr/distributions/redhat.rb +0 -2
  38. data/lib/pkgr/env.rb +10 -4
  39. data/lib/pkgr/env_value.rb +55 -0
  40. data/lib/pkgr/version.rb +1 -1
  41. metadata +10 -9
@@ -5,23 +5,34 @@ default:
5
5
  - openssl
6
6
  - libxml2
7
7
  - libxslt1.1
8
- - libreadline5
9
- - libreadline6
10
8
  debian-6:
11
9
  - libssl0.9.8
12
10
  - libmysqlclient16
13
11
  - libevent-1.4-2
14
12
  - libevent-core-1.4-2
15
13
  - libevent-extra-1.4-2
14
+ - libreadline5
15
+ - libreadline6
16
16
  debian-7:
17
17
  - libssl1.0.0
18
18
  - libmysqlclient18
19
19
  - libevent-2.0-5
20
20
  - libevent-core-2.0-5
21
21
  - libevent-extra-2.0-5
22
- ubuntu-16.04:
22
+ - libreadline5
23
+ - libreadline6
24
+ debian-8:
23
25
  - libssl1.0.0
24
- - libmysqlclient20
26
+ - libmysqlclient18
27
+ - libevent-2.0-5
28
+ - libevent-core-2.0-5
29
+ - libevent-extra-2.0-5
30
+ - libreadline5
31
+ - libreadline6
32
+ debian-9:
33
+ - libssl1.0.2
34
+ - libmariadbclient18
25
35
  - libevent-2.0-5
26
36
  - libevent-core-2.0-5
27
37
  - libevent-extra-2.0-5
38
+ - libreadline7
@@ -12,4 +12,4 @@ sles-11:
12
12
  - postgresql
13
13
  sles-12:
14
14
  - libmysqlclient18
15
- - postgresql93
15
+ - postgresql
@@ -13,6 +13,7 @@ LOGS="/var/log/${APP_NAME}"
13
13
  chown -R ${APP_USER}.${APP_GROUP} ${APP_HOME}
14
14
 
15
15
  # link app log directory to /var/log/NAME
16
+ mkdir -p ${LOGS}
16
17
  rm -rf ${HOME_LOGS}
17
18
  ln -fs ${LOGS} ${HOME_LOGS}
18
19
  chown -R ${APP_USER}.${APP_GROUP} ${LOGS}
@@ -43,7 +44,7 @@ echo "=============="
43
44
  # Call custom postinstall script.
44
45
  CUSTOM_POSTINSTALL_SCRIPT="<%= Base64.encode64 File.read(after_install) %>"
45
46
 
46
- tmpfile=$(mktemp)
47
+ <%= "tmpfile=$(#{"TMPDIR=\"#{tmpdir}\" " if tmpdir}mktemp)" %>
47
48
  chmod a+x "${tmpfile}"
48
49
  echo "${CUSTOM_POSTINSTALL_SCRIPT}" | base64 -d - > ${tmpfile}
49
50
 
@@ -18,7 +18,7 @@ fi
18
18
  # Call custom postuninstall script.
19
19
  CUSTOM_POSTUNINSTALL_SCRIPT="<%= Base64.encode64 File.read(after_remove) %>"
20
20
 
21
- tmpfile=$(mktemp)
21
+ <%= "tmpfile=$(#{"TMPDIR=\"#{tmpdir}\" " if tmpdir}mktemp)" %>
22
22
  chmod a+x "${tmpfile}"
23
23
  echo "${CUSTOM_POSTUNINSTALL_SCRIPT}" | base64 -d - > ${tmpfile}
24
24
 
@@ -27,7 +27,7 @@ fi
27
27
  # https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html
28
28
  CUSTOM_PREINSTALL_SCRIPT="<%= Base64.encode64 File.read(before_install) %>"
29
29
 
30
- tmpfile=$(mktemp)
30
+ <%= "tmpfile=$(#{"TMPDIR=\"#{tmpdir}\" " if tmpdir}mktemp)" %>
31
31
  chmod a+x "${tmpfile}"
32
32
  echo "${CUSTOM_PREINSTALL_SCRIPT}" | base64 -d - > ${tmpfile}
33
33
 
@@ -10,7 +10,7 @@ export APP_HOME="<%= home %>"
10
10
  <% if before_remove && File.readable?(before_remove) %>
11
11
  CUSTOM_PREUNINSTALL_SCRIPT="<%= Base64.encode64 File.read(before_remove) %>"
12
12
 
13
- tmpfile=$(mktemp)
13
+ <%= "tmpfile=$(#{"TMPDIR=\"#{tmpdir}\" " if tmpdir}mktemp)" %>
14
14
  chmod a+x "${tmpfile}"
15
15
  echo "${CUSTOM_PREUNINSTALL_SCRIPT}" | base64 -d - > ${tmpfile}
16
16
 
@@ -4,7 +4,7 @@ Requires=<%= name %>-<%= process_name %>.service
4
4
  After=<%= name %>-<%= process_name %>.service
5
5
 
6
6
  [Service]
7
- Environment=PORT=PORT_NUM
7
+ Environment=APP_PROCESS_INDEX=__PROCESS_INDEX__
8
8
  ExecStart=/usr/bin/<%= name %> run <%= process_name %>
9
9
  Restart=always
10
10
  StandardOutput=syslog
@@ -14,19 +14,18 @@
14
14
  ### END INIT INFO
15
15
 
16
16
  export PATH=/sbin:/usr/sbin:/bin:/usr/bin
17
- export PORT=PORT_NUM
17
+ export APP_PROCESS_INDEX=__PROCESS_INDEX__
18
18
 
19
19
  name="<%= name %>"
20
20
  process_name="<%= process_name %>"
21
21
  user="<%= user %>"
22
22
  group="<%= group %>"
23
- full_process_name="${name}-${process_name}-PROCESS_NUM"
23
+ full_process_name="${name}-${process_name}-${APP_PROCESS_INDEX}"
24
24
  pidfile="/var/run/${full_process_name}.pid"
25
25
 
26
-
27
26
  start() {
28
27
  # Run the program!
29
- ${name} run ${process_name} >> /var/log/${name}/${process_name}-PROCESS_NUM.log 2>&1 &
28
+ ${name} run ${process_name} >> /var/log/${name}/${process_name}-${APP_PROCESS_INDEX}.log 2>&1 &
30
29
 
31
30
  # Generate the pidfile from here. If we instead made the forked process
32
31
  # generate it there will be a race condition between the pidfile writing
@@ -2,6 +2,6 @@ start on starting <%= name %>-<%= process_name %>
2
2
  stop on stopping <%= name %>-<%= process_name %>
3
3
  respawn
4
4
 
5
- env PORT=PORT_NUM
5
+ env APP_PROCESS_INDEX=__PROCESS_INDEX__
6
6
 
7
7
  exec <%= name %> run <%= process_name %> >> /var/log/<%= name %>/<%= process_name %>-PROCESS_NUM.log 2>&1
@@ -107,20 +107,23 @@ module Pkgr
107
107
 
108
108
  # Pass the app through the buildpack
109
109
  def compile
110
- if buildpack_for_app
111
- puts "-----> #{buildpack_for_app.banner} app"
110
+ begin
111
+ FileUtils.mkdir_p(app_home_dir)
112
+ rescue Errno::EACCES => e
113
+ Pkgr.logger.warn "Can't create #{app_home_dir.inspect}, which may be needed by some buildpacks."
114
+ end
115
+ FileUtils.mkdir_p(compile_cache_dir)
116
+ FileUtils.mkdir_p(compile_env_dir)
112
117
 
113
- begin
114
- FileUtils.mkdir_p(app_home_dir)
115
- rescue Errno::EACCES => e
116
- Pkgr.logger.warn "Can't create #{app_home_dir.inspect}, which may be needed by some buildpacks."
118
+ if buildpacks_for_app.size > 0
119
+ run_hook config.before_hook
120
+
121
+ buildpacks_for_app.each do |buildpack|
122
+ puts "-----> #{buildpack.banner} app"
123
+ buildpack.compile(source_dir, compile_cache_dir, compile_env_dir)
124
+ buildpack.release(source_dir)
117
125
  end
118
- FileUtils.mkdir_p(compile_cache_dir)
119
- FileUtils.mkdir_p(compile_env_dir)
120
126
 
121
- run_hook config.before_hook
122
- buildpack_for_app.compile(source_dir, compile_cache_dir, compile_env_dir)
123
- buildpack_for_app.release(source_dir)
124
127
  run_hook config.after_hook
125
128
  else
126
129
  raise Errors::UnknownAppType, "Can't find a buildpack for your app"
@@ -285,17 +288,23 @@ module Pkgr
285
288
  @distribution ||= Distributions.current(config)
286
289
  end
287
290
 
288
- # List of available buildpacks for the current distribution.
289
- def buildpacks
290
- distribution.buildpacks
291
- end
292
-
293
- # Buildpack detected for the app, if any.
294
- def buildpack_for_app
291
+ # Buildpacks detected for the app, if any. If multiple buildpacks are explicitly specified, all are used
292
+ def buildpacks_for_app
295
293
  raise "#{source_dir} does not exist" unless File.directory?(source_dir)
296
- @buildpack_for_app ||= buildpacks.find do |buildpack|
297
- buildpack.setup(config.edge, config.home)
298
- buildpack.detect(source_dir)
294
+ @buildpacks_for_app ||= begin
295
+ mode, buildpacks = distribution.buildpacks
296
+ case mode
297
+ when :custom
298
+ buildpacks.find_all do |buildpack|
299
+ buildpack.setup(config.edge, config.home)
300
+ buildpack.detect(source_dir)
301
+ end
302
+ else
303
+ [buildpacks.find do |buildpack|
304
+ buildpack.setup(config.edge, config.home)
305
+ buildpack.detect(source_dir)
306
+ end].compact
307
+ end
299
308
  end
300
309
  end
301
310
 
@@ -307,7 +316,7 @@ module Pkgr
307
316
  def run_hook(file)
308
317
  return true if file.nil?
309
318
 
310
- cmd = %{env -i APP_NAME="#{config.name}" PATH="$PATH"#{config.env} bash '#{file}' 2>&1}
319
+ cmd = %{env -i APP_NAME="#{config.name}" PATH="$PATH" #{config.env} bash '#{file}' 2>&1}
311
320
 
312
321
  Pkgr.logger.debug "Running hook in #{source_dir}: #{file.inspect}"
313
322
  puts "-----> Running hook: #{file.inspect}"
@@ -20,7 +20,7 @@ module Pkgr
20
20
  @url, @branch = url.split("#")
21
21
  @branch ||= "master"
22
22
  @type = type
23
- @env = env
23
+ @env = env || Env.new
24
24
  end
25
25
 
26
26
  def buildpack_cache_dir
@@ -28,7 +28,7 @@ module Pkgr
28
28
  end
29
29
 
30
30
  def detect(path)
31
- buildpack_detect = Mixlib::ShellOut.new("#{dir}/bin/detect \"#{path}\"")
31
+ buildpack_detect = Mixlib::ShellOut.new("env -i #{compound_environment(path)} #{dir}/bin/detect \"#{path}\"")
32
32
  buildpack_detect.logger = Pkgr.logger
33
33
  buildpack_detect.run_command
34
34
  @banner = buildpack_detect.stdout.chomp
@@ -36,7 +36,7 @@ module Pkgr
36
36
  end
37
37
 
38
38
  def compile(path, compile_cache_dir, compile_env_dir)
39
- cmd = %{env -i PATH="$PATH"#{env} #{dir}/bin/compile "#{path}" "#{compile_cache_dir}" "#{compile_env_dir}" }
39
+ cmd = %{env -i #{compound_environment(path)} #{dir}/bin/compile "#{path}" "#{compile_cache_dir}" "#{compile_env_dir}" }
40
40
  Pkgr.debug "Running #{cmd.inspect}"
41
41
 
42
42
  Dir.chdir(path) do
@@ -53,7 +53,7 @@ module Pkgr
53
53
  end
54
54
 
55
55
  def release(path)
56
- buildpack_release = Mixlib::ShellOut.new("#{dir}/bin/release \"#{path}\" > #{path}/.release")
56
+ buildpack_release = Mixlib::ShellOut.new("env -i #{compound_environment(path)} #{dir}/bin/release \"#{path}\" > #{path}/.release")
57
57
  buildpack_release.logger = Pkgr.logger
58
58
  buildpack_release.run_command
59
59
  buildpack_release.exitstatus == 0
@@ -75,7 +75,7 @@ module Pkgr
75
75
  def refresh(edge = true)
76
76
  return if !edge
77
77
  Dir.chdir(dir) do
78
- buildpack_refresh = Mixlib::ShellOut.new("git fetch origin && ( git reset --hard #{branch} || git reset --hard origin/#{branch} )")
78
+ buildpack_refresh = Mixlib::ShellOut.new("git fetch origin && ( git reset --hard #{branch} || git reset --hard origin/#{branch} ) && chmod -f +x bin/detect && chmod -f +x bin/compile && chmod -f +x bin/release")
79
79
  buildpack_refresh.logger = Pkgr.logger
80
80
  buildpack_refresh.run_command
81
81
  buildpack_refresh.error!
@@ -104,5 +104,17 @@ module Pkgr
104
104
  buildpack_replace.error!
105
105
  end
106
106
  end
107
+
108
+ private
109
+
110
+ def compound_environment(path)
111
+ Env.new(['PATH=$PATH']).merge(env).merge(exported_environment(File.join(path, "export")))
112
+ end
113
+
114
+ def exported_environment(path)
115
+ Env.from_export(path)
116
+ rescue Errno::ENOENT
117
+ Env.new
118
+ end
107
119
  end
108
120
  end
@@ -31,7 +31,7 @@ module Pkgr
31
31
 
32
32
  method_option :buildpack,
33
33
  :type => :string,
34
- :desc => "Custom buildpack to use"
34
+ :desc => "Custom buildpack to use. May be a single string or a list."
35
35
  method_option :buildpack_list,
36
36
  :type => :string,
37
37
  :desc => "Specify a file containing a list of buildpacks to use (--buildpack takes precedence if given)"
@@ -54,6 +54,9 @@ module Pkgr
54
54
  method_option :homepage,
55
55
  :type => :string,
56
56
  :desc => "Project homepage"
57
+ method_option :home,
58
+ :type => :string,
59
+ :desc => "Project home"
57
60
  method_option :description,
58
61
  :type => :string,
59
62
  :desc => "Project description"
@@ -111,7 +114,6 @@ module Pkgr
111
114
  :desc => "Specific system dependencies that must be present before building"
112
115
  method_option :disable_default_dependencies,
113
116
  :type => :boolean,
114
- :default => false,
115
117
  :desc => "Disable default dependencies"
116
118
  method_option :host,
117
119
  :type => :string,
@@ -152,8 +154,10 @@ module Pkgr
152
154
  :desc => "Recursively mark a directory as being owned by the package"
153
155
  method_option :disable_cli,
154
156
  :type => :boolean,
155
- :default => false,
156
157
  :desc => "Disable installing CLI"
158
+ method_option :tmpdir,
159
+ :type => :string,
160
+ :desc => 'Set a custom tmpdir for hook scripts to get created in'
157
161
 
158
162
  def package(tarball)
159
163
  Pkgr.level = Logger::INFO if options[:verbose]
@@ -100,6 +100,10 @@ module Pkgr
100
100
  @table[:group] || user
101
101
  end
102
102
 
103
+ def tmpdir
104
+ @table[:tmpdir]
105
+ end
106
+
103
107
  def architecture
104
108
  @table[:architecture] || "x86_64"
105
109
  end
@@ -124,6 +128,10 @@ module Pkgr
124
128
  @table[:env].is_a?(Pkgr::Env) ? @table[:env] : Pkgr::Env.new(@table[:env])
125
129
  end
126
130
 
131
+ def buildpacks
132
+ @table[:buildpack].is_a?(String) ? @table[:buildpack].split(",") : @table[:buildpack]
133
+ end
134
+
127
135
  def valid?
128
136
  @errors = []
129
137
  @errors.push("name can't be blank") if name.nil? || name.empty?
@@ -223,6 +231,7 @@ module Pkgr
223
231
  "--group \"#{group}\"",
224
232
  "--iteration \"#{iteration}\"",
225
233
  "--homepage \"#{homepage}\"",
234
+ "--home \"#{home}\"",
226
235
  "--architecture \"#{architecture}\"",
227
236
  "--description \"#{description}\"",
228
237
  "--maintainer \"#{maintainer}\"",
@@ -251,6 +260,7 @@ module Pkgr
251
260
  args.push "--verify" if verify
252
261
  args.push "--no-clean" if !clean
253
262
  args.push "--no-edge" if !edge
263
+ args.push "--tmpdir" if !tmpdir
254
264
  args
255
265
  end
256
266
  end
@@ -1,6 +1,43 @@
1
1
  module Pkgr
2
+
2
3
  module Distributions
3
- class Amazon < Redhat
4
+
5
+ class Amazon < Base
6
+
7
+ def release
8
+ @release[/^[0-9]+/]
9
+ end
10
+
11
+ def runner
12
+ @runner ||= Runner.new("upstart", "1.5", "initctl")
13
+ end
14
+
15
+ def package_test_command(package)
16
+ "rpm -qa '#{package}' | grep '#{package}' > /dev/null 2>&1"
17
+ end
18
+
19
+ def package_install_command(packages)
20
+ "sudo yum -q check-update ; sudo yum install -y #{packages.map{|package| "\"#{package}\""}.join(" ")}"
21
+ end
22
+
23
+ def installer_dependencies
24
+ super.push("which").uniq
25
+ end
26
+
27
+ def fpm_command(build_dir)
28
+ AmazonFpmCommand.new(self, build_dir).command
29
+ end
30
+
31
+ class AmazonFpmCommand < FpmCommand
32
+ def args
33
+ list = super
34
+ list << "-t" << "rpm"
35
+ list
36
+ end
37
+ end
38
+
4
39
  end
40
+
5
41
  end
42
+
6
43
  end
@@ -76,12 +76,10 @@ module Pkgr
76
76
 
77
77
  # Returns a list of Buildpack objects
78
78
  def buildpacks
79
- custom_buildpack_uri = config.buildpack
80
- if custom_buildpack_uri
81
- uuid = Digest::SHA1.hexdigest(custom_buildpack_uri)
82
- [Buildpack.new(custom_buildpack_uri, :custom, config.env)]
79
+ if config.buildpacks
80
+ [:custom, config.buildpacks.map { |url| Buildpack.new(url, :custom, config.env) }]
83
81
  else
84
- load_buildpack_list
82
+ [:builtin, load_buildpack_list]
85
83
  end
86
84
  end # def buildpacks
87
85
 
@@ -101,16 +99,17 @@ module Pkgr
101
99
  app_name = config.name
102
100
  list = []
103
101
 
104
- # directories
105
- [
106
- "usr/bin",
102
+ directories = [
107
103
  config.home.gsub(/^\//, ""),
108
104
  "etc/#{app_name}/conf.d",
109
105
  "etc/default",
110
106
  "var/log/#{app_name}",
111
107
  "var/db/#{app_name}",
112
108
  "usr/share/#{app_name}"
113
- ].each{|dir| list.push Templates::DirTemplate.new(dir) }
109
+ ]
110
+
111
+ directories << "usr/bin" if config.cli?
112
+ directories.each{|dir| list.push Templates::DirTemplate.new(dir) }
114
113
 
115
114
  list.push Templates::FileTemplate.new("etc/default/#{app_name}", data_file("environment", "default.erb"))
116
115
  list.push Templates::FileTemplate.new("etc/logrotate.d/#{app_name}", data_file("logrotate", "logrotate.erb"))
@@ -195,3 +194,4 @@ end # module Pkgr
195
194
  require 'pkgr/distributions/debian'
196
195
  require 'pkgr/distributions/fedora'
197
196
  require 'pkgr/distributions/sles'
197
+ require 'pkgr/distributions/amazon'
@@ -14,7 +14,7 @@ module Pkgr
14
14
 
15
15
  def runner
16
16
  @runner ||= case release
17
- when /^8/
17
+ when /^8/, /^9/
18
18
  Runner.new("systemd", "default", "systemctl")
19
19
  else
20
20
  Runner.new("sysv", "lsb-3.1", "update-rc.d")
@@ -24,5 +24,3 @@ module Pkgr
24
24
  end
25
25
  end
26
26
  end
27
-
28
- require 'pkgr/distributions/amazon'