pkgr 1.1.4pre3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -55,6 +55,7 @@ module Pkgr
55
55
  end
56
56
 
57
57
  tarball_extract = Mixlib::ShellOut.new("tar xzf #{tarball} -C #{source_dir}", opts)
58
+ tarball_extract.logger = Pkgr.logger
58
59
  tarball_extract.run_command
59
60
  tarball_extract.error!
60
61
  end
@@ -62,7 +63,8 @@ module Pkgr
62
63
  # Update existing config with the one from .pkgr.yml file, if any
63
64
  def update_config
64
65
  if File.exist?(config_file)
65
- @config = Config.load_file(config_file, distribution.version).merge(config)
66
+ Pkgr.debug "Loading #{distribution.slug} from #{config_file}."
67
+ @config = Config.load_file(config_file, distribution.slug).merge(config)
66
68
  Pkgr.debug "Found .pkgr.yml file. Updated config is now: #{config.inspect}"
67
69
  end
68
70
  end
@@ -115,8 +117,8 @@ module Pkgr
115
117
 
116
118
  # Launch the FPM command that will generate the package.
117
119
  def package
118
- Pkgr.info "Running command: #{fpm_command}"
119
120
  app_package = Mixlib::ShellOut.new(fpm_command)
121
+ app_package.logger = Pkgr.logger
120
122
  app_package.run_command
121
123
  app_package.error!
122
124
  end
@@ -190,7 +192,7 @@ module Pkgr
190
192
 
191
193
  # Returns the current distribution we're packaging for.
192
194
  def distribution
193
- @distribution ||= Distributions.current
195
+ @distribution ||= Distributions.current(config.force_os)
194
196
  end
195
197
 
196
198
  # List of available buildpacks for the current distribution.
@@ -214,10 +216,19 @@ module Pkgr
214
216
  protected
215
217
  def run_hook(file)
216
218
  return true if file.nil?
219
+
220
+ cmd = %{env -i PATH="$PATH"#{config.env} bash '#{file}' 2>&1}
221
+
222
+ puts "-----> Running hook: #{file.inspect}"
223
+
217
224
  Dir.chdir(source_dir) do
218
- app_package = Mixlib::ShellOut.new("bash '#{file}'")
219
- app_package.run_command
220
- app_package.error!
225
+ IO.popen(cmd) do |io|
226
+ until io.eof?
227
+ data = io.gets
228
+ print " #{data}"
229
+ end
230
+ end
231
+ raise "Hook failed" unless $?.exitstatus.zero?
221
232
  end
222
233
  end
223
234
  end
@@ -29,6 +29,7 @@ module Pkgr
29
29
 
30
30
  def detect(path)
31
31
  buildpack_detect = Mixlib::ShellOut.new("#{dir}/bin/detect \"#{path}\"")
32
+ buildpack_detect.logger = Pkgr.logger
32
33
  buildpack_detect.run_command
33
34
  @banner = buildpack_detect.stdout.chomp
34
35
  buildpack_detect.exitstatus == 0
@@ -52,6 +53,7 @@ module Pkgr
52
53
 
53
54
  def release(path, compile_cache_dir)
54
55
  buildpack_release = Mixlib::ShellOut.new("#{dir}/bin/release \"#{path}\" \"#{compile_cache_dir}\" > #{path}/.release")
56
+ buildpack_release.logger = Pkgr.logger
55
57
  buildpack_release.run_command
56
58
  buildpack_release.exitstatus == 0
57
59
  end
@@ -72,7 +74,8 @@ module Pkgr
72
74
  def refresh(edge = true)
73
75
  return if !edge
74
76
  Dir.chdir(dir) do
75
- buildpack_refresh = Mixlib::ShellOut.new("git fetch origin && git reset --hard origin/#{branch}")
77
+ buildpack_refresh = Mixlib::ShellOut.new("git fetch origin && git reset --hard $(git describe 'origin/#{branch}' || git describe '#{branch}')")
78
+ buildpack_refresh.logger = Pkgr.logger
76
79
  buildpack_refresh.run_command
77
80
  buildpack_refresh.error!
78
81
  end
@@ -82,14 +85,17 @@ module Pkgr
82
85
  FileUtils.mkdir_p(buildpack_cache_dir)
83
86
  Dir.chdir(buildpack_cache_dir) do
84
87
  buildpack_install = Mixlib::ShellOut.new("git clone \"#{url}\"")
88
+ buildpack_install.logger = Pkgr.logger
85
89
  buildpack_install.run_command
86
90
  buildpack_install.error!
87
91
  end
92
+ refresh(true)
88
93
  end
89
94
 
90
95
  def replace_app_with_app_home(app_home)
91
96
  Dir.chdir(dir) do
92
97
  buildpack_replace = Mixlib::ShellOut.new("find . -type f -print0 | xargs -0 perl -pi -e s,/app,#{app_home},g")
98
+ buildpack_replace.logger = Pkgr.logger
93
99
  buildpack_replace.run_command
94
100
  buildpack_replace.error!
95
101
  end
@@ -23,25 +23,75 @@ module Pkgr
23
23
 
24
24
  desc "package TARBALL", "Package the given tarball or directory"
25
25
 
26
- method_option :target, :type => :string, :default => "deb", :desc => "Target package to build (only 'deb' supported for now)"
27
- method_option :changelog, :type => :string, :desc => "Changelog"
28
- method_option :architecture, :type => :string, :default => "x86_64", :desc => "Target architecture for the package"
29
- method_option :homepage, :type => :string, :desc => "Project homepage"
30
- method_option :description, :type => :string, :desc => "Project description"
31
- method_option :version, :type => :string, :desc => "Package version (if git directory given, it will use the latest git tag available)"
32
- method_option :iteration, :type => :string, :default => Time.now.strftime("%Y%m%d%H%M%S"), :desc => "Package iteration (you should keep the default here)"
33
- method_option :user, :type => :string, :desc => "User to run the app under (defaults to your app name)"
34
- method_option :group, :type => :string, :desc => "Group to run the app under (defaults to your app name)"
35
- method_option :compile_cache_dir, :type => :string, :desc => "Where to store the files cached between packaging runs. Path will be resolved from the temporary code repository folder, so use absolute paths if needed."
36
- method_option :before_precompile, :type => :string, :desc => "Provide a script to run just before the buildpack compilation. Path will be resolved from the temporary code repository folder, so use absolute paths if needed."
37
- method_option :dependencies, :type => :array, :default => [], :desc => "Specific system dependencies that you want to install with the package"
38
- method_option :build_dependencies, :type => :array, :default => [], :desc => "Specific system dependencies that must be present before building"
39
- method_option :host, :type => :string, :desc => "Remote host to build on (default: local machine)"
40
- method_option :auto, :type => :boolean, :default => false, :desc => "Automatically attempt to install missing dependencies"
41
- method_option :clean, :type => :boolean, :default => true, :desc => "Automatically clean up temporary dirs"
42
- method_option :buildpack, :type => :string, :desc => "Custom buildpack to use"
43
- method_option :edge, :type => :boolean, :default => true, :desc => "Always use the latest version of the buildpack if already installed"
44
- method_option :env, :type => :array, default: [], :description => 'Specify environment variables for buildpack (--env "CURL_TIMEOUT=2" "BUNDLE_WITHOUT=development test")'
26
+ method_option :buildpack,
27
+ :type => :string,
28
+ :desc => "Custom buildpack to use"
29
+ method_option :target,
30
+ :type => :string,
31
+ :default => "deb",
32
+ :desc => "Target package to build (only 'deb' supported for now)"
33
+ method_option :changelog,
34
+ :type => :string,
35
+ :desc => "Changelog"
36
+ method_option :architecture,
37
+ :type => :string,
38
+ :default => "x86_64",
39
+ :desc => "Target architecture for the package"
40
+ method_option :homepage,
41
+ :type => :string,
42
+ :desc => "Project homepage"
43
+ method_option :description,
44
+ :type => :string,
45
+ :desc => "Project description"
46
+ method_option :version,
47
+ :type => :string,
48
+ :desc => "Package version (if git directory given, it will use the latest git tag available)"
49
+ method_option :iteration,
50
+ :type => :string,
51
+ :default => Time.now.strftime("%Y%m%d%H%M%S"),
52
+ :desc => "Package iteration (you should keep the default here)"
53
+ method_option :user,
54
+ :type => :string,
55
+ :desc => "User to run the app under (defaults to your app name)"
56
+ method_option :group,
57
+ :type => :string,
58
+ :desc => "Group to run the app under (defaults to your app name)"
59
+ method_option :compile_cache_dir,
60
+ :type => :string,
61
+ :desc => "Where to store the files cached between packaging runs. Path will be resolved from the temporary code repository folder, so use absolute paths if needed."
62
+ method_option :before_precompile,
63
+ :type => :string,
64
+ :desc => "Provide a script to run just before the buildpack compilation. Path will be resolved from the temporary code repository folder, so use absolute paths if needed."
65
+ method_option :dependencies,
66
+ :type => :array,
67
+ :default => [],
68
+ :desc => "Specific system dependencies that you want to install with the package"
69
+ method_option :build_dependencies,
70
+ :type => :array,
71
+ :default => [],
72
+ :desc => "Specific system dependencies that must be present before building"
73
+ method_option :host,
74
+ :type => :string,
75
+ :desc => "Remote host to build on (default: local machine)"
76
+ method_option :auto,
77
+ :type => :boolean,
78
+ :default => false,
79
+ :desc => "Automatically attempt to install missing dependencies"
80
+ method_option :clean,
81
+ :type => :boolean,
82
+ :default => true,
83
+ :desc => "Automatically clean up temporary dirs"
84
+ method_option :edge,
85
+ :type => :boolean,
86
+ :default => true,
87
+ :desc => "Always use the latest version of the buildpack if already installed"
88
+ method_option :env,
89
+ :type => :array,
90
+ :default => [],
91
+ :desc => 'Specify environment variables for buildpack (--env "CURL_TIMEOUT=2" "BUNDLE_WITHOUT=development test")'
92
+ method_option :force_os,
93
+ :type => :string,
94
+ :desc => 'Force a specific distribution to build for (e.g. --force-os "debian-wheezy")'
45
95
 
46
96
  def package(tarball)
47
97
  Pkgr.level = Logger::INFO if options[:verbose]
@@ -6,6 +6,7 @@ module Pkgr
6
6
  class << self
7
7
  def load_file(path, distribution)
8
8
  config = YAML.load_file(path)
9
+ Pkgr.debug "Configuration from file: #{config.inspect} - Distribution: #{distribution.inspect}."
9
10
 
10
11
  targets = config.delete("targets") || {}
11
12
  (targets[distribution.to_s] || {}).each do |k,v|
@@ -22,7 +23,15 @@ module Pkgr
22
23
 
23
24
  def merge(other)
24
25
  new_config = self.class.new
25
- self.each{|k,v| new_config.send("#{k}=".to_sym, v)}
26
+ self.each{|k,v|
27
+ new_value = case v
28
+ when Array
29
+ v | (other.delete(k) || [])
30
+ else
31
+ v
32
+ end
33
+ new_config.send("#{k}=".to_sym, new_value)
34
+ }
26
35
  other.each{|k,v| new_config.send("#{k}=".to_sym, v)}
27
36
  new_config
28
37
  end
@@ -34,6 +43,10 @@ module Pkgr
34
43
  end
35
44
  end
36
45
 
46
+ def delete(key)
47
+ @table.delete(key)
48
+ end
49
+
37
50
  def home
38
51
  "/opt/#{name}"
39
52
  end
@@ -66,6 +79,7 @@ module Pkgr
66
79
  @errors = []
67
80
  @errors.push("name can't be blank") if name.nil? || name.empty?
68
81
  @errors.push("version can't be blank") if version.nil? || version.empty?
82
+ @errors.push("version must start with a digit") if !version.empty? && version !~ /^\d/
69
83
  @errors.push("iteration can't be blank") if iteration.nil? || iteration.empty?
70
84
  @errors.push("user can't be blank") if user.nil? || user.empty?
71
85
  @errors.push("group can't be blank") if group.nil? || group.empty?
@@ -93,6 +107,7 @@ module Pkgr
93
107
  args.push "--compile-cache-dir \"#{compile_cache_dir}\"" unless compile_cache_dir.nil? || compile_cache_dir.empty?
94
108
  args.push "--before-precompile \"#{before_precompile}\"" unless before_precompile.nil? || before_precompile.empty?
95
109
  args.push "--buildpack \"#{buildpack}\"" unless buildpack.nil? || buildpack.empty?
110
+ args.push "--force-os \"#{force_os}\"" unless force_os.nil? || force_os.empty?
96
111
  args.push "--env #{env.variables.map{|v| "\"#{v}\""}.join(" ")}" if env.present?
97
112
  args.push "--auto" if auto
98
113
  args.push "--verbose" if verbose
@@ -1,5 +1,4 @@
1
1
  default:
2
- - libssl0.9.8
3
2
  - curl
4
3
  - libmysqlclient-dev
5
4
  - libpq-dev
@@ -10,3 +9,7 @@ default:
10
9
  - libxslt1-dev
11
10
  - libreadline-dev
12
11
  - build-essential
12
+ squeeze:
13
+ - libssl0.9.8
14
+ wheezy:
15
+ - libssl1.0.0
@@ -3,28 +3,19 @@ default:
3
3
  - mysql-common
4
4
  - libpq5
5
5
  - libsqlite3-0
6
- - libssl0.9.8
7
6
  - openssl
8
7
  - libxml2
9
8
  - libxslt1.1
10
9
  - libreadline5
11
10
  - libreadline6
12
- debian-squeeze:
13
- - libmysqlclient16
14
- - libevent-1.4-2
15
- - libevent-core-1.4-2
16
- - libevent-extra-1.4-2
17
- ubuntu-lucid:
11
+ squeeze:
12
+ - libssl0.9.8
18
13
  - libmysqlclient16
19
14
  - libevent-1.4-2
20
15
  - libevent-core-1.4-2
21
16
  - libevent-extra-1.4-2
22
- debian-wheezy:
23
- - libmysqlclient18
24
- - libevent-2.0-5
25
- - libevent-core-2.0-5
26
- - libevent-extra-2.0-5
27
- ubuntu-precise:
17
+ wheezy:
18
+ - libssl1.0.0
28
19
  - libmysqlclient18
29
20
  - libevent-2.0-5
30
21
  - libevent-core-2.0-5
@@ -38,7 +38,11 @@ module Pkgr
38
38
  tmpfile = Tempfile.new(["pkgr-tarball", ".tar.gz"])
39
39
  system("tar czf #{tmpfile.path} --exclude .git --exclude .svn -C \"#{path}\" .") || raise(Pkgr::Errors::Base, "Can't compress input directory")
40
40
  # Remove any non-digit characters that may be before the version number
41
- config.version ||= (Git.new(path).latest_tag || "").gsub(/^[^\d](\d.*)/, '\1')
41
+ config.version ||= begin
42
+ v = (Git.new(path).latest_tag || "").gsub(/^[^\d]+(\d.*)/, '\1')
43
+ v = "0.0.0" if v !~ /^\d/
44
+ v
45
+ end
42
46
  config.compile_cache_dir ||= File.join(path, ".git", "cache")
43
47
  config.name ||= File.basename(path)
44
48
  @path = tmpfile.path
@@ -5,13 +5,18 @@ require 'facter'
5
5
 
6
6
  module Pkgr
7
7
  module Distributions
8
- def current
9
- osfamily = Facter.value('osfamily')
10
- klass = const_get(osfamily)
11
- klass.new([Facter.value('operatingsystem'), Facter.value('lsbdistcodename')].join("-").downcase)
8
+ def current(force_os = nil)
9
+ distro = if force_os.nil?
10
+ [Facter.value('operatingsystem'), Facter.value('lsbdistcodename')]
11
+ else
12
+ force_os.split("-")
13
+ end.map(&:capitalize).join("")
14
+
15
+ klass = const_get(distro)
16
+ klass.new
12
17
  rescue NameError => e
