gz_release 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZjZkZWVhY2U2MTMyMzUxODFhZTMwZDEwMzJhZjY2Yzc1NTVlNjVkNg==
5
+ data.tar.gz: !binary |-
6
+ ZWFlYzA3MmYyY2RmYTMyYWNkOTlkN2MwZDMxNWQ2NTMwN2ZhZDhmYw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZmM3NzBjOTY1Y2FjYjRhOWMxZjA5Mjg5OTNmMTVmYTg0NzY4ODllNjQ5MzBj
10
+ NTZhMTZkYzNhMTllZGM1NTYwMGIwM2RhOTk1NWExZjJiMTk4NDE4ZTQ5MzA4
11
+ ZTliNmM3MTFiMDIzMGZkNWMyMGQ5NWFiMzA0MzM3NTg0YzA1N2Q=
12
+ data.tar.gz: !binary |-
13
+ ODMxMzg2NTk2OWE2YzFiYTIzN2ViNDA3N2RjNmJjYTI0YWU1MDMzZmUyYWE1
14
+ ZjVhOWY0YWUwYWNhMjZmMTU0ZTg1OTk5YjkyMTllZDVhNTljMzc1ZTQ0Yjkx
15
+ MjU5MjUxODk1Y2JlN2M0ZWRjOGQ3OWY5MTYyMDVkMzNjODc2YmQ=
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
@@ -0,0 +1,472 @@
1
+ # Common configuration.
2
+ AllCops:
3
+ # Include gemspec and Rakefile
4
+ Include:
5
+ - '**/*.gemspec'
6
+ - '**/Rakefile'
7
+ - '**/*.rake'
8
+ - '**/Gemfile'
9
+ Exclude:
10
+ - 'vendor/**'
11
+ RunRailsCops: true
12
+
13
+ # Indent private/protected/public as deep as method definitions
14
+ AccessModifierIndentation:
15
+ EnforcedStyle: outdent
16
+ SupportedStyles:
17
+ - outdent
18
+ - indent
19
+
20
+ # Indentation of `when`.
21
+ CaseIndentation:
22
+ IndentWhenRelativeTo: end
23
+ SupportedStyles:
24
+ - case
25
+ - end
26
+ IndentOneStep: false
27
+
28
+ ClassLength:
29
+ CountComments: false # count full line comments?
30
+ Max: 200
31
+
32
+ # Align ends correctly.
33
+ EndAlignment:
34
+ # The value `keyword` means that `end` should be aligned with the matching
35
+ # keyword (if, while, etc.).
36
+ # The value `variable` means that in assignments, `end` should be aligned
37
+ # with the start of the variable on the left hand side of `=`. In all other
38
+ # situations, `end` should still be aligned with the keyword.
39
+ AlignWith: variable
40
+ SupportedStyles:
41
+ - keyword
42
+ - variable
43
+
44
+ # Built-in global variables are allowed by default.
45
+ GlobalVars:
46
+ AllowedVariables: ['$1', '$2', '$3', '$4', '$5', '$6']
47
+
48
+ LineLength:
49
+ Max: 120
50
+
51
+ MethodLength:
52
+ CountComments: false # count full line comments?
53
+ Max: 20
54
+
55
+ NumericLiterals:
56
+ MinDigits: 10
57
+
58
+ SignalException:
59
+ EnforcedStyle: only_raise
60
+ SupportedStyles:
61
+ - only_raise
62
+ - only_fail
63
+ - semantic
64
+
65
+ SpaceBeforeBlockBraces:
66
+ EnforcedStyle: no_space
67
+ SupportedStyles:
68
+ - space
69
+ - no_space
70
+
71
+ SpaceInsideBlockBraces:
72
+ EnforcedStyle: no_space
73
+ SupportedStyles:
74
+ - space
75
+ - no_space
76
+ # Valid values are: space, no_space
77
+ EnforcedStyleForEmptyBraces: no_space
78
+ # Space between { and |. Overrides EnforcedStyle if there is a conflict.
79
+ SpaceBeforeBlockParameters: false
80
+
81
+ SpaceInsideHashLiteralBraces:
82
+ EnforcedStyle: no_space
83
+ EnforcedStyleForEmptyBraces: no_space
84
+ SupportedStyles:
85
+ - space
86
+ - no_space
87
+
88
+ # Checks whether the source file has a utf-8 encoding comment or not
89
+ Encoding:
90
+ EnforcedStyle: when_needed
91
+ SupportedStyles:
92
+ - when_needed
93
+ - always
94
+
95
+ WordArray:
96
+ MinSize: 0
97
+
98
+ ##########################################################################
99
+ ####################### DEFAULTS FROM RUBOCOP ############################
100
+ ##########################################################################
101
+
102
+ # Align the elements of a hash literal if they span more than one line.
103
+ AlignHash:
104
+ # Alignment of entries using hash rocket as separator. Valid values are:
105
+ #
106
+ # key - left alignment of keys
107
+ # 'a' => 2
108
+ # 'bb' => 3
109
+ # separator - alignment of hash rockets, keys are right aligned
110
+ # 'a' => 2
111
+ # 'bb' => 3
112
+ # table - left alignment of keys, hash rockets, and values
113
+ # 'a' => 2
114
+ # 'bb' => 3
115
+ EnforcedHashRocketStyle: key
116
+ # Alignment of entries using colon as separator. Valid values are:
117
+ #
118
+ # key - left alignment of keys
119
+ # a: 0
120
+ # bb: 1
121
+ # separator - alignment of colons, keys are right aligned
122
+ # a: 0
123
+ # bb: 1
124
+ # table - left alignment of keys and values
125
+ # a: 0
126
+ # bb: 1
127
+ EnforcedColonStyle: key
128
+ # Select whether hashes that are the last argument in a method call should be
129
+ # inspected? Valid values are:
130
+ #
131
+ # always_inspect - Inspect both implicit and explicit hashes.
132
+ # Registers and offence for:
133
+ # function(a: 1,
134
+ # b: 2)
135
+ # Registers an offence for:
136
+ # function({a: 1,
137
+ # b: 2})
138
+ # always_ignore - Ignore both implicit and explicit hashes.
139
+ # Accepts:
140
+ # function(a: 1,
141
+ # b: 2)
142
+ # Accepts:
143
+ # function({a: 1,
144
+ # b: 2})
145
+ # ignore_implicit - Ingore only implicit hashes.
146
+ # Accepts:
147
+ # function(a: 1,
148
+ # b: 2)
149
+ # Registers an offence for:
150
+ # function({a: 1,
151
+ # b: 2})
152
+ # ignore_explicit - Ingore only explicit hashes.
153
+ # Accepts:
154
+ # function({a: 1,
155
+ # b: 2})
156
+ # Registers an offence for:
157
+ # function(a: 1,
158
+ # b: 2)
159
+ EnforcedLastArgumentHashStyle: always_inspect
160
+ SupportedLastArgumentHashStyles:
161
+ - always_inspect
162
+ - always_ignore
163
+ - ignore_implicit
164
+ - ignore_explicit
165
+
166
+ AlignParameters:
167
+ # Alignment of parameters in multi-line method calls.
168
+ #
169
+ # The `with_first_parameter` style aligns the following lines along the same column
170
+ # as the first parameter.
171
+ #
172
+ # method_call(a,
173
+ # b)
174
+ #
175
+ # The `with_fixed_indentation` style alignes the following lines with one
176
+ # level of indenation relative to the start of the line with the method call.
177
+ #
178
+ # method_call(a,
179
+ # b)
180
+ EnforcedStyle: with_first_parameter
181
+ SupportedStyles:
182
+ - with_first_parameter
183
+ - with_fixed_indentation
184
+
185
+ # Allow safe assignment in conditions.
186
+ AssignmentInCondition:
187
+ AllowSafeAssignment: true
188
+
189
+ BlockNesting:
190
+ Max: 3
191
+
192
+ BracesAroundHashParameters:
193
+ EnforcedStyle: no_braces
194
+ SupportedStyles:
195
+ - braces
196
+ - no_braces
197
+
198
+ ClassAndModuleChildren:
199
+ # Checks the style of children definitions at classes and modules.
200
+ #
201
+ # Basically there are two different styles:
202
+ #
203
+ # `nested` - have each child on a separat line
204
+ # class Foo
205
+ # class Bar
206
+ # end
207
+ # end
208
+ #
209
+ # `compact` - combine definitions as much as possible
210
+ # class Foo::Bar
211
+ # end
212
+ #
213
+ # The compact style is only forced, for classes / modules with one child.
214
+ EnforcedStyle: nested
215
+ SupportedStyles:
216
+ - nested
217
+ - compact
218
+
219
+ # Align with the style guide.
220
+ CollectionMethods:
221
+ # Mapping from undesired method to desired_method
222
+ # e.g. to use `detect` over `find`:
223
+ #
224
+ # CollectionMethods:
225
+ # PreferredMethods:
226
+ # find: detect
227
+ PreferredMethods:
228
+ collect: 'map'
229
+ collect!: 'map!'
230
+ inject: 'reduce'
231
+ detect: 'find'
232
+ find_all: 'select'
233
+
234
+ # Checks formatting of special comments
235
+ CommentAnnotation:
236
+ Keywords:
237
+ - TODO
238
+ - FIXME
239
+ - OPTIMIZE
240
+ - HACK
241
+ - REVIEW
242
+
243
+ # Avoid complex methods.
244
+ CyclomaticComplexity:
245
+ Max: 6
246
+
247
+ # Multi-line method chaining should be done with leading dots.
248
+ DotPosition:
249
+ EnforcedStyle: leading
250
+ SupportedStyles:
251
+ - leading
252
+ - trailing
253
+
254
+ # Use empty lines between defs.
255
+ EmptyLineBetweenDefs:
256
+ # If true, this parameter means that single line method definitions don't
257
+ # need an empty line between them.
258
+ AllowAdjacentOneLineDefs: false
259
+
260
+ FileName:
261
+ Exclude:
262
+ - Rakefile
263
+ - Gemfile
264
+ - Capfile
265
+
266
+ # Checks use of for or each in multiline loops.
267
+ For:
268
+ EnforcedStyle: each
269
+ SupportedStyles:
270
+ - for
271
+ - each
272
+
273
+ # Enforce the method used for string formatting.
274
+ FormatString:
275
+ EnforcedStyle: format
276
+ SupportedStyles:
277
+ - format
278
+ - sprintf
279
+ - percent
280
+
281
+ HashSyntax:
282
+ EnforcedStyle: ruby19
283
+ SupportedStyles:
284
+ - ruby19
285
+ - hash_rockets
286
+
287
+ IfUnlessModifier:
288
+ MaxLineLength: 79
289
+
290
+ # Checks the indentation of the first key in a hash literal.
291
+ IndentHash:
292
+ # The value `special_inside_parentheses` means that hash literals with braces
293
+ # that have their opening brace on the same line as a surrounding opening
294
+ # round parenthesis, shall have their first key indented relative to the
295
+ # first position inside the parenthesis.
296
+ # The value `consistent` means that the indentation of the first key shall
297
+ # always be relative to the first position of the line where the opening
298
+ # brace is.
299
+ EnforcedStyle: special_inside_parentheses
300
+ SupportedStyles:
301
+ - special_inside_parentheses
302
+ - consistent
303
+
304
+ LambdaCall:
305
+ EnforcedStyle: call
306
+ SupportedStyles:
307
+ - call
308
+ - braces
309
+
310
+ MethodDefParentheses:
311
+ EnforcedStyle: require_parentheses
312
+ SupportedStyles:
313
+ - require_parentheses
314
+ - require_no_parentheses
315
+
316
+ MethodLength:
317
+ CountComments: false # count full line comments?
318
+ Max: 10
319
+
320
+ MethodName:
321
+ EnforcedStyle: snake_case
322
+ SupportedStyles:
323
+ - snake_case
324
+ - camelCase
325
+
326
+ ParameterLists:
327
+ Max: 5
328
+ CountKeywordArgs: true
329
+
330
+ # Allow safe assignment in conditions.
331
+ ParenthesesAroundCondition:
332
+ AllowSafeAssignment: true
333
+
334
+ PercentLiteralDelimiters:
335
+ PreferredDelimiters:
336
+ '%': ()
337
+ '%i': ()
338
+ '%q': ()
339
+ '%Q': ()
340
+ '%r': '{}'
341
+ '%s': ()
342
+ '%w': ()
343
+ '%W': ()
344
+ '%x': ()
345
+
346
+ PredicateName:
347
+ NamePrefixBlacklist:
348
+ - is_
349
+ - has_
350
+ - have_
351
+
352
+ RaiseArgs:
353
+ EnforcedStyle: exploded
354
+ SupportedStyles:
355
+ - compact # raise Exception.new(msg)
356
+ - exploded # raise Exception, msg
357
+
358
+
359
+ RedundantReturn:
360
+ # When true allows code like `return x, y`.
361
+ AllowMultipleReturnValues: false
362
+
363
+ RegexpLiteral:
364
+ # The maximum number of (escaped) slashes that a slash-delimited regexp is
365
+ # allowed to have. If there are more slashes, a %r regexp shall be used.
366
+ MaxSlashes: 1
367
+
368
+ Semicolon:
369
+ # Allow ; to separate several expressions on the same line.
370
+ AllowAsExpressionSeparator: false
371
+
372
+ SingleLineBlockParams:
373
+ Methods:
374
+ - reduce:
375
+ - a
376
+ - e
377
+ - inject:
378
+ - a
379
+ - e
380
+
381
+ SingleLineMethods:
382
+ AllowIfMethodIsEmpty: true
383
+
384
+ StringLiterals:
385
+ EnforcedStyle: single_quotes
386
+ SupportedStyles:
387
+ - single_quotes
388
+ - double_quotes
389
+
390
+ SpaceAroundEqualsInParameterDefault:
391
+ EnforcedStyle: space
392
+ SupportedStyles:
393
+ - space
394
+ - no_space
395
+
396
+ TrailingComma:
397
+ EnforcedStyleForMultiline: no_comma
398
+ SupportedStyles:
399
+ - comma
400
+ - no_comma
401
+
402
+ # TrivialAccessors doesn't require exact name matches and doesn't allow
403
+ # predicated methods by default.
404
+ TrivialAccessors:
405
+ ExactNameMatch: false
406
+ AllowPredicates: false
407
+ # Allows trivial writers that don't end in an equal sign. e.g.
408
+ #
409
+ # def on_exception(action)
410
+ # @on_exception=action
411
+ # end
412
+ # on_exception :restart
413
+ #
414
+ # Commonly used in DSLs
415
+ AllowDSLWriters: false
416
+ Whitelist:
417
+ - to_ary
418
+ - to_a
419
+ - to_c
420
+ - to_enum
421
+ - to_h
422
+ - to_hash
423
+ - to_i
424
+ - to_int
425
+ - to_io
426
+ - to_open
427
+ - to_path
428
+ - to_proc
429
+ - to_r
430
+ - to_regexp
431
+ - to_str
432
+ - to_s
433
+ - to_sym
434
+
435
+ VariableName:
436
+ EnforcedStyle: snake_case
437
+ SupportedStyles:
438
+ - snake_case
439
+ - camelCase
440
+
441
+ WhileUntilModifier:
442
+ MaxLineLength: 79
443
+
444
+ ##################### Rails ##################################
445
+
446
+ ActionFilter:
447
+ EnforcedStyle: action
448
+ SupportedStyles:
449
+ - action
450
+ - filter
451
+ Include:
452
+ - app/controllers/*.rb
453
+
454
+ DefaultScope:
455
+ Include:
456
+ - app/models/*.rb
457
+
458
+ HasAndBelongsToMany:
459
+ Include:
460
+ - app/models/*.rb
461
+
462
+ ReadWriteAttribute:
463
+ Include:
464
+ - app/models/*.rb
465
+
466
+ ScopeArgs:
467
+ Include:
468
+ - app/models/*.rb
469
+
470
+ Validation:
471
+ Include:
472
+ - app/models/*.rb
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gz_release.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Allen Madsen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # GzRelease
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'gz_release'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install gz_release
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/gz_release/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gz_release/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'gz_release'
8
+ spec.version = GzRelease::VERSION
9
+ spec.authors = ['Allen Madsen']
10
+ spec.email = ['blatyo@gmail.com']
11
+ spec.summary = 'Tasks for building docker images on a CI'
12
+ spec.description = 'Tasks for building docker images on a CI'
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}){|f| File.basename(f)}
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ end
@@ -0,0 +1,3 @@
1
+ require 'gz_release/version'
2
+ require 'gz_release/tasks'
3
+ require 'gz_release/test_helper'
@@ -0,0 +1,215 @@
1
+ module GzRelease
2
+ # Rake tasks for building a docker image
3
+ class Tasks
4
+ include Rake::DSL if defined? Rake::DSL
5
+
6
+ DOCKERFILE_PATH = File.expand_path('./Dockerfile')
7
+ DOCKER_CACHE_PATH = File.expand_path('~/.docker')
8
+ DOCKER_IMAGE_PATH = File.join(DOCKER_CACHE_PATH, 'image.tar')
9
+ TIMESTAMP_FORMAT = '%Y_%m_%d_%H_%M_%S'
10
+
11
+ BuildError = Class.new(StandardError)
12
+
13
+ class << self
14
+ def install(*args)
15
+ new(*args).install
16
+ end
17
+ end
18
+
19
+ attr_reader :image_name, :version
20
+
21
+ def initialize(options = {})
22
+ @image_name, @version = options.values_at(:image_name, :version)
23
+
24
+ raise BuildError, 'Image name not specified.' unless image_name
25
+ end
26
+
27
+ def install
28
+ namespace :release do
29
+ desc 'Creates a latest tag and version tag if available. Version is set in Rakefile'
30
+
31
+ desc 'Creates a git tag and image tag of the current timestamp.'
32
+ task(:tag_timestamp){tag_timestamp}
33
+
34
+ desc 'Pulls latest version of the image from dockerhub'
35
+ task(:pull){pull}
36
+
37
+ desc 'Loads ~/.docker/image.tar into docker cache. If file does not exist, pulls from dockerhub.'
38
+ task(:load){load}
39
+
40
+ desc 'Dumps docker cache into ~/.docker/image.tar'
41
+ task(:dump){dump}
42
+
43
+ desc 'Builds the docker image from generated Dockerfile'
44
+ task(:build){build}
45
+
46
+ namespace :tag do
47
+ desc 'Creates a tag for the branch for the docker image'
48
+ task(:branch){tag_branch}
49
+
50
+ desc 'Creates a tag for version specified in Rakefile for docker image'
51
+ task(:version){tag_version}
52
+
53
+ desc 'Creates latest tag for the docker image'
54
+ task(:latest){tag_latest}
55
+
56
+ desc 'Creates timestamp tag for the docker image and git repo'
57
+ task(:timestamp){tag_timestamp}
58
+ end
59
+
60
+ namespace :push do
61
+ desc 'Pushes docker image tagged as current git branch.'
62
+ task(branch: :'release:tag:branch'){push_branch}
63
+
64
+ desc 'Pushes docker image tagged as version specified in Rakefile'
65
+ task(version: :'release:tag:version'){push_version}
66
+
67
+ desc 'Pushes docker image tagged as latest'
68
+ task(latest: :'release:tag:latest'){push_latest}
69
+
70
+ desc 'Pushes docker image and git tag tagged by the timestamp.'
71
+ task(timestamp: :'release:tag:timestamp'){push_timestamp}
72
+ end
73
+ end
74
+ end
75
+
76
+ def pull
77
+ run("docker pull #{image_version}")
78
+ rescue BuildError
79
+ puts 'Skipping pull. Note, this should generally only happen on first build.'
80
+ end
81
+
82
+ def load
83
+ if File.exist?(DOCKER_IMAGE_PATH)
84
+ run("docker load -i #{DOCKER_IMAGE_PATH}")
85
+ else
86
+ pull
87
+ end
88
+ end
89
+
90
+ def dump
91
+ require 'fileutils'
92
+
93
+ FileUtils.mkdir_p(DOCKER_CACHE_PATH)
94
+ run("docker save #{image_latest} > #{DOCKER_IMAGE_PATH}")
95
+ end
96
+
97
+ def build
98
+ run("docker build -t #{image_sha} .")
99
+ end
100
+
101
+ def tag(tag_name)
102
+ run("docker tag -f #{image_sha} #{tag_name}")
103
+ end
104
+
105
+ def git_tag(tag_name)
106
+ run("git tag -a #{tag_name} -m 'Tagging #{tag_name} from #{branch}(#{sha})' #{sha}")
107
+ end
108
+
109
+ def push(tag_name)
110
+ login
111
+
112
+ run("docker push #{tag_name}")
113
+ end
114
+
115
+ def git_push(tag_name)
116
+ run("git push origin #{tag_name}")
117
+ end
118
+
119
+ def login
120
+ email = ENV['DOCKER_EMAIL']
121
+ user = ENV['DOCKER_USER']
122
+ password = ENV['DOCKER_PASSWORD']
123
+
124
+ errors = []
125
+ errors << 'Missing DOCKER_EMAIL environment variable.' unless email
126
+ errors << 'Missing DOCKER_USER environment variable.' unless user
127
+ errors << 'Missing DOCKER_PASSWORD environment variable.' unless password
128
+ raise BuildError, "Encountered the following errors:\n #{errors.join("\n")}" if errors.any?
129
+
130
+ run("docker login -e #{email} -u #{user} -p #{password}", display_command: false)
131
+ end
132
+
133
+ def run(command, options = {display_command: true})
134
+ puts command if options[:display_command]
135
+ system(command)
136
+
137
+ raise BuildError, 'There was a problem executing this command.' unless $CHILD_STATUS == 0
138
+ end
139
+
140
+ # SHA
141
+ def image_sha
142
+ "#{image_name}:#{sha}"
143
+ end
144
+
145
+ def sha
146
+ @sha ||= `git rev-parse HEAD`.strip
147
+ end
148
+
149
+ # Branch
150
+ def tag_branch
151
+ tag(image_branch)
152
+ end
153
+
154
+ def push_branch
155
+ push(image_branch)
156
+ end
157
+
158
+ def image_branch
159
+ "#{image_name}:#{branch}"
160
+ end
161
+
162
+ def branch
163
+ @branch ||= ENV['CIRCLE_BRANCH'] ? ENV['CIRCLE_BRANCH'] : `git rev-parse --abbrev-ref HEAD`.strip
164
+ end
165
+
166
+ # Version
167
+ def tag_version
168
+ return unless version
169
+
170
+ tag(image_version)
171
+ end
172
+
173
+ def push_version
174
+ return unless version
175
+
176
+ push(image_version)
177
+ end
178
+
179
+ def image_version
180
+ "#{image_name}:#{version}"
181
+ end
182
+
183
+ # Latest
184
+ def tag_latest
185
+ tag(image_latest)
186
+ end
187
+
188
+ def push_latest
189
+ push(image_latest)
190
+ end
191
+
192
+ def image_latest
193
+ "#{image_name}:latest"
194
+ end
195
+
196
+ # Timestamp
197
+ def tag_timestamp
198
+ git_tag(timestamp)
199
+ tag(image_timestamp)
200
+ end
201
+
202
+ def push_timestamp
203
+ git_push(timestamp)
204
+ push(image_timestamp)
205
+ end
206
+
207
+ def image_timestamp
208
+ "#{image_name}:#{timestamp}"
209
+ end
210
+
211
+ def timestamp
212
+ @timestamp ||= Time.now.utc.strftime(TIMESTAMP_FORMAT)
213
+ end
214
+ end
215
+ end
@@ -0,0 +1,14 @@
1
+ module GzDocker
2
+ # Allows testing of a docker image
3
+ module TestHelper
4
+ def docker(image, command)
5
+ require 'ostruct'
6
+ result = OpenStruct.new
7
+
8
+ result.output = `docker run #{image} #{command}`
9
+ result.status = $CHILD_STATUS.exitstatus
10
+
11
+ result
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ # Version
2
+ module GzRelease
3
+ VERSION = '0.0.1'
4
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gz_release
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Allen Madsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Tasks for building docker images on a CI
42
+ email:
43
+ - blatyo@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .rubocop.yml
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - gz_release.gemspec
55
+ - lib/gz_release.rb
56
+ - lib/gz_release/tasks.rb
57
+ - lib/gz_release/test_helper.rb
58
+ - lib/gz_release/version.rb
59
+ homepage: ''
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.4.5
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Tasks for building docker images on a CI
83
+ test_files: []
84
+ has_rdoc: