pipedawg 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b54013025d872389b0b01408fb78b39c63fcfc9b0d7b06d87559ae3c88e0f538
4
- data.tar.gz: 1d0242a83a9dc068accbe107369950d8bdc4d040e0706bd00cd9b1f40e6112de
3
+ metadata.gz: 041e80c36e4a1f30695c0d60233c8fcc3261ac734dee7d0770dde11ad1e0ac71
4
+ data.tar.gz: ee48577c9c00e3ef4f76cabe22895d435b26bb10cd6dd4ff5a950dbaebaaf5bc
5
5
  SHA512:
6
- metadata.gz: b5fb6c7365461b7d70ffdcc96cf18c7fafb686433683f236748735be10916e9f21e7635e3b1b7744d9d4010c2c57497423a0bca645f519f9b2bd968dbdaf6394
7
- data.tar.gz: 338a5bb1a1fa767fc5610ee92a534eb37e41289e39c18106c8ae3b549011e09f198fc936cf2dded73fe96c50c4dbdaf84f4d96e02b5020aaab5f84bba3b87856
6
+ metadata.gz: 83e2ef040fbdbec747968ca61d58079e720dd32cea77fd0dc0b39f451dab618e247cf85617f6f6f6dbaf881263e90c4b2f7b90b3df96d5c60e6a338db5b007d1
7
+ data.tar.gz: 34cccd812da30055338afc7368a5f62f46c0df7ba8e7dc7c21e9590fdcd4a5d398df30be22f0e5aac6c7a9a3944f4683b1b96be79da9b75276aca89ee13e8d89
@@ -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
data/lib/pipedawg/job.rb CHANGED
@@ -13,7 +13,7 @@ module Pipedawg
13
13
  image: { name: 'ruby:2.5' },
14
14
  needs: [],
15
15
  retry: nil,
16
- rules: [],
16
+ rules: nil,
17
17
  script: [],
18
18
  stage: 'build',
19
19
  tags: []
@@ -9,82 +9,93 @@ module Pipedawg
9
9
  @kaniko_opts = {
10
10
  build_args: {},
11
11
  config: {
12
- '$CI_REGISTRY': {
13
- username: '$CI_REGISTRY_USER',
14
- password: '$CI_REGISTRY_PASSWORD'
15
- }
12
+ '$CI_REGISTRY': { username: '$CI_REGISTRY_USER', password: '$CI_REGISTRY_PASSWORD' }
16
13
  },
17
- config_file: '/kaniko/.docker/config.json',
18
- context: '${CI_PROJECT_DIR}',
19
- destinations: [],
20
- dockerfile: 'Dockerfile',
21
- executor: '/kaniko/executor',
22
- external_files: {},
23
- flags: [],
24
- ignore_paths: [],
25
- insecure_registries: [],
26
- kaniko_image: {
27
- entrypoint: [''],
28
- name: 'gcr.io/kaniko-project/executor:debug'
29
- },
30
- options: {},
31
- registry_certificates: {},
32
- registry_mirrors: [],
33
- skip_tls_verify_registry: [],
34
- trusted_ca_cert_source_files: [],
14
+ config_file: '/kaniko/.docker/config.json', context: '${CI_PROJECT_DIR}',
15
+ destinations: [], dockerfile: 'Dockerfile', executor: '/kaniko/executor',
16
+ external_files: {}, flags: [], ignore_paths: [], insecure_registries: [],
17
+ image: { entrypoint: [''], name: 'gcr.io/kaniko-project/executor:debug' },
18
+ options: {}, registry_certificates: {}, registry_mirrors: [],
19
+ skip_tls_verify_registry: [], trusted_ca_cert_source_files: [],
35
20
  trusted_ca_cert_target_file: '/kaniko/ssl/certs/ca-certificates.crt'
36
21
  }.merge(kaniko_opts)
37
22
  super name, opts
38
23
  update
39
24
  end
40
25
 
41
- def update # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
26
+ def update # rubocop:disable Metrics/AbcSize
42
27
  require 'json'
43
- opts[:image] = kaniko_opts[:image]
44
- script = ["echo #{kaniko_opts[:config].to_json.inspect} > \"#{kaniko_opts[:config_file]}\""]
45
- cert_copies = Array(kaniko_opts[:trusted_ca_cert_source_files]).map do |cert|
28
+ opts[:image] = kaniko_opts[:image] if kaniko_opts[:image]
29
+ opts[:script] = config + cert_copies + file_copies + Array(kaniko_cmd)
30
+ end
31
+
32
+ private
33
+
34
+ def config
35
+ ["echo #{kaniko_opts[:config].to_json.inspect} > \"#{kaniko_opts[:config_file]}\""]
36
+ end
37
+
38
+ def cert_copies
39
+ Array(kaniko_opts[:trusted_ca_cert_source_files]).map do |cert|
46
40
  "cat \"#{cert}\" >> \"#{kaniko_opts[:trusted_ca_cert_target_file]}\""
47
41
  end
48
- script.concat cert_copies
49
- file_copies = kaniko_opts[:external_files].map do |source, dest|
42
+ end
43
+
44
+ def file_copies
45
+ kaniko_opts[:external_files].map do |source, dest|
50
46
  "cp \"#{source}\" \"#{kaniko_opts[:context]}/#{dest}\""