13
- raise Errors::UnknownDistribution, "Don't know about the current distribution you're on: #{osfamily.inspect}"
18
+ raise Errors::UnknownDistribution, "Don't know about the current distribution you're on: #{distro}"
14
19
  end
15
20
  module_function :current
16
21
  end
17
- end
22
+ end
@@ -7,9 +7,17 @@ module Pkgr
7
7
  module Distributions
8
8
  class Debian
9
9
 
10
- attr_reader :version
11
- def initialize(version)
12
- @version = version
10
+ # Must be subclassed.
11
+ def codename
12
+ raise NotImplementedError, "codename must be set"
13
+ end
14
+
15
+ def osfamily
16
+ "debian"
17
+ end
18
+
19
+ def slug
20
+ [osfamily, codename].join("-")
13
21
  end
14
22
 
15
23
  def templates(app_name)
@@ -53,15 +61,15 @@ module Pkgr
53
61
  def check(config)
54
62
  missing_packages = (build_dependencies(config.build_dependencies) || []).select do |package|
55
63
  test_command = "dpkg -s '#{package}' > /dev/null 2>&1"
56
- Pkgr.debug "Running #{test_command}"
64
+ Pkgr.debug "sh(#{test_command})"
57
65
  ! system(test_command)
58
66
  end
59
67
 
60
68
  unless missing_packages.empty?
61
69
  package_install_command = "sudo apt-get install -y #{missing_packages.map{|package| "\"#{package}\""}.join(" ")}"
62
70
  if config.auto
63
- Pkgr.debug "Running command: #{package_install_command}"
64
71
  package_install = Mixlib::ShellOut.new(package_install_command)
72
+ package_install.logger = Pkgr.logger
65
73
  package_install.run_command
66
74
  package_install.error!
67
75
  else
@@ -97,29 +105,15 @@ module Pkgr
97
105
  uuid = Digest::SHA1.hexdigest(custom_buildpack_uri)
98
106
  [Buildpack.new(custom_buildpack_uri, :custom, config.env)]
99
107
  else
100
- case version
101
- when "ubuntu-precise", "debian-wheezy", "ubuntu-lucid", "debian-squeeze"
102
- %w{
103
- https://github.com/heroku/heroku-buildpack-ruby.git
104
- https://github.com/heroku/heroku-buildpack-nodejs.git
105
- https://github.com/heroku/heroku-buildpack-java.git
106
- https://github.com/heroku/heroku-buildpack-play.git
107
- https://github.com/heroku/heroku-buildpack-python.git
108
- https://github.com/heroku/heroku-buildpack-php.git
109
- https://github.com/heroku/heroku-buildpack-clojure.git
110
- https://github.com/kr/heroku-buildpack-go.git
111
- https://github.com/miyagawa/heroku-buildpack-perl.git
112
- https://github.com/heroku/heroku-buildpack-scala
113
- https://github.com/igrigorik/heroku-buildpack-dart.git
114
- https://github.com/rhy-jot/buildpack-nginx.git
115
- https://github.com/Kloadut/heroku-buildpack-static-apache.git
116
- }.map{|url| Buildpack.new(url, :builtin, config.env)}
117
- else
118
- []
119
- end
108
+ default_buildpacks.map{|url| Buildpack.new(url, :builtin, config.env)}
120
109
  end
121
110
  end
122
111
 
112
+ # Return the default buildpacks. Must be subclassed.
113
+ def default_buildpacks
114
+ []
115
+ end
116
+
123
117
  def preinstall_file(config)
124
118
  @preinstall_file ||= begin
125
119
  source = File.join(data_dir, "hooks", "preinstall.sh")
@@ -146,12 +140,12 @@ module Pkgr
146
140
 
147
141
  def dependencies(other_dependencies = nil)
148
142
  deps = YAML.load_file(File.join(data_dir, "dependencies.yml"))
149
- (deps["default"] || []) | (deps[version] || []) | (other_dependencies || [])
143
+ (deps["default"] || []) | (deps[codename] || []) | (other_dependencies || [])
150
144
  end
151
145
 
152
146
  def build_dependencies(other_dependencies = nil)
153
147
  deps = YAML.load_file(File.join(data_dir, "build_dependencies.yml"))
154
- (deps["default"] || []) | (deps[version] || []) | (other_dependencies || [])
148
+ (deps["default"] || []) | (deps[codename] || []) | (other_dependencies || [])
155
149
  end
156
150
 
157
151
  def data_file(name)
@@ -164,3 +158,7 @@ module Pkgr
164
158
  end
165
159
  end
166
160
  end
161
+
162
+ %w{debian_squeeze debian_wheezy ubuntu_lucid ubuntu_precise}.each do |distro|
163
+ require "pkgr/distributions/#{distro}"
164
+ end
@@ -0,0 +1,22 @@
1
+ require "pkgr/distributions/debian"
2
+
3
+ module Pkgr
4
+ module Distributions
5
+ class DebianSqueeze < Debian
6
+ def codename
7
+ "squeeze"
8
+ end
9
+
10
+ def default_buildpacks
11
+ %w{
12
+ https://github.com/heroku/heroku-buildpack-ruby.git
13
+ https://github.com/heroku/heroku-buildpack-nodejs.git
14
+ https://github.com/heroku/heroku-buildpack-java.git
15
+ https://github.com/heroku/heroku-buildpack-play.git
16
+ https://github.com/heroku/heroku-buildpack-python.git
17
+ https://github.com/heroku/heroku-buildpack-clojure.git
18
+ }
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require "pkgr/distributions/debian"
2
+
3
+ module Pkgr
4
+ module Distributions
5
+ class DebianWheezy < Debian
6
+ def codename
7
+ "wheezy"
8
+ end
9
+
10
+ def default_buildpacks
11
+ %w{
12
+ https://github.com/pkgr/heroku-buildpack-ruby.git#precise
13
+ https://github.com/heroku/heroku-buildpack-nodejs.git
14
+ https://github.com/heroku/heroku-buildpack-java.git
15
+ https://github.com/heroku/heroku-buildpack-play.git
16
+ https://github.com/heroku/heroku-buildpack-python.git
17
+ https://github.com/heroku/heroku-buildpack-clojure.git
18
+ }
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ require "pkgr/distributions/debian_squeeze"
2
+
3
+ module Pkgr
4
+ module Distributions
5
+ class UbuntuLucid < DebianSqueeze
6
+ def codename
7
+ "lucid"
8
+ end
9
+
10
+ def osfamily
11
+ "ubuntu"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require "pkgr/distributions/debian_wheezy"
2
+
3
+ module Pkgr
4
+ module Distributions
5
+ class UbuntuPrecise < DebianWheezy
6
+ def codename
7
+ "precise"
8
+ end
9
+
10
+ def osfamily
11
+ "ubuntu"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -12,6 +12,7 @@ module Pkgr
12
12
  return nil unless valid?
13
13
  Dir.chdir(path) do
14
14
  git_describe = Mixlib::ShellOut.new("git describe --tags --abbrev=0")
15
+ git_describe.logger = Pkgr.logger
15
16
  git_describe.run_command
16
17
  git_describe.stdout.chomp
17
18
  end
@@ -1,3 +1,3 @@
1
1
  module Pkgr
2
- VERSION = "1.1.4pre3"
2
+ VERSION = "1.1.4"
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pkgr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4pre3
5
- prerelease: 5
4
+ version: 1.1.4
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Cyril Rohr
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-22 00:00:00.000000000 Z
12
+ date: 2014-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -154,6 +154,10 @@ files:
154
154
  - lib/pkgr/data/pkgr.yml
155
155
  - lib/pkgr/dispatcher.rb
156
156
  - lib/pkgr/distributions/debian.rb
157
+ - lib/pkgr/distributions/debian_squeeze.rb
158
+ - lib/pkgr/distributions/debian_wheezy.rb
159
+ - lib/pkgr/distributions/ubuntu_lucid.rb
160
+ - lib/pkgr/distributions/ubuntu_precise.rb
157
161
  - lib/pkgr/distributions.rb
158
162
  - lib/pkgr/env.rb
159
163
  - lib/pkgr/git.rb