build-labels 0.0.19 → 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/build-labels +1 -0
- data/lib/build-labels/builder.rb +10 -48
- data/lib/build-labels/command_cache.rb +10 -21
- data/lib/build-labels/command_line.rb +3 -0
- data/lib/build-labels/command_set_version.rb +36 -0
- data/lib/build-labels/command_to_compose.rb +3 -3
- data/lib/build-labels/command_to_dockerfiles.rb +2 -5
- data/lib/build-labels/yaml_merge.rb +2 -2
- data/lib/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ece715acff32709330b757daf3bde7df56b686cfdb48ae95274fde1cea6c629f
|
4
|
+
data.tar.gz: 92de637e65532323c3ffb810c2eb1c5c4dba08724dde1c18f593b6c97a07933b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd5e5a24c460f2bb57f41a9206c45d99b4cf97dc2088f34ad760e287be95b611554d02fb3f6a728b2533b8f12e70da0e763464c3fb711cafea84530a15cdf2ba
|
7
|
+
data.tar.gz: 0a5b06118df2116a5e76d15393a0c55ae34bddfd5ede44d4fda9c09e19d714dc346c598b23d594c6be2953cdb01d387c82ad25b12129174b935d6be3f3b66bba
|
data/bin/build-labels
CHANGED
data/lib/build-labels/builder.rb
CHANGED
@@ -4,36 +4,6 @@ require 'ostruct'
|
|
4
4
|
require 'pp'
|
5
5
|
require_relative 'yaml_merge'
|
6
6
|
|
7
|
-
class MyYAMLTree < Psych::Visitors::YAMLTree
|
8
|
-
class Registrar
|
9
|
-
# record object for future, using '@_yaml_anchor_name' rather
|
10
|
-
# than object_id if it exists
|
11
|
-
def register target, node
|
12
|
-
anchor_name = target.instance_variable_get('@_yaml_anchor_name') || target.object_id
|
13
|
-
@obj_to_node[anchor_name] = node
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# check to see if this object has been seen before
|
18
|
-
def accept target
|
19
|
-
if anchor_name = target.instance_variable_get('@_yaml_anchor_name')
|
20
|
-
if @st.key? anchor_name
|
21
|
-
oid = anchor_name
|
22
|
-
node = @st[oid]
|
23
|
-
anchor = oid.to_s
|
24
|
-
node.anchor = anchor
|
25
|
-
return @emitter.alias anchor
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# accept is a pretty big method, call super to avoid copying
|
30
|
-
# it all here. super will handle the cases when it's an object
|
31
|
-
# that's been seen but doesn't have '@_yaml_anchor_name' set
|
32
|
-
super
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
7
|
module BuildLabels
|
38
8
|
|
39
9
|
class Builder
|
@@ -84,31 +54,23 @@ module BuildLabels
|
|
84
54
|
yield ns, values
|
85
55
|
end
|
86
56
|
end
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
result = YamlMerge::parse_and_process_yaml compose_text
|
91
|
-
compose = YamlMerge::deep_copy_without_aliases result
|
92
|
-
|
93
|
-
# compose = YAML.load compose_text
|
94
|
-
|
95
|
-
compose['services'].each do |name, service|
|
96
|
-
service.delete_if {|k, v| !%w[image build].include? k }
|
57
|
+
def extend_compose(compose)
|
58
|
+
compose['services'].transform_values! do |service|
|
97
59
|
next unless service['build']
|
98
|
-
|
99
|
-
|
100
|
-
end
|
60
|
+
service.slice!('image', 'build')
|
61
|
+
service['build'] = { 'context' => service['build'] } if service['build'].is_a?(String)
|
101
62
|
service['build']['labels'] ||= []
|
102
|
-
add_namespace
|
103
|
-
self.dc.name = name
|
63
|
+
add_namespace(:dc, 'docker.service')
|
64
|
+
self.dc.name = service['name']
|
104
65
|
|
105
66
|
each_labels do |ns, values|
|
106
|
-
values.
|
67
|
+
values.each do |k, v|
|
107
68
|
service['build']['labels'] << "#{ns}.#{k}=#{v}" unless v.to_s.empty?
|
108
69
|
end
|
109
70
|
end
|
110
|
-
|
111
|
-
|
71
|
+
service
|
72
|
+
end.compact!
|
73
|
+
|
112
74
|
puts compose.to_yaml
|
113
75
|
end
|
114
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,
|
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'].
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
21
|
+
# - type=local,src=./.cache
|
22
|
+
# - type=local,dest=./.cache,mode=max
|
34
23
|
end
|
35
24
|
|
36
25
|
def help = 'Add cache section'
|
@@ -21,6 +21,7 @@ module BuildLabels
|
|
21
21
|
puts "Load env error: #{e.message}"
|
22
22
|
raise "Invalid #{filename} file"
|
23
23
|
end
|
24
|
+
|
24
25
|
def run(args)
|
25
26
|
params = {}
|
26
27
|
|
@@ -54,6 +55,8 @@ module BuildLabels
|
|
54
55
|
compose_text = File.read(params[:compose]) if params[:compose]
|
55
56
|
compose_text ||= STDIN.read unless $stdin.tty?
|
56
57
|
|
58
|
+
result = YamlMerge.parse_and_process_yaml compose_text
|
59
|
+
compose_text = YamlMerge.deep_copy_without_aliases result
|
57
60
|
builder = Builder.new
|
58
61
|
|
59
62
|
# eval $(grep -v -e '^#' .build_info | xargs -I {} echo export \'{}\') && echo $CI_COMMIT_AUTHOR
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'command_line'
|
2
|
+
|
3
|
+
BuildLabels::CommandLine::COMMANDS[:set_version] = Class.new do
|
4
|
+
# def options(parser)
|
5
|
+
# parser.on('', '--set-version', '')
|
6
|
+
# end
|
7
|
+
|
8
|
+
def run(builder, params, compose)
|
9
|
+
raise 'Compose file not defined' unless compose
|
10
|
+
|
11
|
+
compose_dir = params[:compose] ? File.dirname(params[:compose]) : '.'
|
12
|
+
|
13
|
+
compose['services'].each do |name, svc|
|
14
|
+
next unless svc['build']
|
15
|
+
versionfile = svc['build'].is_a?(String) ? './' : svc['build']['context']
|
16
|
+
versionfile = File.join versionfile, '.version'
|
17
|
+
versionfile = File.expand_path versionfile, compose_dir
|
18
|
+
next unless File.exist? versionfile
|
19
|
+
current_version = File.read(versionfile).strip
|
20
|
+
image = svc['image'].gsub( /:.*/, '')
|
21
|
+
tag = svc['image'][/:(.*)/, 1]
|
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
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def help = 'Add version tag from [docker_context]/.version file to image'
|
34
|
+
end.new
|
35
|
+
|
36
|
+
|
@@ -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,
|
5
|
-
raise 'Compose file not defined' unless
|
4
|
+
def run(builder, params, compose)
|
5
|
+
raise 'Compose file not defined' unless compose
|
6
6
|
|
7
|
-
builder.extend_compose
|
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,
|
5
|
-
raise 'Compose file not defined' unless
|
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']
|
@@ -96,10 +96,10 @@ if File.expand_path($0) == File.expand_path(__FILE__)
|
|
96
96
|
extra: [a, b]
|
97
97
|
YAML
|
98
98
|
|
99
|
-
result = YamlMerge
|
99
|
+
result = YamlMerge.parse_and_process_yaml(yaml_string)
|
100
100
|
puts result.inspect
|
101
101
|
|
102
|
-
data_without_aliases = YamlMerge
|
102
|
+
data_without_aliases = YamlMerge.deep_copy_without_aliases(result)
|
103
103
|
puts data_without_aliases.to_yaml
|
104
104
|
|
105
105
|
# puts Psych.dump(data_without_aliases, indentation: 2, line_width: -1)
|
data/lib/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artyom B
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-07-
|
11
|
+
date: 2024-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- lib/build-labels/command_gitlab.rb
|
112
112
|
- lib/build-labels/command_line.rb
|
113
113
|
- lib/build-labels/command_print.rb
|
114
|
+
- lib/build-labels/command_set_version.rb
|
114
115
|
- lib/build-labels/command_to_compose.rb
|
115
116
|
- lib/build-labels/command_to_dockerfiles.rb
|
116
117
|
- lib/build-labels/yaml_merge.rb
|