build-labels 0.0.33 → 0.0.34

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: b7f38a5e08d98961d415f090e8846bdf3f0776d9690549c8b847a808714e2cdf
4
+ data.tar.gz: 1cb2c8e61d01c5fbc532b3a63e4799ec7f513828d5bd6f22d516e7fa1e2daa10
5
5
  SHA512:
6
- metadata.gz: 5d16ddd47182b2e9ed312994c76b4bd85977a8ea039d31091b9ab43fada09c62dcd2e4b80e9fee47041bbe46c75bf20f0c2d1286e70c938eefa64851ecdb9c00
7
- data.tar.gz: 27b56f7f2a00251daff74eb32c45991d2052fa57c460cc85c73017554a21efeb6f8cb8a5e688418cc8b58ebf0ca72356adf5ee0608ed2b441148d5a339d8baf5
6
+ metadata.gz: 2a93353db3ae189858f7f6c112fb719875981fcf92cf3170f95714c459a5dfbd68aca793adfa9814dcb868e731ea739e516bcda7bd92757429b2b00f9b029571
7
+ data.tar.gz: 20af055d52143ef37bafd53a1277b19b30a89781acd0a7500217d97e80074c76af7681a71c1d39d97956912d2667b86f7499af2b9de000d4f75539893faf7930
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.34'
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.34
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
@@ -102,6 +102,7 @@ extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
104
  - bin/build-labels
105
+ - bin/helm-push
105
106
  - examples/Dockerfile
106
107
  - examples/common-compose.yml
107
108
  - examples/simple-compose.yml
@@ -115,6 +116,9 @@ files:
115
116
  - lib/build-labels/command_to_compose.rb
116
117
  - lib/build-labels/command_to_dockerfiles.rb
117
118
  - lib/build-labels/yaml_merge.rb
119
+ - lib/helm-push.rb
120
+ - lib/helm-push/command_line.rb
121
+ - lib/helm-push/command_push.rb
118
122
  - lib/version.rb
119
123
  homepage: https://rubygems.org/gems/build-labels
120
124
  licenses: