pipedawg 0.2.2 → 0.3.0

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: b1df968015369cc666fc521d546b3194e82f04ec28b9a2473dbc2452b5c37780
4
- data.tar.gz: 5afe211e7fb69ac10808af059e02dc5706c882ad86d2309901d2f943e0ec6a6d
3
+ metadata.gz: 114b51a7224d92e384383b3485e96547a250ae90cc64a89250d7a45ff3ae35c0
4
+ data.tar.gz: 98eac24c50bdeb4282077b32e45afc87f9e8f3db01f47c5b837d36a9a3866ca0
5
5
  SHA512:
6
- metadata.gz: 7348909008c56e40d693f388da3b6eb8210c380a357c87c5e1cf906932a9c66246af77a9328f0746d70b2213943c95f73256d835b5163ca17348a9068998a5ac
7
- data.tar.gz: 9f3b4d44c1e2e5e2b955ecd135ccdcfd100d15fbcc137f40dca0af2797a0aa3637444e2e75ec910ac428a953147d883ecb24414c6e10bba17dfb0d40f3881b70
6
+ metadata.gz: 1504e970a5b8b629f5b95a92a8fd9edc4685d3d98adbf3f94631a0c0d4b12beaadb83a30b5337ba9ad03310956ce1c9e7924f6c04f968bca8287e0c45a69eb5e
7
+ data.tar.gz: 80e24f54810711abc38902ab44aae67499372f9d73c265aedc82d6d6bc2c3dd7d26f230195a435580674502bb40563e67810be18ebbb51bd2e35c4b735888fb0
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pipedawg
4
+ # helm_copy_job class
5
+ class HelmCopyJob < Job
6
+ attr_accessor :helm_opts
7
+
8
+ def initialize(name = 'build', opts = {}, helm_opts = {})
9
+ @helm_opts = {
10
+ chart: name,
11
+ destinations: [{ user: nil, password: nil, url: nil }],
12
+ helm: 'helm',
13
+ image: { entrypoint: [''], name: 'alpine/helm' },
14
+ password: nil, url: nil, user: nil, version: nil
15
+ }.merge(helm_opts)
16
+ super name, opts
17
+ update
18
+ end
19
+
20
+ def update
21
+ opts[:image] = helm_opts[:image] if helm_opts[:image]
22
+ opts[:script] = [] + pull + (helm_opts[:destinations].map { |d| push(d) }).flatten(1)
23
+ end
24
+
25
+ private
26
+
27
+ def pull
28
+ case helm_opts[:url]
29
+ when nil
30
+ []
31
+ when %r{^oci://}
32
+ pull_oci
33
+ else
34
+ pull_classic
35
+ end
36
+ end
37
+
38
+ def push(destination)
39
+ case destination[:url]
40
+ when nil
41
+ []
42
+ when %r{^oci://}
43
+ push_oci(destination)
44
+ else
45
+ push_classic(destination)
46
+ end
47
+ end
48
+
49
+ def pull_oci # rubocop:disable Metrics/AbcSize
50
+ script = []
51
+ if helm_opts[:url] && helm_opts[:chart] && helm_opts[:version]
52
+ script = ['export HELM_EXPERIMENTAL_OCI=1']
53
+ script << login_oci(helm_opts) if helm_opts[:user] && helm_opts[:password]
54
+ script << "\"#{helm_opts[:helm]}\" pull \"#{helm_opts[:url]}/#{helm_opts[:chart]}\" --version \"#{helm_opts[:version]}\"" # rubocop:disable Layout/LineLength
55
+ end
56
+ script
57
+ end
58
+
59
+ def push_oci(destination) # rubocop:disable Metrics/AbcSize
60
+ script = []
61
+ if destination[:url] && helm_opts[:chart] && helm_opts[:version]
62
+ script = ['export HELM_EXPERIMENTAL_OCI=1']
63
+ script << login_oci(destination) if destination[:user] && destination[:password]
64
+ script << "\"#{helm_opts[:helm]}\" push \"#{helm_opts[:chart]}-#{helm_opts[:version]}.tgz\" \"#{destination[:url]}\"" # rubocop:disable Layout/LineLength
65
+ end
66
+ script
67
+ end
68
+
69
+ def login_oci(login_opts)
70
+ require 'uri'
71
+ "echo \"#{login_opts[:password]}\" | \"#{helm_opts[:helm]}\" registry login --username \"#{login_opts[:user]}\" --password-stdin \"#{URI(login_opts[:url]).host}\"" # rubocop:disable Layout/LineLength
72
+ end
73
+
74
+ def pull_classic # rubocop:disable Metrics/AbcSize
75
+ script = []
76
+ if helm_opts[:url] && helm_opts[:chart] && helm_opts[:version]
77
+ suffix = login_classic(helm_opts)
78
+ script << "\"#{helm_opts[:helm]}\" repo add source \"#{helm_opts[:url]}\"#{suffix}"
79
+ script << "\"#{helm_opts[:helm]}\" repo update"
80
+ script << "\"#{helm_opts[:helm]}\" pull \"source/#{helm_opts[:chart]}\" --version \"#{helm_opts[:version]}\""
81
+ end
82
+ script
83
+ end
84
+
85
+ def push_classic(destination)
86
+ script = []
87
+ if destination[:url] && helm_opts[:chart] && helm_opts[:version]
88
+ script << plugin_classic
89
+ suffix = login_classic(destination)
90
+ script << "\"#{helm_opts[:helm]}\" cm-push \"#{helm_opts[:chart]}-#{helm_opts[:version]}.tgz\" \"#{destination[:url]}\"#{suffix}" # rubocop:disable Layout/LineLength
91
+ end
92
+ script
93
+ end
94
+
95
+ def login_classic(login_opts)
96
+ if login_opts[:user] && login_opts[:password]
97
+ " --username \"#{login_opts[:user]}\" --password \"#{login_opts[:password]}\""
98
+ else
99
+ ''
100
+ end
101
+ end
102
+
103
+ def plugin_classic
104
+ "\"#{helm_opts[:helm]}\" plugin list | grep -q cm-push || \"#{helm_opts[:helm]}\" plugin install https://github.com/chartmuseum/helm-push"
105
+ end
106
+ end
107
+ end
@@ -23,7 +23,7 @@ module Pipedawg
23
23
  flags: [],
24
24
  ignore_paths: [],
25
25
  insecure_registries: [],
26
- kaniko_image: {
26
+ image: {
27
27
  entrypoint: [''],
28
28
  name: 'gcr.io/kaniko-project/executor:debug'
29
29
  },
@@ -40,7 +40,7 @@ module Pipedawg
40
40
 
41
41
  def update # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
42
42
  require 'json'
43
- opts[:image] = kaniko_opts[:image]
43
+ opts[:image] = kaniko_opts[:image] if kaniko_opts[:image]
44
44
  script = ["echo #{kaniko_opts[:config].to_json.inspect} > \"#{kaniko_opts[:config_file]}\""]
45
45
  cert_copies = Array(kaniko_opts[:trusted_ca_cert_source_files]).map do |cert|
46
46
  "cat \"#{cert}\" >> \"#{kaniko_opts[:trusted_ca_cert_target_file]}\""
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pipedawg
4
- VERSION = '0.2.2'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/pipedawg.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'pipedawg/job'
4
+ require 'pipedawg/helm_copy_job'
4
5
  require 'pipedawg/kaniko_job'
5
6
  require 'pipedawg/pipeline'
6
7
  require 'pipedawg/version'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pipedawg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - harbottle
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-01 00:00:00.000000000 Z
11
+ date: 2022-02-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Generate GitLab CI pipelines.
14
14
  email:
@@ -20,6 +20,7 @@ files:
20
20
  - LICENSE.txt
21
21
  - README.md
22
22
  - lib/pipedawg.rb
23
+ - lib/pipedawg/helm_copy_job.rb
23
24
  - lib/pipedawg/job.rb
24
25
  - lib/pipedawg/kaniko_job.rb
25
26
  - lib/pipedawg/pipeline.rb