build-labels 0.0.33 → 0.0.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58802674d1c9dae0283ad5041f6f0e0b7e43aa860efb13b926af1eacabfbfb67
4
- data.tar.gz: 4f19adaa08a50333be156a39ccd0de31d34014bb7763e44e32f14c79e052718c
3
+ metadata.gz: a62dff9e164a3749d73437662ef1a249abd71a02050ca03e25351ca1d1a41010
4
+ data.tar.gz: 91cc2502095199151d2b172b6c93c32734789c62297827e61d062e89da0b47a9
5
5
  SHA512:
6
- metadata.gz: 5d16ddd47182b2e9ed312994c76b4bd85977a8ea039d31091b9ab43fada09c62dcd2e4b80e9fee47041bbe46c75bf20f0c2d1286e70c938eefa64851ecdb9c00
7
- data.tar.gz: 27b56f7f2a00251daff74eb32c45991d2052fa57c460cc85c73017554a21efeb6f8cb8a5e688418cc8b58ebf0ca72356adf5ee0608ed2b441148d5a339d8baf5
6
+ metadata.gz: de0cf08be70b97b79bad86dc198a0e0908cc8c4e69444b4d223c1f4172f5de5e2cfde7ea625ba0e5298597810529956b93d8ee13be7f6f54f60b44038fe6ddea
7
+ data.tar.gz: f0c7ea0621cd5b80fa0001aef381e10b737fe9e1e4658c7571d48997e0c1968f71698d98532f3191dfcd85a87b1b902d036414a378775432c456c355c9444718
data/bin/helm-push ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ lib = File.expand_path('../lib', __dir__)
3
+ $LOAD_PATH << lib
4
+ #$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'helm-push/command_line'
7
+ require 'helm-push/command_push'
8
+
9
+ HelmPush::CommandLine.run ARGV
@@ -0,0 +1,78 @@
1
+ require_relative '../version'
2
+ require 'optparse'
3
+ # frozen_string_literal: true
4
+ require_relative '../build-labels/yaml_merge'
5
+
6
+ module HelmPush
7
+ module CommandLine
8
+ COMMANDS = {}
9
+
10
+ class << self
11
+ def load_env(filename)
12
+ File.read(filename).lines.map(&:strip).grep_v(/^\s*#/).reject(&:empty?)
13
+ .map {
14
+ if _1 =~ /([^=]+)=(.*)/
15
+ a, k,v = Regexp.last_match.to_a
16
+ ENV[k] = v
17
+ [k,v]
18
+ else
19
+ nil
20
+ end
21
+ }.compact.to_h
22
+ rescue =>e
23
+ puts "Load env error: #{e.message}"
24
+ raise "Invalid #{filename} file"
25
+ end
26
+
27
+ def run(args)
28
+ params = {}
29
+
30
+ ARGV << '-h' if ARGV.empty?
31
+ OptionParser.new do |o|
32
+ o.version = "#{BuildLabels::Builder::VERSION}"
33
+
34
+ usage = [
35
+ 'helm-push -c docker-compose.yml -version-mask=\d+\.\d+\.\d+',
36
+ 'cat docker-compose.yml | helm-push',
37
+ 'helm-push < docker-compose.yml'
38
+ ]
39
+ o.banner = "Version: #{o.version}\nUsage:\n\t#{usage.join "\n\t"}"
40
+ o.separator ''
41
+ o.separator 'Commands:'
42
+ COMMANDS.each { |name, cmd| o.separator "#{' ' * 5}#{name} - #{cmd.help}" }
43
+
44
+ o.separator ''
45
+ o.separator 'Options:'
46
+
47
+ # in all caps are required
48
+ o.on('-c', '--compose COMPOSE_FILE', 'Compose file')
49
+ o.on('-m', '--version-mask VERSION_MASK', 'Version mask')
50
+ o.on('-e', '--env FILE', 'Load .build_info FILE') { load_env _1 }
51
+ o.on('-n', '--no-env', 'Do not process env variables') { true }
52
+ COMMANDS.values.select{_1.options(o) if _1.respond_to? :options }
53
+
54
+ o.on('-h', '--help') { puts o; exit }
55
+ rest = o.parse! args, into: params
56
+
57
+
58
+ compose_text = File.read(params[:compose]) if params[:compose]
59
+ compose_text ||= STDIN.read unless $stdin.tty?
60
+
61
+ result = YamlMerge.parse_and_process_yaml compose_text
62
+ compose_text = YamlMerge.deep_copy_without_aliases result
63
+
64
+ # eval $(grep -v -e '^#' .build_info | xargs -I {} echo export \'{}\') && echo $CI_COMMIT_AUTHOR
65
+ rest = ['push'] if rest.empty?
66
+
67
+ rest.each do |command|
68
+ raise "Unknown command: #{command}" unless COMMANDS.key?(command.to_sym)
69
+ COMMANDS[command.to_sym].run params, compose_text
70
+ end
71
+ rescue => e
72
+ puts e.message
73
+ exit 1
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,29 @@
1
+ require_relative 'command_line'
2
+
3
+ HelmPush::CommandLine::COMMANDS[:push] = Class.new do
4
+ def run(params, compose)
5
+ raise 'Compose file not defined' unless compose
6
+ raise 'Version mask not defined' unless params[:'version-mask']
7
+
8
+ compose['services'].each do |service_name, svc|
9
+ next unless svc['build']
10
+ unless svc['build']['tags']
11
+ svc['build']['tags'] = [svc['image']]
12
+ end
13
+
14
+ svc['build']['tags'].each do |full_tag|
15
+ _image, tag = full_tag.split(':')
16
+ if tag =~ Regexp.new(params[:'version-mask'])
17
+ puts "Package and Push Helm for the image #{full_tag}"
18
+
19
+ system "helm package helm/#{service_name} --app-version #{tag} --version #{tag} --destination helm/" or raise("helm package failed")
20
+ system "curl -u ${HELM_USER}:${HELM_PASSWORD} --upload-file helm/#{service_name}-#{tag}.tgz ${HELM_HOST}" or raise("helm push failed")
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ def help = 'Package and Push Helm for each service'
27
+ end.new
28
+
29
+
data/lib/helm-push.rb ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "helm-push/push"
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module BuildLabels
2
2
  class Builder
3
- VERSION = '0.0.33'
3
+ VERSION = '0.0.35'
4
4
  end
5
5
  end
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.33
4
+ version: 0.0.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artyom B
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-10 00:00:00.000000000 Z
11
+ date: 2025-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -98,10 +98,12 @@ description: ''
98
98
  email: author@email.address
99
99
  executables:
100
100
  - build-labels
101
+ - helm-push
101
102
  extensions: []
102
103
  extra_rdoc_files: []
103
104
  files:
104
105
  - bin/build-labels
106
+ - bin/helm-push
105
107
  - examples/Dockerfile
106
108
  - examples/common-compose.yml
107
109
  - examples/simple-compose.yml
@@ -115,6 +117,9 @@ files:
115
117
  - lib/build-labels/command_to_compose.rb
116
118
  - lib/build-labels/command_to_dockerfiles.rb
117
119
  - lib/build-labels/yaml_merge.rb
120
+ - lib/helm-push.rb
121
+ - lib/helm-push/command_line.rb
122
+ - lib/helm-push/command_push.rb
118
123
  - lib/version.rb
119
124
  homepage: https://rubygems.org/gems/build-labels
120
125
  licenses: