gaffer 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ Jeweler::Tasks.new do |s|
7
7
  s.author = "Orion Henry"
8
8
  s.email = "orion@heroku.com"
9
9
  s.homepage = "http://github.com/orionz/gaffer"
10
- s.files = FileList["[A-Z]*", "{bin,default,lib,spec}/**/*"]
10
+ s.files = FileList["[A-Z]*", "{bin,default,lib,spec,templates}/**/*"]
11
11
  s.executables = %w(gaffer)
12
12
  s.add_dependency "git"
13
13
  s.add_dependency "right_aws"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/bin/gaffer CHANGED
@@ -4,11 +4,24 @@ require File.dirname(__FILE__) + '/../lib/gaffer'
4
4
 
5
5
  require 'optparse'
6
6
 
7
+ ## TODO
8
+ ## proper way to deal with a branch?
9
+ ## make rebuild
10
+ ## make sure the gpg key stuff works and is getting imported/signed
11
+ ## resolve bundle package vs bundle install --deployed
12
+ ## resolve build_ids
13
+
7
14
  options = {}
8
15
 
9
16
  optparse = OptionParser.new do|opts|
10
17
  opts.banner = <<banner
11
- Usage: gaffer [options] ACTION [ DIR [ DIR [ ... ] ] ]
18
+ Usage: gaffer [options] init # init a new repo
19
+ gaffer [options] pull # pull a repo down from s3
20
+ gaffer [options] ls # list packages in repo
21
+ gaffer [options] rebuild # rebuild all repo indexes
22
+ gaffer [options] build [ DIR ... ] # build a package
23
+ gaffer [options] push # push repo to s3
24
+ gaffer [options] add [ PKG ... ] # add package to repo
12
25
  banner
13
26
 
14
27
  opts.on( '-f', '--force', 'Force an action' ) do
@@ -24,25 +37,34 @@ end
24
37
  optparse.parse!
25
38
 
26
39
  command = ARGV.shift
27
- target = ARGV.shift || Dir::pwd
40
+ targets = ARGV
41
+ targets = [Dir::pwd] if targets.empty?
28
42
 
29
43
  gaffer = Gaffer::Base.new(options)
30
44
 
31
- case command
32
- when "initrepo"
33
- gaffer.repro.init
34
- when "pull"
35
- gaffer.repro.pull
36
- when "build"
37
- gaffer.build(target)
38
- when "push"
39
- gaffer.repro.push
40
- when "add"
41
- gaffer.add(target)
42
- when "publish"
43
- gaffer.push gaffer.compile(target)
44
- else
45
- puts "No action: --help for help [#{command}]"
46
- exit 1
45
+ begin
46
+ case command
47
+ when "init"
48
+ gaffer.repro.init
49
+ when "pull"
50
+ gaffer.repro.pull
51
+ when "ls"
52
+ puts gaffer.repro.packages
53
+ when "rebuild"
54
+ gaffer.repro.rebuild
55
+ when "build"
56
+ targets.each { |target| gaffer.build target }
57
+ when "push"
58
+ gaffer.repro.push
59
+ when "add"
60
+ targets.each { |target| gaffer.add target }
61
+ when "publish"
62
+ # gaffer.push gaffer.compile(target)
63
+ else
64
+ puts "No action: --help for help [#{command}]"
65
+ exit 1
66
+ end
67
+ rescue Object => e
68
+ puts "ERROR: #{e.message}"
69
+ exit 2
47
70
  end
48
-
@@ -7,6 +7,7 @@ module Gaffer
7
7
  end
8
8
 
9
9
  def build(dir)
10
+ @dir = dir
10
11
  @git = Git::open(dir)
11
12
 
12
13
  @project = File::basename(File::dirname(@git.repo.path))
@@ -19,8 +20,7 @@ module Gaffer
19
20
 
20
21
  raise "Bad version #{@version}" unless @version =~ /^\d+[.]\d+[.]\d+$/
21
22
 
22
- build_id = @git.tags.map { |a| a.name =~ /^#{@version}-(.+)/; $1.to_i }.sort.last.to_i + 1
23
- @build_name = "#{@version}-#{build_id}"
23
+ @build_name = "#{@version}-#{next_build_id}"
24
24
 
25
25
  puts "======> #{@version.inspect}"
26
26
 
@@ -31,11 +31,20 @@ module Gaffer
31
31
  # Gaffer::Deb::new(self, "#{project}-dev", "#{project} (>= #{@version})").build
32
32
  end
33
33
 
34
+ def git_build_id
35
+ @git.tags.map { |a| a.name =~ /^#{@version}-(.+)/; $1.to_i }.sort.last.to_i
36
+ end
37
+
38
+ def repro_build_id
39
+ repro.packages.map { |p| p =~ /^#{@project}_#{@version}-(\d+)_/; $1 }.reject { |x| x.nil? }.max.to_i rescue 0
40
+ end
41
+
42
+ def next_build_id
43
+ [git_build_id, repro_build_id].max + 1
44
+ end
45
+
34
46
  def add(file)
35
- file = File.expand_path(file)
36
- Dir.chdir(repro_dir) do
37
- repro.include(file)
38
- end
47
+ repro.include(file)
39
48
  end
40
49
 
41
50
  def push_changed(dir, &blk)
@@ -54,20 +63,17 @@ module Gaffer
54
63
 
55
64
  options[:aws_key] ||= ENV['AWS_ACCESS_KEY_ID']
56
65
  options[:aws_secret] ||= ENV['AWS_SECRET_ACCESS_KEY']
57
- options[:bucket] ||= ENV['REP_BUCKET']
58
- options[:email] ||= ENV['REP_EMAIL']
59
- options[:maintainer] ||= ENV['REP_MAINTAINER']
66
+ options[:bucket] ||= ENV['GAFFER_BUCKET']
67
+ options[:email] ||= ENV['GAFFER_EMAIL']
68
+ options[:maintainer] ||= ENV['GAFFER_MAINTAINER']
69
+ options[:key] ||= ENV['GAFFER_KEY']
60
70
  options[:key] ||= options[:email]
61
71
 
62
72
  options[:codename] ||= "maverick"
63
73
  options[:components] ||= "main"
64
74
  options[:force] ||= !!@force
65
75
 
66
- dir = repro_dir
67
-
68
- puts "Repo: #{dir}"
69
-
70
- Gaffer::Repro.new(dir, options)
76
+ Gaffer::Repro.new(repro_dir, options)
71
77
  end
72
78
 
73
79
  def repro_dir
@@ -12,39 +12,67 @@ module Gaffer
12
12
 
13
13
  def build
14
14
  Dir.mktmpdir do |dir|
15
- install_dir = "#{dir}/#{@base.prefix}"
16
- Git.clone(@base.dir, install_dir)
15
+ install_dir = Rush["#{dir}/#{@base.prefix}/"]
16
+ Git.clone(@base.dir, install_dir.full_path)
17
17
  Rush.bash "mkdir #{dir}/DEBIAN"
18
18
  File.open("#{dir}/DEBIAN/control", "w") do |f|
19
19
  f.write(control)
20
20
  end
21
21
  puts control
22
22
  if @dev
23
- Rush.bash "find #{install_dir} | grep -v [.]git | grep -v #{install_dir}$ | xargs rm -rf"
23
+ Rush.bash "find #{install_dir.full_path} | grep -v [.]git | grep -v #{install_dir.full_path}$ | xargs rm -rf"
24
24
  else
25
- Rush.bash "find #{install_dir} | grep [.]git | grep -v #{install_dir}$ | xargs rm -rf"
26
- # [ :preinst, :postinst, :prerm, :postrm ].each do |script|
27
- # file = File.open("#{dir}/DEBIAN/#{script}","w")
28
- # file.chmod(0755)
29
- # file.write(template(script))
30
- # file.close
31
- # end
32
- if has_init?
33
- puts "INSTALLING init.conf"
34
- Rush.bash "mkdir -p #{dir}/etc/init"
35
- Rush.bash "cp #{@base.dir}/init.conf #{dir}/etc/init/#{@base.project}.conf"
25
+ Rush.bash "find #{install_dir.full_path} | grep [.]git | grep -v #{install_dir.full_path}$ | xargs rm -rf"
26
+ [ :preinst, :postinst, :prerm, :postrm ].each do |script|
27
+ file = File.open("#{dir}/DEBIAN/#{script}","w")
28
+ file.chmod(0755)
29
+ file.write(template(script))
30
+ file.close
36
31
  end
37
- if File.exists?("#{@base.dir}/Gemfile")
38
- Dir.chdir(@base.dir) do
39
- # TODO this can break in strange ways - STDOUT/STDERR is a mess
40
- if Rush.bash('bundle install --deployment').match(/native extensions/)
41
- @arch = Rush.bash "dpkg --print-architecture"
42
- end
32
+ if install_dir["sudoers"].exists?
33
+ Rush["#{dir}/etc/sudoers.d/"].create
34
+ Rush["#{dir}/etc/sudoers.d/#{project}"].write install_dir["sudoers"].read
35
+ end
36
+ if install_dir["init.conf"].exists?
37
+ puts " * detected init.conf - installing..."
38
+ Rush["#{dir}/etc/init/"].create
39
+ Rush["#{dir}/etc/init/#{project}.conf"].write install_dir["init.conf"].read
40
+ puts "init.conf -> /etc/init/#{project}.conf"
41
+ elsif install_dir["run"].exists?
42
+ puts " * detected file 'run' - setting up initfile ..."
43
+ initfile = template(:init)
44
+ puts "----"
45
+ puts initfile
46
+ puts "----"
47
+ puts " * installing to /etc/init/#{project}.conf"
48
+ Rush["#{dir}/etc/init/#{project}.conf"].parent.create
49
+ Rush["#{dir}/etc/init/#{project}.conf"].write(initfile)
50
+ end
51
+ if install_dir["Gemfile"].exists?
52
+ puts " * Gemfile detected - installing gems before packaging"
53
+ ## bundle output cannot be trusted - errors go to stdout and output goes to stderr
54
+ begin
55
+ install_dir.bash "bundle package 2>&1 > .tmp.bundle.out"
56
+ # install_dir.bash "bundle install --development 2>&1 > .tmp.bundle.out"
57
+ rescue Object => e
58
+ puts " * Bundle error:"
59
+ puts install_dir[".tmp.bundle.out"].read
60
+ raise "Bundle failed"
43
61
  end
62
+ puts install_dir[".tmp.bundle.out"].read
63
+ # if out.match(/native extensions/)
64
+ # puts "Warning: native extensions - the package is arch specific"
65
+ # @arch = Rush.bash("dpkg --print-architecture").chomp
66
+ # end
67
+ # end
44
68
  end
45
69
  end
46
- Rush.bash "dpkg-deb -b #{dir} ./#{filebase}.deb"
47
- File.expand_path("./#{filebase}.deb")
70
+ puts Rush.bash "pwd"
71
+ puts "fakeroot dpkg-deb -b #{dir} ./#{filebase}.deb"
72
+ puts Rush.bash "fakeroot dpkg-deb -b #{dir} ./#{filebase}.deb"
73
+ x = File.expand_path("./#{filebase}.deb")
74
+ puts x
75
+ x
48
76
  end
49
77
  end
50
78
 
@@ -68,6 +96,10 @@ module Gaffer
68
96
  ERB.new(File.read("#{File.dirname(__FILE__)}/../../templates/#{type}.erb")).result(binding)
69
97
  end
70
98
 
99
+ def origin
100
+ Rush[@base.dir]
101
+ end
102
+
71
103
  def maintainer
72
104
  @base.maintainer
73
105
  end
@@ -76,6 +108,10 @@ module Gaffer
76
108
  @base.build_name
77
109
  end
78
110
 
111
+ def project
112
+ @base.project
113
+ end
114
+
79
115
  def control
80
116
  template(:control)
81
117
  end
@@ -15,33 +15,51 @@ module Gaffer
15
15
  end
16
16
 
17
17
  def init
18
- if not Dir[@root].empty?
19
- raise "Dir #{@root} not empty - cannot init" unless @force
20
- FileUtils.rm_rf @root
18
+ unless root_dir.exists?
19
+ raise "Dir #{root_dir} exists - cannot init" unless @force
20
+ root_dir.destroy
21
21
  end
22
22
  create_dirs
23
- write_file "ubuntu/conf/options", options
24
- write_file "ubuntu/conf/distributions", distributes
23
+ conf_dir["options"].write options
24
+ conf_dir["distributions"].write distributions
25
25
  write_version 1
26
26
  end
27
27
 
28
+ def packages
29
+ index_dir["*"].map { |s| s.name }.sort
30
+ end
31
+
28
32
  def create_dirs
29
- repo_dirs.each do |dir|
30
- if not File.exists?("#{@root}/ubuntu/#{dir}")
31
- puts "* mkdir -p #{@root}/ubuntu/#{dir}"
32
- FileUtils.mkdir_p "#{@root}/ubuntu/#{dir}"
33
- end
33
+ repo_dir.create
34
+ index_dir.create
35
+ subdirs.each do |dir|
36
+ repo_dir["#{dir}/"].create
34
37
  end
35
38
  end
36
39
 
37
40
  def include(file)
41
+ f = Rush[File.expand_path(file)]
38
42
  bump_version
39
- file = File.expand_path(file)
40
- Dir.chdir("#{@root}/ubuntu") do
41
- run "reprepro includedeb #{@codename} #{file}"
43
+ raise "File already in index" if index_dir[f.name].exists?
44
+ f.copy_to index_dir
45
+ bucket_put "index/#{f.name}"
46
+ includedeb f
47
+ f.destroy
48
+ puts "* #{f.name} -> index/#{f.name}"
49
+ end
50
+
51
+ def rebuild
52
+ repo_dir["*"].reject { |dir| dir.name == "conf" }.each { |dir| dir.destroy }
53
+ create_dirs
54
+ index_dir["*"].each do |file|
55
+ includedeb file
42
56
  end
43
57
  end
44
58
 
59
+ def includedeb(file)
60
+ repo_dir.bash "reprepro includedeb #{@codename} #{file}"
61
+ end
62
+
45
63
  def ready!
46
64
  raise "No repo. Use 'gaffer pull' to download a repo from S3 or 'gaffer initrepo' to make a new one" unless File.include? "#{@root}/ubuntu/conf/distributions"
47
65
  end
@@ -51,6 +69,7 @@ module Gaffer
51
69
  puts "Version: #{local_version}"
52
70
  delete_remote
53
71
  write_remote
72
+ touch
54
73
  puts " [apt source]"
55
74
  puts url
56
75
  puts ""
@@ -62,6 +81,7 @@ module Gaffer
62
81
  puts "Version: #{remote_version}"
63
82
  delete_local
64
83
  write_local
84
+ touch
65
85
  end
66
86
 
67
87
  def url
@@ -70,17 +90,10 @@ module Gaffer
70
90
 
71
91
  private
72
92
 
73
- def repo_dirs
93
+ def subdirs
74
94
  %w(conf dists incoming indices logs pool project tmp)
75
95
  end
76
96
 
77
- def write_file(path, data)
78
- FileUtils.mkdir_p File.dirname("#{@root}/#{path}")
79
- File.open("#{@root}/#{path}","w") do |f|
80
- f.write(data)
81
- end
82
- end
83
-
84
97
  def options
85
98
  d = []
86
99
  d << "ask-passphrase"
@@ -88,7 +101,7 @@ module Gaffer
88
101
  d.join("\n") + "\n"
89
102
  end
90
103
 
91
- def distributes
104
+ def distributions
92
105
  d = []
93
106
  d << "Origin: #{@maintainer}"
94
107
  d << "Label: #{@maintainer} Deploy Repo"
@@ -101,10 +114,7 @@ module Gaffer
101
114
  end
102
115
 
103
116
  def run(cmd)
104
- Dir.chdir("#{@root}/ubuntu") do
105
- puts "DEBUG: #{cmd}"
106
- system(cmd) || (raise "Commmand failed: #{cmd}")
107
- end
117
+ repo_dir.bash cmd
108
118
  end
109
119
 
110
120
  def s3
@@ -113,12 +123,12 @@ module Gaffer
113
123
  end
114
124
 
115
125
  def remote
116
- bucket.keys('prefix' => 'ubuntu').map { |k| k.to_s }
126
+ bucket.keys.map { |k| k.to_s }
117
127
  end
118
128
 
119
129
  def local
120
130
  Dir.chdir(@root) do
121
- Dir["**/*"].reject { |f| File.directory?(f) }
131
+ Dir["**/*"].reject { |f| File.directory?(f) }
122
132
  end
123
133
  end
124
134
 
@@ -138,16 +148,31 @@ module Gaffer
138
148
 
139
149
  def write_local
140
150
  remote.each do |file|
141
- puts "* local write #{file}"
142
- write_file(file, bucket.get(file))
151
+ puts " * local write #{file}"
152
+ root_dir[file].parent.create
153
+ root_dir[file].write bucket.get(file)
143
154
  end
144
155
  end
145
156
 
146
157
  def write_remote
147
158
  local.each do |file|
148
- next if File.directory?("#{@root}/#{file}")
159
+ next if root_dir[file].dir?
160
+ new = last_accessed <= root_dir[file].last_accessed
161
+ next unless new
149
162
  puts "* remote write #{file}"
150
- bucket.put("#{file}", File.open("#{@root}/#{file}"), {}, file =~ /^ubuntu\/(db|conf)\// ? 'private' : 'public-read')
163
+ bucket_put file
164
+ end
165
+ end
166
+
167
+ def bucket_put(file)
168
+ bucket.put file, root_dir[file].read, {}, remote_perm(file)
169
+ end
170
+
171
+ def remote_perm(file)
172
+ if file =~ /^index|^ubuntu.db|^ubuntu.conf/
173
+ 'private'
174
+ else
175
+ 'public-read'
151
176
  end
152
177
  end
153
178
 
@@ -157,7 +182,7 @@ module Gaffer
157
182
  end
158
183
 
159
184
  def local_version
160
- File.read("#{@root}/ubuntu/conf/version").to_i rescue 0
185
+ conf_dir["version"].read.to_i rescue 0
161
186
  end
162
187
 
163
188
  def remote_version
@@ -168,8 +193,32 @@ module Gaffer
168
193
  write_version(local_version + 1)
169
194
  end
170
195
 
196
+ def root_dir
197
+ Rush["#{@root}/"]
198
+ end
199
+
200
+ def index_dir
201
+ root_dir["index/"]
202
+ end
203
+
204
+ def repo_dir
205
+ root_dir["ubuntu/"]
206
+ end
207
+
208
+ def conf_dir
209
+ repo_dir["conf/"]
210
+ end
211
+
212
+ def last_accessed
213
+ Time.at(conf_dir["last_accessed"].read.to_i) rescue Time.at(0)
214
+ end
215
+
216
+ def touch
217
+ conf_dir["last_accessed"].write Time.now.to_i
218
+ end
219
+
171
220
  def write_version(version)
172
- write_file "ubuntu/conf/version", version.to_s
221
+ conf_dir["version"].write version.to_s
173
222
  end
174
223
  end
175
224
  end
@@ -0,0 +1,17 @@
1
+ INSTALL
2
+
3
+ /var/lib/dpkg/tmp.ci/preinst install 0.0.3-4
4
+ /var/lib/dpkg/info/gaffer.postinst configure 0.0.3-4
5
+
6
+ UPGRADE
7
+
8
+ /var/lib/dpkg/info/gaffer.prerm upgrade 0.0.3-4
9
+ /var/lib/dpkg/tmp.ci/preinst upgrade 0.0.3-4
10
+ /var/lib/dpkg/info/gaffer.postrm upgrade 0.0.3-4
11
+ /var/lib/dpkg/info/gaffer.postinst configure 0.0.3-4
12
+
13
+ REMOVE
14
+
15
+ /var/lib/dpkg/info/gaffer.prerm remove
16
+ /var/lib/dpkg/info/gaffer.postrm remove
17
+
@@ -0,0 +1,11 @@
1
+ Source: <%= package %>
2
+ Section: unknown
3
+ Priority: extra
4
+ Maintainer: <%= maintainer %>
5
+ Version: <%= build_name %>
6
+ Homepage: <%= origin_url %>
7
+ Package: <%= package %>
8
+ Architecture: <%= arch %>
9
+ Depends: <%= depends %>
10
+ Description: <%= description %>
11
+ <%= readme %>
@@ -0,0 +1,11 @@
1
+ description "autogenerated init.conf from gaffer"
2
+
3
+ start on runlevel [2345]
4
+ stop on runlevel [!2345]
5
+
6
+ respawn
7
+
8
+ chdir /opt/<%= project %>
9
+
10
+ exec ./run > /var/log/<%= project %>.log 2>&1
11
+
@@ -0,0 +1,20 @@
1
+ #!/bin/bash
2
+
3
+ echo $0 $*
4
+
5
+ PACKAGE="<%= package %>"
6
+
7
+ if [ "$1" == "configure" ]; then
8
+ cd /opt/$PACKAGE
9
+ if [ -x configure ]; then
10
+ echo "Running /opt/$PACKAGE/configure"
11
+ ./configure $*
12
+ fi
13
+
14
+ if [ -f Gemfile ]; then
15
+ bundle install --deployment
16
+ fi
17
+ fi
18
+
19
+ exit 0
20
+
@@ -0,0 +1,14 @@
1
+ #!/bin/bash
2
+
3
+ echo $0 $*
4
+
5
+ PACKAGE="<%= package %>"
6
+
7
+ if [ "$1" == "remove" ]; then
8
+ userdel $PACKAGE
9
+ fi
10
+
11
+ #if [ "$1" == "upgrade" ]; then
12
+ #fi
13
+
14
+ exit 0
@@ -0,0 +1,15 @@
1
+ #!/bin/bash
2
+
3
+ echo $0 $*
4
+
5
+ PACKAGE="<%= package %>"
6
+
7
+ if [ "$1" == "install" ]; then
8
+ echo adding user $PACKAGE
9
+ useradd $PACKAGE --shell /bin/bash --home /opt/$PACKAGE --create-home
10
+ fi
11
+
12
+ #if [ "$1" == "upgrade" ]; then
13
+ #fi
14
+
15
+ exit 0
@@ -0,0 +1,13 @@
1
+ #!/bin/bash
2
+
3
+ echo $0 $*
4
+
5
+ PACKAGE="<%= package %>"
6
+
7
+ #if [ "$1" == "remove" ]; then
8
+ #fi
9
+
10
+ #if [ "$1" == "upgrade" ]; then
11
+ #fi
12
+
13
+ exit 0
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gaffer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Orion Henry
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-23 00:00:00 -08:00
18
+ date: 2010-12-13 00:00:00 -08:00
19
19
  default_executable: gaffer
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -90,6 +90,13 @@ files:
90
90
  - lib/gaffer/base.rb
91
91
  - lib/gaffer/deb.rb
92
92
  - lib/gaffer/repro.rb
93
+ - templates/INFO
94
+ - templates/control.erb
95
+ - templates/init.erb
96
+ - templates/postinst.erb
97
+ - templates/postrm.erb
98
+ - templates/preinst.erb
99
+ - templates/prerm.erb
93
100
  has_rdoc: true
94
101
  homepage: http://github.com/orionz/gaffer
95
102
  licenses: []