orchparty-rancher 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4be0536af375d51453ea0e2add04a268d294bcf4
4
+ data.tar.gz: 68825291be60b67b39db5460e51476795efeb4b7
5
+ SHA512:
6
+ metadata.gz: f378a7863f72bf3f715002d764edc9f224616f6282288e19d635a013f8dad3887f2d79599f1ae3ded182a6fd36ae0b5883e2b06bd2dc23931fbbdb340f2726bb
7
+ data.tar.gz: 6a107813b34ce29772600fbf5848fbcc5b06407cf20730b2fc5180bfed5266e2488c24f6f5a5a4d30f240668624760f6132508061474346b7ce98a903c386f56
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.14.4
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in orchparty-rancher.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # Orchparty::Rancher
2
+
3
+ [![Build Status](https://travis-ci.org/jannishuebl/orchparty.svg?branch=master)](https://travis-ci.org/pschrammel/orchparty-rancher)
4
+ [![Gem Version](https://badge.fury.io/rb/orchparty-rancher.svg)](https://badge.fury.io/rb/orchparty-rancher)
5
+
6
+ This is a [Orchparty](https://orch.party/) plugin to generate
7
+ docker-compose.yml and rancher-compose.yml files.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'orchparty-rancher'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install orchparty-rancher
24
+
25
+ ## Usage
26
+
27
+ Add a rancher section to your stack description:
28
+
29
+ ```
30
+ application "test" do
31
+ service "web" do
32
+ image 'mywebservice/webservice'
33
+ rancher do
34
+ scale 3
35
+ upgrade_strategy do
36
+ _ start_first: true
37
+ _ interval_millis: 30000
38
+ end
39
+ health_check do
40
+ _ healthy_threshold: 2
41
+ _ initializing_timeout: 60000
42
+ _ interval: 30000
43
+ _ port: 4000
44
+ _ request_line: "GET / HTTP/1.1"
45
+ _ response_timeout: 3000
46
+ _ strategy: 'recreate'
47
+ _ unhealthy_threshold: 3
48
+ end
49
+ end
50
+ end
51
+ ```
52
+
53
+ Run orchparty with the rancher_v2 generator:
54
+ ```ruby
55
+ orchparty generate rancher_v2 -f stack.rb -d docker-compose.yml -r rancher-compose.yml
56
+ ```
57
+
58
+ ## Development
59
+
60
+ 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.
61
+
62
+ 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).
63
+
64
+ ## Contributing
65
+
66
+ Bug reports and pull requests are welcome on GitHub at
67
+ https://github.com/pschrammel/orchparty-rancher.
68
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "orchparty/rancher"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,83 @@
1
+ module Orchparty
2
+ class RancherBuilder < HashBuilder
3
+ def scale(num)
4
+ @hash ||= AST.hash
5
+ @hash[:scale]=num
6
+ end
7
+ def upgrade_strategy(&block)
8
+ @hash ||= AST.hash
9
+ @hash[:upgrade_strategy]=HashBuilder.build(block)
10
+ end
11
+ def health_check(&block)
12
+ @hash ||= AST.hash
13
+ @hash[:health_check]=HashBuilder.build(block)
14
+ end
15
+ end
16
+
17
+ class ServiceBuilder
18
+ def rancher(&block)
19
+ @node.rancher = RancherBuilder.build(block)
20
+ self
21
+ end
22
+ end
23
+ end
24
+
25
+
26
+ module Orchparty
27
+ module Plugin
28
+ module RancherV2
29
+ def self.desc
30
+ "generate rancher-compose.yml v2 file"
31
+ end
32
+
33
+ def self.define_flags(c)
34
+ c.flag [:docker_compose,:d], :desc => 'Set the output file'
35
+ c.flag [:rancher_compose,:r], :desc => 'Set the output file'
36
+ end
37
+
38
+ def self.generate(ast, options)
39
+ output = rancher_output(ast)
40
+ File.write(options[:rancher_compose], output)
41
+ output = docker_output(ast)
42
+ File.write(options[:docker_compose], output)
43
+ end
44
+
45
+ def self.transform_to_yaml(hash)
46
+ hash = hash.deep_transform_values{|v| v.is_a?(Hash) ? v.to_h : v }
47
+ HashUtils.deep_stringify_keys(hash)
48
+ end
49
+
50
+ def self.rancher_output(application)
51
+ output_hash = {
52
+ "version" => "2",
53
+ "services" =>
54
+ application.services.map do |name,service|
55
+ service = service.to_h
56
+ rancher= ( service['rancher'] || service[:rancher] || { scale: 1 } ) # some dummy placeholder
57
+ [service.delete(:name), HashUtils.deep_stringify_keys(rancher)]
58
+ end.to_h,
59
+ }
60
+ output_hash.to_yaml(line_width: -1)
61
+ end
62
+
63
+ def self.docker_output(application)
64
+ output_hash = {"version" => "2",
65
+ "services" =>
66
+ application.services.map do |name,service|
67
+ service = service.to_h
68
+ #p service.keys
69
+ service.delete('rancher')
70
+ service.delete(:rancher)
71
+ [service.delete(:name), HashUtils.deep_stringify_keys(service.to_h)]
72
+ end.to_h,
73
+ }
74
+ output_hash["volumes"] = transform_to_yaml(application.volumes) if application.volumes && !application.volumes.empty?
75
+ output_hash["networks"] = transform_to_yaml(application.networks) if application.networks && !application.networks.empty?
76
+ output_hash.to_yaml(line_width: -1)
77
+ end
78
+
79
+ end
80
+ end
81
+ end
82
+
83
+ Orchparty::Plugin.register_plugin(:rancher_v2, Orchparty::Plugin::RancherV2)
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ #require 'orchparty/rancher/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "orchparty-rancher"
8
+ spec.version = "0.1.0"
9
+ spec.authors = ["Peter Schrammel"]
10
+ spec.email = ["peter.schrammel@gmx.de"]
11
+
12
+ spec.summary = %q{"Add a rancher-compose.yml generator to orchparty"}
13
+ spec.description = %q{"Add a rancher-compose.yml generator to orchparty"}
14
+ spec.homepage = "https://github.com/pschrammel/orchparty-rancher"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ #if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+ #else
21
+ # raise "RubyGems 2.0 or newer is required to protect against " \
22
+ # "public gem pushes."
23
+ #end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.14"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_development_dependency "orchparty", "~> 1.2.2"
36
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: orchparty-rancher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Peter Schrammel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: orchparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.2.2
69
+ description: '"Add a rancher-compose.yml generator to orchparty"'
70
+ email:
71
+ - peter.schrammel@gmx.de
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - lib/orchparty/plugins/rancher_v2.rb
85
+ - orchparty-rancher.gemspec
86
+ homepage: https://github.com/pschrammel/orchparty-rancher
87
+ licenses: []
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.6.12
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: '"Add a rancher-compose.yml generator to orchparty"'
109
+ test_files: []