build-labels 0.0.19 → 0.0.20
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 +1 -31
- data/lib/build-labels/command_line.rb +1 -0
- data/lib/build-labels/command_set_version.rb +35 -0
- data/lib/build-labels/yaml_merge.rb +2 -2
- data/lib/version.rb +2 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 719ae14a1673df0a68553fd77a508710602c56d1f21ad91580d7630549ac4e5d
|
4
|
+
data.tar.gz: 70ae3fde84121c4491d07ca7468ef431fba2722ecebbfd98e9d2226ec7670a41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c4d95157d6df97ec7a2d9a1240abd7c2fd942656b89edb3e1a474d4419bfe4e2d37b06748a0b165272c17498f1e545f01def418d7c553545936d0a59ec15827
|
7
|
+
data.tar.gz: ec133f72a9dea369b906640a02827f9c7d5292a8ddd7e4af4638d9b45b01aade9b422bdd167893ae113c47395f031ec883424914074b2b209587d6910184028f
|
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
|
@@ -96,7 +66,7 @@ module BuildLabels
|
|
96
66
|
service.delete_if {|k, v| !%w[image build].include? k }
|
97
67
|
next unless service['build']
|
98
68
|
if service['build'].class == String
|
99
|
-
service['build'] = { 'context'
|
69
|
+
service['build'] = { 'context' => service['build'] }
|
100
70
|
end
|
101
71
|
service['build']['labels'] ||= []
|
102
72
|
add_namespace :dc, 'docker.service'
|
@@ -0,0 +1,35 @@
|
|
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_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
|
14
|
+
|
15
|
+
compose_dir = params[:compose] ? File.dirname(params[:compose]) : '.'
|
16
|
+
|
17
|
+
compose['services'].each do |name, svc|
|
18
|
+
next unless svc['build']
|
19
|
+
versionfile = svc['build'].is_a?(String) ? './' : svc['build']['context']
|
20
|
+
versionfile = File.join versionfile, '.version'
|
21
|
+
versionfile = File.expand_path versionfile, compose_dir
|
22
|
+
next unless File.exist? versionfile
|
23
|
+
current_version = File.read(versionfile).strip
|
24
|
+
image = svc['image'].gsub( /:.*/, '')
|
25
|
+
tag = svc['image'][/:(.*)/, 1]
|
26
|
+
svc['image'] = "#{image}:#{current_version}#{tag ? "-" + tag : ""}"
|
27
|
+
end
|
28
|
+
|
29
|
+
compose_text.replace compose.to_yaml
|
30
|
+
end
|
31
|
+
|
32
|
+
def help = 'Add version tag from [docker_context]/.version file to image'
|
33
|
+
end.new
|
34
|
+
|
35
|
+
|
@@ -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.20
|
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-
|
11
|
+
date: 2024-07-12 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
|
@@ -120,7 +121,7 @@ licenses:
|
|
120
121
|
- Nonstandard
|
121
122
|
metadata:
|
122
123
|
source_code_uri: https://github.com/artyomb/build-labels
|
123
|
-
post_install_message:
|
124
|
+
post_install_message:
|
124
125
|
rdoc_options: []
|
125
126
|
require_paths:
|
126
127
|
- lib
|
@@ -136,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
137
|
version: '0'
|
137
138
|
requirements: []
|
138
139
|
rubygems_version: 3.3.7
|
139
|
-
signing_key:
|
140
|
+
signing_key:
|
140
141
|
specification_version: 4
|
141
142
|
summary: Generate docker build image labels from CI variables
|
142
143
|
test_files: []
|