pipedawg 0.1.0 → 0.2.2

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: 6da632acfefa54ce858d4277758160be20246355596f84a5cf7f7a47c6bf7f93
4
- data.tar.gz: 52c803810e345742b2ae1f0ff10e19e3afd5a8423164667346fcda75d78b54ee
3
+ metadata.gz: b1df968015369cc666fc521d546b3194e82f04ec28b9a2473dbc2452b5c37780
4
+ data.tar.gz: 5afe211e7fb69ac10808af059e02dc5706c882ad86d2309901d2f943e0ec6a6d
5
5
  SHA512:
6
- metadata.gz: 3aa2f038cabfca9659ac80cc1c04a186d3ffed3d5dac47e3ab64140f09d1c5dfecba9d41c59e90e7215dab99edad8aeff8a3f2162b11b88b42551fe88ace12e8
7
- data.tar.gz: 758697c43505ff847d74e3c5db85417652636dda97082b444ef975752dd03cd0853d6cc78b9403c9ecf11894510daf5ded82edeab7bb7b1e99b9441ec28b207b
6
+ metadata.gz: 7348909008c56e40d693f388da3b6eb8210c380a357c87c5e1cf906932a9c66246af77a9328f0746d70b2213943c95f73256d835b5163ca17348a9068998a5ac
7
+ data.tar.gz: 9f3b4d44c1e2e5e2b955ecd135ccdcfd100d15fbcc137f40dca0af2797a0aa3637444e2e75ec910ac428a953147d883ecb24414c6e10bba17dfb0d40f3881b70
data/README.md CHANGED
@@ -1,10 +1,18 @@
1
- # Pipedawg
1
+ # pipedawg
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/pipedawg.svg)](https://rubygems.org/gems/pipedawg)
2
4
 
3
5
  Generate GitLab CI pipelines.
4
6
 
5
7
  ## Installation
6
8
 
7
- Add this line to your application's Gemfile:
9
+ Install `pipedawg` with:
10
+
11
+ ```
12
+ gem install pipedawg
13
+ ```
14
+
15
+ Or add this line to your application's Gemfile:
8
16
 
9
17
  ```ruby
10
18
  gem 'pipedawg'
@@ -12,25 +20,90 @@ gem 'pipedawg'
12
20
 
13
21
  And then execute:
14
22
 
15
- $ bundle install
23
+ ```sh
24
+ bundle install
25
+ ```
16
26
 
17
- Or install it yourself as:
27
+ ## Ruby library
18
28
 
19
- $ gem install pipedawg
29
+ Example:
20
30
 
21
- ## Usage
31
+ ```ruby
32
+ #!/usr/bin/env ruby
33
+ # frozen_string_literal: true
34
+
35
+ # print_pipeline.rb
36
+ require 'pipedawg'
37
+
38
+ gem_job = Pipedawg::Job.new(
39
+ 'build:gem',
40
+ artifacts: ['*.gem'],
41
+ image: 'ruby',
42
+ script: ['bundle install', 'gem build *.gemspec']
43
+ )
44
+
45
+ kaniko_job = Pipedawg::KanikoJob.new(
46
+ 'build:kaniko',
47
+ {needs: ['build:gem'], retry: 2},
48
+ {context:'${CI_PROJECT_DIR}/docker',external_files: {'*.gem':'gems'}}
49
+ )
50
+
51
+ pipeline = Pipedawg::Pipeline.new 'build:image', jobs: [gem_job, kaniko_job]
52
+ puts pipeline.to_yaml
53
+ ```
22
54
 
55
+ ```console
56
+ $ chmod +x print_pipeline.rb
57
+ $ ./print_pipeline.rb
58
+ ---
59
+ stages:
60
+ - '1'
61
+ - '2'
62
+ workflow: {}
63
+ build:gem:
64
+ artifacts:
65
+ - "*.gem"
66
+ cache: {}
67
+ image: ruby
68
+ needs: []
69
+ rules: []
70
+ script:
71
+ - bundle install
72
+ - gem build *.gemspec
73
+ stage: '1'
74
+ tags: []
75
+ build:kaniko:
76
+ artifacts: {}
77
+ cache: {}
78
+ needs:
79
+ - build:gem
80
+ retry: 2
81
+ rules: []
82
+ script:
83
+ - echo "{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}"
84
+ > "/kaniko/.docker/config.json"
85
+ - cp "*.gem" "${CI_PROJECT_DIR}/docker/gems"
86
+ - '"/kaniko/executor" --context "${CI_PROJECT_DIR}/docker" --dockerfile "Dockerfile"
87
+ --no-push'
88
+ stage: '2'
89
+ tags: []
90
+ ```
23
91
 
24
92
  ## Development
25
93
 
26
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
94
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake spec` to run the tests. Run `bundle exec rubocop` to run the linter. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
95
+
96
+ Note that by default, Bundler will attempt to install gems to the system, e.g. `/usr/bin`, `/usr/share`, which requires elevated access and can interfere with files that are managed by the system's package manager. This behaviour can be overridden by creating the file `.bundle/config` and adding the following line:
97
+ ```
98
+ BUNDLE_PATH: "./.bundle"
99
+ ```
100
+ When you run `bin/setup` or `bundle install`, all gems will be installed inside the .bundle directory of this project.
27
101
 
28
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
102
+ To make this behaviour a default for all gem projects, the above line can be added to the user's bundle config file in their home directory (`~/.bundle/config`)
29
103
 
30
104
  ## Contributing
31
105
 
32
- Bug reports and pull requests are welcome on GitHub at https://github.com/liger1978/pipedawg.
33
-
106
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/liger1978/pipedawg).
34
107
 
35
108
  ## License
36
109
 
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: []
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pipedawg
4
+ # kaniko_job class
5
+ class KanikoJob < Job
6
+ attr_accessor :kaniko_opts
7
+
8
+ def initialize(name = 'build', opts = {}, kaniko_opts = {}) # rubocop:disable Metrics/MethodLength
9
+ @kaniko_opts = {
10
+ build_args: {},
11
+ config: {
12
+ '$CI_REGISTRY': {
13
+ username: '$CI_REGISTRY_USER',
14
+ password: '$CI_REGISTRY_PASSWORD'
15
+ }
16
+ },
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: [],
35
+ trusted_ca_cert_target_file: '/kaniko/ssl/certs/ca-certificates.crt'
36
+ }.merge(kaniko_opts)
37
+ super name, opts
38
+ update
39
+ end
40
+
41
+ def update # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
42
+ 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|
46
+ "cat \"#{cert}\" >> \"#{kaniko_opts[:trusted_ca_cert_target_file]}\""
47
+ end
48
+ script.concat cert_copies
49
+ file_copies = kaniko_opts[:external_files].map do |source, dest|
50
+ "cp \"#{source}\" \"#{kaniko_opts[:context]}/#{dest}\""
51
+ end
52
+ script.concat file_copies
53
+ flags = kaniko_opts[:flags].clone
54
+ 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
+ "--insecure-registry #{r}"
61
+ end.join(' ')
62
+ registry_certificates_cli = kaniko_opts[:registry_certificates].map do |k, v|
63
+ "--registry-certificate #{k}=\"#{v}\""
64
+ 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|
67
+ "--skip-tls-verify-registry #{r}"
68
+ 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
+ end
89
+ end
90
+ end
@@ -10,8 +10,9 @@ 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
+ update
15
16
  end
16
17
 
17
18
  def to_yaml
@@ -24,11 +25,11 @@ module Pipedawg
24
25
  JSON.parse(pipeline.to_json).to_yaml
25
26
  end
26
27
 
27
- def to_yaml_file(file = '.gitlab-ci.yml')
28
+ def to_yaml_file(file = 'pipeline.yml')
28
29
  File.write(file, to_yaml)
29
30
  end
30
31
 
31
- def update_stages
32
+ def update
32
33
  stages = []
33
34
  opts[:jobs].each do |job|
34
35
  stage = stage_from_needs(opts[:jobs], job.name)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pipedawg
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.2'
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/kaniko_job'
4
5
  require 'pipedawg/pipeline'
5
6
  require 'pipedawg/version'
6
7
 
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.1.0
4
+ version: 0.2.2
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-18 00:00:00.000000000 Z
11
+ date: 2022-02-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Generate GitLab CI pipelines.
14
14
  email:
