build-labels 0.0.20 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 719ae14a1673df0a68553fd77a508710602c56d1f21ad91580d7630549ac4e5d
4
- data.tar.gz: 70ae3fde84121c4491d07ca7468ef431fba2722ecebbfd98e9d2226ec7670a41
3
+ metadata.gz: ece715acff32709330b757daf3bde7df56b686cfdb48ae95274fde1cea6c629f
4
+ data.tar.gz: 92de637e65532323c3ffb810c2eb1c5c4dba08724dde1c18f593b6c97a07933b
5
5
  SHA512:
6
- metadata.gz: 6c4d95157d6df97ec7a2d9a1240abd7c2fd942656b89edb3e1a474d4419bfe4e2d37b06748a0b165272c17498f1e545f01def418d7c553545936d0a59ec15827
7
- data.tar.gz: ec133f72a9dea369b906640a02827f9c7d5292a8ddd7e4af4638d9b45b01aade9b422bdd167893ae113c47395f031ec883424914074b2b209587d6910184028f
6
+ metadata.gz: bd5e5a24c460f2bb57f41a9206c45d99b4cf97dc2088f34ad760e287be95b611554d02fb3f6a728b2533b8f12e70da0e763464c3fb711cafea84530a15cdf2ba
7
+ data.tar.gz: 0a5b06118df2116a5e76d15393a0c55ae34bddfd5ede44d4fda9c09e19d714dc346c598b23d594c6be2953cdb01d387c82ad25b12129174b935d6be3f3b66bba
@@ -54,31 +54,23 @@ module BuildLabels
54
54
  yield ns, values
55
55
  end
56
56
  end
57
-
58
- def extend_compose(compose_text)
59
-
60
- result = YamlMerge::parse_and_process_yaml compose_text
61
- compose = YamlMerge::deep_copy_without_aliases result
62
-
63
- # compose = YAML.load compose_text
64
-
65
- compose['services'].each do |name, service|
66
- service.delete_if {|k, v| !%w[image build].include? k }
57
+ def extend_compose(compose)
58
+ compose['services'].transform_values! do |service|
67
59
  next unless service['build']
68
- if service['build'].class == String
69
- service['build'] = { 'context' => service['build'] }
70
- end
60
+ service.slice!('image', 'build')
61
+ service['build'] = { 'context' => service['build'] } if service['build'].is_a?(String)
71
62
  service['build']['labels'] ||= []
72
- add_namespace :dc, 'docker.service'
73
- self.dc.name = name
63
+ add_namespace(:dc, 'docker.service')
64
+ self.dc.name = service['name']
74
65
 
75
66
  each_labels do |ns, values|
76
- values.each_pair do |k,v|
67
+ values.each do |k, v|
77
68
  service['build']['labels'] << "#{ns}.#{k}=#{v}" unless v.to_s.empty?
78
69
  end
79
70
  end
80
- end
81
- compose['services'].delete_if do |name, svc| ! svc.key?('build') end
71
+ service
72
+ end.compact!
73
+
82
74
  puts compose.to_yaml
83
75
  end
84
76
  end
@@ -5,32 +5,21 @@ BuildLabels::CommandLine::COMMANDS[:cache] = Class.new do
5
5
  parser.on('', '--cache-from CACHE FROM', 'type=[local,registry] ... ')
6
6
  parser.on('', '--cache-to CACHE TO', 'type=[local,registry] ...')
7
7
  end
8
- def run(builder, params, compose_text)
9
- compose = YAML.load compose_text
8
+ def run(builder, params, compose)
10
9
  compose['services'].each do |service_name, service|
11
10
  next unless service['build']
12
11
 
13
- if service['build'].class == String
14
- service['build'] = { 'context' => service['build'] }
15
- end
16
- # p params
17
- # registry = params[:registry]
18
- image = service['image'].gsub( /:.*/, '')
19
- if params[:'cache-from']
20
- service['build']['cache_from'] = [ params[:'cache-from'] % {image: image, service_name: service_name} ]
21
- else
22
- service['build']['cache_from'] = [ "type=registry,ref=#{image}:cache" ]
23
- end
12
+ service['build'] = { 'context' => service['build'] } if service['build'].is_a?(String)
24
13
 
25
- if params[:'cache-to']
26
- service['build']['cache_to'] = [ params[:'cache-to'] % {image: image, service_name: service_name} ]
27
- else
28
- service['build']['cache_to'] = [ "type=registry,ref=#{image}:cache,mode=max" ]
29
- end
30
- # # - type=local,src=./.cache
31
- # # - type=local,dest=./.cache,mode=max
14
+ image = service['image'].split(':').first
15
+ cache_from = params[:'cache-from'] || "type=registry,ref=#{image}:cache"
16
+ cache_to = params[:'cache-to'] || "type=registry,ref=#{image}:cache,mode=max"
17
+
18
+ service['build']['cache_from'] = [format(cache_from, image: image, service_name: service_name)]
19
+ service['build']['cache_to'] = [format(cache_to, image: image, service_name: service_name)]
32
20
  end