51
47
  end
52
- script.concat file_copies
48
+ end
49
+
50
+ def kaniko_cmd # rubocop:disable Metrics/AbcSize
51
+ ["\"#{kaniko_opts[:executor]}\" --context \"#{kaniko_opts[:context]}\"",
52
+ "--dockerfile \"#{kaniko_opts[:dockerfile]}\"", flags, options, build_args,
53
+ ignore_paths, insecure_registries, registry_certificates, registry_mirrors,
54
+ destinations, skip_tls_verify_registries].reject(&:empty?).join(' ')
55
+ end
56
+
57
+ def flags
53
58
  flags = kaniko_opts[:flags].clone
54
59
  flags << 'no-push' if kaniko_opts[:destinations].empty?
55
- flags_cli = flags.uniq.map { |f| "--#{f}" }.join(' ')
56
- options_cli = kaniko_opts[:options].map { |k, v| "--#{k}=\"#{v}\"" }.join(' ')
57
- build_args_cli = kaniko_opts[:build_args].map { |k, v| "--build-arg #{k}=\"#{v}\"" }.join(' ')
58
- ignore_paths_cli = Array(kaniko_opts[:ignore_paths]).map { |p| "--ignore-path #{p}" }.join(' ')
59
- insecure_registries_cli = Array(kaniko_opts[:insecure_registries]).map do |r|
60
+ flags.uniq.map { |f| "--#{f}" }.join(' ')
61
+ end
62
+
63
+ def options
64
+ kaniko_opts[:options].map { |k, v| "--#{k}=\"#{v}\"" }.join(' ')
65
+ end
66
+
67
+ def build_args
68
+ kaniko_opts[:build_args].map { |k, v| "--build-arg #{k}=\"#{v}\"" }.join(' ')
69
+ end
70
+
71
+ def ignore_paths
72
+ Array(kaniko_opts[:ignore_paths]).map { |p| "--ignore-path #{p}" }.join(' ')
73
+ end
74
+
75
+ def insecure_registries
76
+ Array(kaniko_opts[:insecure_registries]).map do |r|
60
77
  "--insecure-registry #{r}"
61
78
  end.join(' ')
62
- registry_certificates_cli = kaniko_opts[:registry_certificates].map do |k, v|
63
- "----registry-certificate #{k}=\"#{v}\""
79
+ end
80
+
81
+ def registry_certificates
82
+ kaniko_opts[:registry_certificates].map do |k, v|
83
+ "--registry-certificate #{k}=\"#{v}\""
64
84
  end.join(' ')
65
- registry_mirrors_cli = Array(kaniko_opts[:registry_mirrors]).map { |r| "--registry-mirror #{r}" }.join(' ')
66
- skip_tls_verify_registrys_cli = Array(kaniko_opts[:skip_tls_verify_registry]).map do |r|
85
+ end
86
+
87
+ def registry_mirrors
88
+ Array(kaniko_opts[:registry_mirrors]).map { |r| "--registry-mirror #{r}" }.join(' ')
89
+ end
90
+
91
+ def destinations
92
+ kaniko_opts[:destinations].map { |d| "--destination #{d}" }.join(' ')
93
+ end
94
+
95
+ def skip_tls_verify_registries
96
+ Array(kaniko_opts[:skip_tls_verify_registry]).map do |r|
67
97
  "--skip-tls-verify-registry #{r}"
68
98
  end.join(' ')
69
- destinations_cli = kaniko_opts[:destinations].map { |d| "--destination #{d}" }.join(' ')
70
- kaniko_cmds = [
71
- "\"#{kaniko_opts[:executor]}\"",
72
- '--context',
73
- "\"#{kaniko_opts[:context]}\"",
74
- '--dockerfile',
75
- "\"#{kaniko_opts[:dockerfile]}\"",
76
- flags_cli,
77
- options_cli,
78
- build_args_cli,
79
- ignore_paths_cli,
80
- insecure_registries_cli,
81
- registry_certificates_cli,
82
- registry_mirrors_cli,
83
- destinations_cli,
84
- skip_tls_verify_registrys_cli
85
- ].reject(&:empty?)
86
- script << kaniko_cmds.join(' ')
87
- opts[:script] = script
88
99
  end
89
100
  end
90
101
  end
@@ -10,7 +10,7 @@ module Pipedawg
10
10
  @opts = {
11
11
  jobs: [Pipedawg::Job.new],
12
12
  stages: ['build'],
13
- workflow: {}
13
+ workflow: nil
14
14
  }.merge(opts)
15
15
  update
16
16
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pipedawg
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.1'
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.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - harbottle
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-28 00:00:00.000000000 Z
11
+ date: 2022-02-08 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
@@ -46,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
47
  - !ruby/object:Gem::Version
47
48
  version: '0'
48
49
  requirements: []
49
- rubygems_version: 3.0.3
50
+ rubygems_version: 3.1.2
50
51
  signing_key:
51
52
  specification_version: 4
52
53
  summary: Generate GitLab CI pipelines.