@@ -17,21 +17,13 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - ".bundle/config"
21
- - ".gitignore"
22
- - ".gitlab-ci.yml"
23
- - ".rspec"
24
- - ".rubocop.yml"
25
- - ".travis.yml"
26
- - Gemfile
27
20
  - LICENSE.txt
28
21
  - README.md
29
- - Rakefile
30
22
  - lib/pipedawg.rb
31
23
  - lib/pipedawg/job.rb
24
+ - lib/pipedawg/kaniko_job.rb
32
25
  - lib/pipedawg/pipeline.rb
33
26
  - lib/pipedawg/version.rb
34
- - pipedawg.gemspec
35
27
  homepage: https://github.com/liger1978/pipedawg
36
28
  licenses:
37
29
  - MIT
@@ -54,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
46
  - !ruby/object:Gem::Version
55
47
  version: '0'
56
48
  requirements: []
57
- rubygems_version: 3.0.3
49
+ rubygems_version: 3.1.2
58
50
  signing_key:
59
51
  specification_version: 4
60
52
  summary: Generate GitLab CI pipelines.
data/.bundle/config DELETED
@@ -1,4 +0,0 @@
1
- ---
2
- BUNDLE_BIN: "bin"
3
- BUNDLE_DISABLE_SHARED_GEMS: "true"
4
- BUNDLE_PATH: "./bundle"
data/.gitignore DELETED
@@ -1,15 +0,0 @@
1
- /bin/
2
- /bundle/
3
- /.yardoc
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- /*.gem
11
- /vendor
12
- Gemfile.lock
13
-
14
- # rspec failure tracking
15
- .rspec_status
data/.gitlab-ci.yml DELETED
@@ -1,14 +0,0 @@
1
- ---
2
- stages:
3
- - build
4
- workflow: {}
5
- build:
6
- artifacts: {}
7
- cache: {}
8
- image:
9
- name: ruby:2.5
10
- needs: []
11
- rules: []
12
- script: []
13
- stage: build
14
- tags: []
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/.rubocop.yml DELETED
@@ -1,14 +0,0 @@
1
- ---
2
- AllCops:
3
- Exclude:
4
- - 'bin/**/*'
5
- - 'bundle/**/*'
6
- - '*.gemspec'
7
- NewCops: enable
8
-
9
- Metrics/BlockLength:
10
- Exclude:
11
- - 'Rakefile'
12
- - '**/*.rake'
13
- - 'test/**/*.rb'
14
- - 'spec/**/*_spec.rb'
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.6.6
6
- before_install: gem install bundler -v 2.1.4
data/Gemfile DELETED
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- # Specify your gem's dependencies in pipedawg.gemspec
6
- gemspec
7
-
8
- gem 'irb', '~> 1.4'
9
- gem 'rake', '~> 12.0'
10
- gem 'rdoc', '~> 6.4'
11
- gem 'rspec', '~> 3.0'
12
- gem 'rubocop', '~> 1.24', require: false
13
- gem 'rubocop-rake', '~> 0.6', require: false
14
- gem 'rubocop-rspec', '~> 2.7', require: false
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- task default: :spec
data/pipedawg.gemspec DELETED
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lib/pipedawg/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'pipedawg'
7
- spec.version = Pipedawg::VERSION
8
- spec.authors = ['harbottle']
9
- spec.email = ['harbottle@room3d3.com']
10
-
11
- spec.summary = 'Generate GitLab CI pipelines.'
12
- spec.description = 'Generate GitLab CI pipelines.'
13
- spec.homepage = 'https://github.com/liger1978/pipedawg'
14
- spec.license = 'MIT'
15
-
16
- spec.metadata['homepage_uri'] = spec.homepage
17
- spec.metadata['source_code_uri'] = 'https://github.com/liger1978/pipedawg'
18
- spec.metadata['changelog_uri'] = 'https://github.com/liger1978/pipedawg'
19
-
20
- # Specify which files should be added to the gem when it is released.
21
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
- end
25
- spec.bindir = 'exe'
26
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
- spec.require_paths = ['lib']
28
-
29
- end