33
- compose_text.replace compose.to_yaml
21
+ # - type=local,src=./.cache
22
+ # - type=local,dest=./.cache,mode=max
34
23
  end
35
24
 
36
25
  def help = 'Add cache section'
@@ -55,6 +55,8 @@ module BuildLabels
55
55
  compose_text = File.read(params[:compose]) if params[:compose]
56
56
  compose_text ||= STDIN.read unless $stdin.tty?
57
57
 
58
+ result = YamlMerge.parse_and_process_yaml compose_text
59
+ compose_text = YamlMerge.deep_copy_without_aliases result
58
60
  builder = Builder.new
59
61
 
60
62
  # eval $(grep -v -e '^#' .build_info | xargs -I {} echo export \'{}\') && echo $CI_COMMIT_AUTHOR
@@ -5,12 +5,8 @@ BuildLabels::CommandLine::COMMANDS[:set_version] = Class.new do
5
5
  # parser.on('', '--set-version', '')
6
6
  # end
7
7
 
8
- def run(builder, params, compose_text)
9
- raise 'Compose file not defined' unless compose_text
10
-
11
- result = YamlMerge::parse_and_process_yaml compose_text
12
- compose = YamlMerge::deep_copy_without_aliases result
13
- # compose = YAML.load compose_text
8
+ def run(builder, params, compose)
9
+ raise 'Compose file not defined' unless compose
14
10
 
15
11
  compose_dir = params[:compose] ? File.dirname(params[:compose]) : '.'
16
12
 
@@ -24,9 +20,14 @@ BuildLabels::CommandLine::COMMANDS[:set_version] = Class.new do
24
20
  image = svc['image'].gsub( /:.*/, '')
25
21
  tag = svc['image'][/:(.*)/, 1]
26
22
  svc['image'] = "#{image}:#{current_version}#{tag ? "-" + tag : ""}"
23
+ next unless svc['build']['tags']
24
+ svc['build']['tags'] = svc['build']['tags'].map do |t|
25
+ image = t.gsub( /:.*/, '')
26
+ tag = t[/:(.*)/, 1]
27
+ "#{image}:#{current_version}#{tag ? "-" + tag : ""}"
28
+ end
27
29
  end
28
30
 
29
- compose_text.replace compose.to_yaml
30
31
  end
31
32
 
32
33
  def help = 'Add version tag from [docker_context]/.version file to image'
@@ -1,10 +1,10 @@
1
1
  require_relative 'command_line'
2
2
 
3
3
  BuildLabels::CommandLine::COMMANDS[:to_compose] = Class.new do
4
- def run(builder, params, compose_text)
5
- raise 'Compose file not defined' unless compose_text
4
+ def run(builder, params, compose)
5
+ raise 'Compose file not defined' unless compose
6
6
 
7
- builder.extend_compose compose_text
7
+ builder.extend_compose compose
8
8
  end
9
9
 
10
10
  def help = 'Add labels to all build sections of docker-compose file'
@@ -1,13 +1,10 @@
1
1
  require_relative 'command_line'
2
2
 
3
3
  BuildLabels::CommandLine::COMMANDS[:to_dockerfiles] = Class.new do
4
- def run(builder, params, compose_text)
5
- raise 'Compose file not defined' unless compose_text
4
+ def run(builder, params, compose)
5
+ raise 'Compose file not defined' unless compose
6
6
  compose_dir = params[:compose] ? File.dirname(params[:compose]) : '.'
7
7
 
8
- result = YamlMerge::parse_and_process_yaml compose_text
9
- compose = YamlMerge::deep_copy_without_aliases result
10
- # compose = YAML.load compose_text
11
8
 
12
9
  compose['services'].each do |name, svc|
13
10
  next unless svc['build']
data/lib/version.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  module BuildLabels
2
2
  class Builder
3
- VERSION = '0.0.20'
3
+ VERSION = '0.0.21'
4
4
  end
5
5
  end
6
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: build-labels
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.20
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artyom B
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-12 00:00:00.000000000 Z
11
+ date: 2024-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -121,7 +121,7 @@ licenses:
121
121
  - Nonstandard
122
122
  metadata:
123
123
  source_code_uri: https://github.com/artyomb/build-labels
124
- post_install_message:
124
+ post_install_message:
125
125
  rdoc_options: []
126
126
  require_paths:
127
127
  - lib
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  version: '0'
138
138
  requirements: []
139
139
  rubygems_version: 3.3.7
140
- signing_key:
140
+ signing_key:
141
141
  specification_version: 4
142
142
  summary: Generate docker build image labels from CI variables
143
143
  test_files: []