rbld 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ require 'logger-better'
2
+ require 'docker'
3
+
4
+ module Rebuild
5
+ module Logger
6
+ def rbld_log
7
+ if @rbld_logger.nil?
8
+ if ENV['RBLD_LOG_LEVEL'].nil?
9
+ @rbld_logger = NullLogger.new
10
+ else
11
+ @rbld_logger = ::Logger::Better.new ENV['RBLD_LOG_FILE'] || STDOUT
12
+ @rbld_logger.level = ENV['RBLD_LOG_LEVEL'].to_sym
13
+ end
14
+ end
15
+ @rbld_logger
16
+ end
17
+ end
18
+ end
19
+
20
+ include Rebuild::Logger
21
+
22
+ #Hook up docker API logs
23
+ #for the higher log level
24
+ if ENV['RBLD_LOG_LEVEL'] && (ENV['RBLD_LOG_LEVEL'].to_sym == :debug)
25
+ Docker::logger = rbld_log
26
+ end
@@ -0,0 +1,66 @@
1
+ require 'colorize'
2
+ require 'io/console'
3
+
4
+ module Rebuild
5
+ module Printer
6
+ class RbldPrinter
7
+ private
8
+
9
+ def self.progress_print(msg)
10
+ STDOUT.print msg.light_green
11
+ STDOUT.flush
12
+ end
13
+
14
+ public
15
+
16
+ def self.error(msg)
17
+ puts
18
+ puts " ERROR: #{msg}".light_red
19
+ puts
20
+ end
21
+
22
+ def self.warning(msg)
23
+ puts "WARNING: #{msg}".light_yellow
24
+ end
25
+
26
+ def self.progress(msg)
27
+ puts
28
+ puts "#{msg}".light_green
29
+ end
30
+
31
+ def self.trace(msg)
32
+ puts "#{msg}".light_black
33
+ end
34
+
35
+ def self.raw_trace(msg)
36
+ STDOUT.write( "#{msg}".light_black )
37
+ STDOUT.flush
38
+ end
39
+
40
+ def self.inplace_trace(msg)
41
+ raw_trace( msg[0...IO.console.winsize[1]] + "\r" ) \
42
+ if STDOUT.tty?
43
+ end
44
+
45
+ def self.progress_start(msg)
46
+ puts
47
+ progress_print "#{msg} [.."
48
+ end
49
+
50
+ def self.progress_tick
51
+ progress_print '.'
52
+ end
53
+
54
+ def self.progress_end
55
+ progress_print '.]'
56
+ puts
57
+ end
58
+ end
59
+
60
+ def rbld_print
61
+ RbldPrinter
62
+ end
63
+ end
64
+ end
65
+
66
+ include Rebuild::Printer
@@ -0,0 +1,100 @@
1
+ require 'docker_registry2'
2
+ require_relative 'rbld_log'
3
+ require_relative 'rbld_utils'
4
+
5
+ module Rebuild
6
+ module Registry
7
+ extend Rebuild::Utils::Errors
8
+
9
+ rebuild_errors \
10
+ EntryNameParsingError: 'Internal registry name parsing failed: %s',
11
+ APIConnectionError: 'Failed to access registry at %s'
12
+
13
+ class Entry
14
+ NAME_PFX = 'rbe-'
15
+ TAG_PFX = '-rt-'
16
+ private_constant :NAME_PFX, :TAG_PFX
17
+
18
+ def initialize(name = nil, tag = nil, remote = nil)
19
+ @name, @tag, @remote = name, tag, remote
20
+
21
+ @url = Rebuild::Utils::FullImageName.new( "#{@remote}/#{NAME_PFX}#{@name}#{TAG_PFX}#{@tag}", \
22
+ 'initial' )
23
+
24
+ @wildcard = "#{NAME_PFX}#{@name}" + \
25
+ ( @tag.to_s.empty? ? '' : "#{TAG_PFX}#{@tag}" )
26
+ end
27
+
28
+ def self.by_internal_name( int_name )
29
+ m = int_name.match(/^#{NAME_PFX}(.*)#{TAG_PFX}(.*)/)
30
+ raise EntryNameParsingError, int_name unless m
31
+ new( *m.captures )
32
+ end
33
+
34
+ attr_reader :name, :tag, :url, :wildcard
35
+ end
36
+
37
+ class API
38
+ def initialize(remote, api_accessor = DockerRegistry)
39
+ @remote = remote
40
+ rbld_log.info( "Connecting to registry #{@remote}" )
41
+ begin
42
+ @api = api_accessor.connect("http://#{@remote}")
43
+ rescue StandardError
44
+ raise APIConnectionError, @remote
45
+ end
46
+ end
47
+
48
+ def search(name = nil, tag = nil)
49
+ wildcard = Entry.new( name, tag, @remote ).wildcard
50
+ rbld_log.info( "Searching for #{wildcard}" )
51
+ @api.search( wildcard ).map do |internal_name|
52
+ rbld_log.debug( "Found #{internal_name}" )
53
+ parse_entry( internal_name )
54
+ end.compact
55
+ end
56
+
57
+ def publish(name, tag, api_obj)
58
+ url = Entry.new( name, tag, @remote ).url
59
+
60
+ api_obj.tag( repo: url.repo, tag: url.tag )
61
+
62
+ begin
63
+ rbld_log.info( "Pushing #{url.full}" )
64
+ api_obj.push(nil, :repo_tag => url.full) do |log|
65
+ progress = JSON.parse(log)["progress"]
66
+ rbld_print.inplace_trace(progress) if progress
67
+ end
68
+ ensure
69
+ api_obj.remove( :name => url.full )
70
+ end
71
+ end
72
+
73
+ def deploy(name, tag, api_class = Docker::Image)
74
+ url = Entry.new( name, tag, @remote ).url
75
+
76
+ begin
77
+ rbld_log.info( "Pulling #{url.full}" )
78
+ img = api_class.create(:fromImage => url.full) do |log|
79
+ progress = JSON.parse(log)["progress"]
80
+ rbld_print.inplace_trace(progress) if progress
81
+ end
82
+ yield img
83
+ ensure
84
+ img.remove( :name => url.full ) if img
85
+ end
86
+ end
87
+
88
+ private
89
+
90
+ def parse_entry(internal_name)
91
+ begin
92
+ Entry.by_internal_name( internal_name )
93
+ rescue EntryNameParsingError => msg
94
+ rbld_log.warn( msg )
95
+ return nil
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,54 @@
1
+ module Rebuild
2
+ module Utils
3
+
4
+ class Error < RuntimeError
5
+ def initialize(fmt, msg)
6
+ if not fmt.to_s.empty?
7
+ if msg.kind_of?(Array)
8
+ super( sprintf( fmt, *msg ) )
9
+ elsif
10
+ super( sprintf( fmt, msg ) )
11
+ end
12
+ else
13
+ super( msg )
14
+ end
15
+ end
16
+
17
+ def self.msg_format(fmt)
18
+ class_eval( "def initialize(msg = nil); super( \"#{fmt}\", msg ); end" )
19
+ end
20
+ end
21
+
22
+ class FullImageName
23
+ def initialize(repo, tag)
24
+ @repo = repo
25
+ @tag = tag
26
+ @full = "#{repo}:#{tag}"
27
+ end
28
+
29
+ def to_s
30
+ @full
31
+ end
32
+
33
+ attr_reader :repo, :tag, :full
34
+ alias_method :name, :repo
35
+ end
36
+
37
+ module Errors
38
+ def rebuild_errors(definitions)
39
+ definitions.each_pair do |name, msg_fmt|
40
+ self.const_set(name.to_s,
41
+ Class.new(Rebuild::Utils::Error) do
42
+ msg_format msg_fmt
43
+ private
44
+ def self.defined_by_rebuild_error_helper
45
+ true
46
+ end
47
+ end)
48
+ end
49
+ end
50
+
51
+ alias rebuild_error rebuild_errors
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,19 @@
1
+ CONF_DIR = File.join( Dir.home, '.rbld' )
2
+ RBLD_CONF = File.expand_path( 'rebuild.conf', CONF_DIR )
3
+
4
+ CONF_CONTENTS = <<TEXT
5
+ #REMOTE_NAME=origin
6
+ #REMOTE_origin="10.0.110.110:5000"
7
+ TEXT
8
+
9
+ task default: [RBLD_CONF]
10
+
11
+ file RBLD_CONF do
12
+ FileUtils.mkdir_p( CONF_DIR )
13
+
14
+ unless File.exist?( RBLD_CONF )
15
+ open(RBLD_CONF, 'w') do |f|
16
+ f.write CONF_CONTENTS
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,294 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbld
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Dmitry Fleytman
8
+ autorequire:
9
+ bindir: cli/bin
10
+ cert_chain: []
11
+ date: 2016-12-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: logger-better
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: docker-api
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.32'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 1.32.1
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '1.32'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 1.32.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: docker_registry2
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.3.0
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.3.0
75
+ - !ruby/object:Gem::Dependency
76
+ name: parseconfig
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.0'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 1.0.8
85
+ type: :runtime
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '1.0'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 1.0.8
95
+ - !ruby/object:Gem::Dependency
96
+ name: require_all
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '1.3'
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 1.3.3
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '1.3'
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: 1.3.3
115
+ - !ruby/object:Gem::Dependency
116
+ name: rake
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '11.2'
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 11.2.2
125
+ type: :runtime
126
+ prerelease: false
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '11.2'
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: 11.2.2
135
+ - !ruby/object:Gem::Dependency
136
+ name: travis
137
+ requirement: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - "~>"
140
+ - !ruby/object:Gem::Version
141
+ version: '1.8'
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 1.8.2
145
+ type: :development
146
+ prerelease: false
147
+ version_requirements: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '1.8'
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: 1.8.2
155
+ - !ruby/object:Gem::Dependency
156
+ name: aruba
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - "~>"
160
+ - !ruby/object:Gem::Version
161
+ version: 0.14.1
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: 0.14.0
165
+ type: :development
166
+ prerelease: false
167
+ version_requirements: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - "~>"
170
+ - !ruby/object:Gem::Version
171
+ version: 0.14.1
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: 0.14.0
175
+ - !ruby/object:Gem::Dependency
176
+ name: ptools
177
+ requirement: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - "~>"
180
+ - !ruby/object:Gem::Version
181
+ version: '1.3'
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ version: 1.3.3
185
+ type: :development
186
+ prerelease: false
187
+ version_requirements: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - "~>"
190
+ - !ruby/object:Gem::Version
191
+ version: '1.3'
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: 1.3.3
195
+ - !ruby/object:Gem::Dependency
196
+ name: retriable
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '2.1'
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ version: 2.1.0
205
+ type: :development
206
+ prerelease: false
207
+ version_requirements: !ruby/object:Gem::Requirement
208
+ requirements:
209
+ - - "~>"
210
+ - !ruby/object:Gem::Version
211
+ version: '2.1'
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: 2.1.0
215
+ - !ruby/object:Gem::Dependency
216
+ name: rspec
217
+ requirement: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - "~>"
220
+ - !ruby/object:Gem::Version
221
+ version: '3.5'
222
+ - - ">="
223
+ - !ruby/object:Gem::Version
224
+ version: 3.5.0
225
+ type: :development
226
+ prerelease: false
227
+ version_requirements: !ruby/object:Gem::Requirement
228
+ requirements:
229
+ - - "~>"
230
+ - !ruby/object:Gem::Version
231
+ version: '3.5'
232
+ - - ">="
233
+ - !ruby/object:Gem::Version
234
+ version: 3.5.0
235
+ description: Zero-dependency, reproducible build environments
236
+ email: rbld-devel@rbld.io
237
+ executables:
238
+ - rbld
239
+ extensions:
240
+ - tools/rebuild-conf/Rakefile
241
+ extra_rdoc_files: []
242
+ files:
243
+ - cli/bin/rbld
244
+ - cli/lib/bootstrap/re-build-bootstrap-utils
245
+ - cli/lib/bootstrap/re-build-entry-point
246
+ - cli/lib/bootstrap/re-build-env-prepare
247
+ - cli/lib/bootstrap/rebuild.rc
248
+ - cli/lib/commands/rbld_checkout.rb
249
+ - cli/lib/commands/rbld_commit.rb
250
+ - cli/lib/commands/rbld_create.rb
251
+ - cli/lib/commands/rbld_deploy.rb
252
+ - cli/lib/commands/rbld_list.rb
253
+ - cli/lib/commands/rbld_load.rb
254
+ - cli/lib/commands/rbld_modify.rb
255
+ - cli/lib/commands/rbld_publish.rb
256
+ - cli/lib/commands/rbld_rm.rb
257
+ - cli/lib/commands/rbld_run.rb
258
+ - cli/lib/commands/rbld_save.rb
259
+ - cli/lib/commands/rbld_search.rb
260
+ - cli/lib/commands/rbld_status.rb
261
+ - cli/lib/rbld_commands.rb
262
+ - cli/lib/rbld_config.rb
263
+ - cli/lib/rbld_engine.rb
264
+ - cli/lib/rbld_log.rb
265
+ - cli/lib/rbld_print.rb
266
+ - cli/lib/rbld_registry.rb
267
+ - cli/lib/rbld_utils.rb
268
+ - tools/rebuild-conf/Rakefile
269
+ homepage: http://rbld.io/
270
+ licenses:
271
+ - Apache-2.0
272
+ metadata: {}
273
+ post_install_message: Thanks for installing rebuild. Run `rbld help` for CLI reference.
274
+ rdoc_options: []
275
+ require_paths:
276
+ - cli/lib
277
+ required_ruby_version: !ruby/object:Gem::Requirement
278
+ requirements:
279
+ - - ">="
280
+ - !ruby/object:Gem::Version
281
+ version: 2.0.0
282
+ required_rubygems_version: !ruby/object:Gem::Requirement
283
+ requirements:
284
+ - - ">="
285
+ - !ruby/object:Gem::Version
286
+ version: '0'
287
+ requirements: []
288
+ rubyforge_project:
289
+ rubygems_version: 2.4.8
290
+ signing_key:
291
+ specification_version: 4
292
+ summary: rbld-1.0.0
293
+ test_files: []
294
+ has_rdoc: