minke 0.16.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +8 -8
  2. data/.codeclimate.yml +7 -0
  3. data/.gitignore +1 -0
  4. data/.ruby-version +1 -1
  5. data/.travis.yml +4 -1
  6. data/Gemfile +5 -0
  7. data/Guardfile +70 -0
  8. data/README.md +12 -9
  9. data/bin/minke +48 -0
  10. data/examples/config_go.yml +44 -25
  11. data/lib/minke/config/config.rb +326 -0
  12. data/lib/minke/config/reader.rb +94 -0
  13. data/lib/minke/docker/docker_compose.rb +53 -0
  14. data/lib/minke/docker/docker_runner.rb +123 -0
  15. data/lib/minke/docker/service_discovery.rb +24 -0
  16. data/lib/minke/docker/system_runner.rb +16 -0
  17. data/lib/minke/generators/config.rb +106 -0
  18. data/lib/minke/generators/config_processor.rb +47 -0
  19. data/lib/minke/generators/config_variables.rb +23 -0
  20. data/lib/minke/generators/processor.rb +131 -0
  21. data/lib/minke/generators/register.rb +19 -0
  22. data/lib/minke/helpers/helper.rb +68 -0
  23. data/lib/minke/rake/app.rake +50 -198
  24. data/lib/minke/rake/config.rake +1 -5
  25. data/lib/minke/rake/docker.rake +7 -5
  26. data/lib/minke/tasks/build.rb +17 -0
  27. data/lib/minke/tasks/build_image.rb +13 -0
  28. data/lib/minke/tasks/cucumber.rb +34 -0
  29. data/lib/minke/tasks/fetch.rb +16 -0
  30. data/lib/minke/tasks/push.rb +22 -0
  31. data/lib/minke/tasks/run.rb +23 -0
  32. data/lib/minke/tasks/task.rb +107 -0
  33. data/lib/minke/tasks/test.rb +17 -0
  34. data/lib/minke/version.rb +1 -1
  35. data/lib/minke.rb +33 -9
  36. data/minke.gemspec +16 -11
  37. metadata +84 -9
  38. data/lib/minke/commands/go.rb +0 -27
  39. data/lib/minke/commands/swift.rb +0 -32
  40. data/lib/minke/docker.rb +0 -122
  41. data/lib/minke/docker_compose.rb +0 -31
  42. data/lib/minke/helpers.rb +0 -56
data/lib/minke.rb CHANGED
@@ -1,15 +1,39 @@
1
- require 'docker'
2
- require 'yaml'
3
- require 'rest-client'
4
1
  require 'consul_loader'
5
- require 'rake'
2
+ require 'docker'
6
3
  require 'erb'
4
+ require 'fileutils'
5
+ require 'logger'
6
+ require 'rake'
7
7
  require 'resolv'
8
+ require 'rest-client'
9
+ require 'rubygems'
10
+ require 'yaml'
11
+ require 'colorize'
12
+ require 'multi_json'
8
13
 
9
14
  require 'minke/version'
10
- require 'minke/docker'
11
- require 'minke/docker_compose'
12
- require 'minke/helpers'
13
15
 
14
- require 'minke/commands/go'
15
- require 'minke/commands/swift'
16
+ require 'minke/helpers/helper'
17
+
18
+ require 'minke/docker/docker_compose'
19
+ require 'minke/docker/docker_runner'
20
+ require 'minke/docker/system_runner'
21
+ require 'minke/docker/service_discovery'
22
+
23
+ require 'minke/config/config'
24
+ require 'minke/config/reader'
25
+
26
+ require 'minke/tasks/task'
27
+ require 'minke/tasks/build'
28
+ require 'minke/tasks/cucumber'
29
+ require 'minke/tasks/fetch'
30
+ require 'minke/tasks/push'
31
+ require 'minke/tasks/run'
32
+ require 'minke/tasks/test'
33
+ require 'minke/tasks/build_image'
34
+
35
+ require 'minke/generators/config'
36
+ require 'minke/generators/config_processor'
37
+ require 'minke/generators/config_variables'
38
+ require 'minke/generators/processor'
39
+ require 'minke/generators/register'
data/minke.gemspec CHANGED
@@ -4,26 +4,31 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'minke/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "minke"
7
+ spec.name = 'minke'
8
8
  spec.version = Minke::VERSION
9
- spec.authors = ["Nic Jackson"]
10
- spec.email = ["jackson.nic@gmail.com"]
9
+ spec.authors = ['Nic Jackson']
10
+ spec.email = ['jackson.nic@gmail.com']
11
11
 
12
- spec.summary = "Minke is a suite of rake tasks for building and testing microservices with Docker. Currently supporting Google Go, Node.js services are coming soon."
13
- spec.homepage = "https://github.com/nicholasjackson/minke"
14
- spec.license = "MIT"
12
+ spec.summary = 'Minke is a suite of rake tasks for building and testing microservices with Docker. Currently supporting Google Go, Node.js services are coming soon.'
13
+ spec.homepage = 'https://github.com/nicholasjackson/minke'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
- spec.bindir = "exe"
17
+ spec.bindir = 'bin'
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
- spec.require_paths = ["lib"]
19
+ spec.executables << 'minke'
20
+ spec.require_paths = ['lib']
20
21
 
21
- spec.add_development_dependency "bundler", "~> 1.10"
22
- spec.add_development_dependency "rspec"
22
+ spec.add_development_dependency 'bundler', '~> 1.10'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'guard'
25
+ spec.add_development_dependency 'guard-rspec'
23
26
 
27
+ spec.add_runtime_dependency 'colorize'
24
28
  spec.add_runtime_dependency 'cucumber'
25
- spec.add_runtime_dependency 'rake', "~> 10.0"
29
+ spec.add_runtime_dependency 'rake', '~> 10.0'
26
30
  spec.add_runtime_dependency 'docker-api'
27
31
  spec.add_runtime_dependency 'rest-client', '~> 1.8'
28
32
  spec.add_runtime_dependency 'consul_loader', '~> 1.0'
33
+ spec.add_runtime_dependency 'multi_json'
29
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nic Jackson
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-03 00:00:00.000000000 Z
11
+ date: 2016-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,48 @@ dependencies:
38
38
  - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: colorize
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
41
83
  - !ruby/object:Gem::Dependency
42
84
  name: cucumber
43
85
  requirement: !ruby/object:Gem::Requirement
@@ -108,13 +150,29 @@ dependencies:
108
150
  - - ~>
109
151
  - !ruby/object:Gem::Version
110
152
  version: '1.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: multi_json
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
111
167
  description:
112
168
  email:
113
169
  - jackson.nic@gmail.com
114
- executables: []
170
+ executables:
171
+ - minke
115
172
  extensions: []
116
173
  extra_rdoc_files: []
117
174
  files:
175
+ - .codeclimate.yml
118
176
  - .gitignore
119
177
  - .rspec
120
178
  - .ruby-gemset
@@ -122,22 +180,39 @@ files:
122
180
  - .travis.yml
123
181
  - CODE_OF_CONDUCT.md
124
182
  - Gemfile
183
+ - Guardfile
125
184
  - LICENSE.txt
126
185
  - README.md
127
186
  - Rakefile
128
187
  - bin/console
188
+ - bin/minke
129
189
  - bin/setup
130
190
  - examples/config_go.yml
131
191
  - examples/config_swift.yml
132
192
  - lib/minke.rb
133
- - lib/minke/commands/go.rb
134
- - lib/minke/commands/swift.rb
135
- - lib/minke/docker.rb
136
- - lib/minke/docker_compose.rb
137
- - lib/minke/helpers.rb
193
+ - lib/minke/config/config.rb
194
+ - lib/minke/config/reader.rb
195
+ - lib/minke/docker/docker_compose.rb
196
+ - lib/minke/docker/docker_runner.rb
197
+ - lib/minke/docker/service_discovery.rb
198
+ - lib/minke/docker/system_runner.rb
199
+ - lib/minke/generators/config.rb
200
+ - lib/minke/generators/config_processor.rb
201
+ - lib/minke/generators/config_variables.rb
202
+ - lib/minke/generators/processor.rb
203
+ - lib/minke/generators/register.rb
204
+ - lib/minke/helpers/helper.rb
138
205
  - lib/minke/rake/app.rake
139
206
  - lib/minke/rake/config.rake
140
207
  - lib/minke/rake/docker.rake
208
+ - lib/minke/tasks/build.rb
209
+ - lib/minke/tasks/build_image.rb
210
+ - lib/minke/tasks/cucumber.rb
211
+ - lib/minke/tasks/fetch.rb
212
+ - lib/minke/tasks/push.rb
213
+ - lib/minke/tasks/run.rb
214
+ - lib/minke/tasks/task.rb
215
+ - lib/minke/tasks/test.rb
141
216
  - lib/minke/version.rb
142
217
  - minke.gemspec
143
218
  homepage: https://github.com/nicholasjackson/minke
@@ -1,27 +0,0 @@
1
- module Minke
2
- module Commands
3
- class Go
4
- def commands config
5
- {
6
- :build => {
7
- :get => [['go','get','-t','-v','-d','./...']],
8
- :build => [['go','build','-a','-installsuffix','cgo','-ldflags','\'-s\'','-o', "#{config['application_name']}"]],
9
- :test => [['go','test','./...']]
10
- },
11
- :docker => {
12
- :image => 'golang:latest',
13
- :env => ['CGO_ENABLED=0'],
14
- :binds => ["#{ENV['GOPATH']}/src:/go/src"],
15
- :working_directory => "#{working_directory}"
16
- }
17
- }
18
- end
19
-
20
- def working_directory
21
- dir = File.expand_path('../.')
22
- gopath = "#{ENV['GOPATH']}"
23
- new_dir = "/go" + dir.gsub(gopath,'')
24
- end
25
- end
26
- end
27
- end
@@ -1,32 +0,0 @@
1
- module Minke
2
- module Commands
3
- class Swift
4
- def commands config
5
- {
6
- :build => {
7
- :get => [
8
- ['swift', 'build', '--fetch'],
9
- # ['bash','-c', "find /src/Packages/ -type d -name Tests -exec echo {} && rm -rf {} \\;"]
10
- ['bash','-c', "find /src/Packages/ -type d -name Tests | xargs rm -rf"]
11
- ],
12
- :build => [
13
- ['rm', '-rf', '.build'],
14
- ['swift', 'build', '-Xcc', '-fblocks','-Xlinker', '-rpath', '-Xlinker', '.build/debug']
15
- ],
16
- :test => [['swift', 'test']],
17
- },
18
- :docker => {
19
- :image => 'ibmcom/kitura-ubuntu:latest',
20
- :binds => ["#{source_directory}:/src"],
21
- :working_directory => "/src"
22
- }
23
- }
24
- end
25
-
26
- def source_directory
27
- Dir.pwd if File.exists?('Package.swift')
28
- File.expand_path('../.') if File.exists?('../Package.swift')
29
- end
30
- end
31
- end
32
- end
data/lib/minke/docker.rb DELETED
@@ -1,122 +0,0 @@
1
- module Minke
2
- class Docker
3
- def self.get_docker_ip_address
4
- if ENV['DOCKER_HOST']
5
- # dockerhost set
6
- host = ENV['DOCKER_HOST'].dup
7
- host.gsub!(/tcp:\/\//, '')
8
- host.gsub!(/:\d+/,'')
9
-
10
- return host
11
- elsif ENV['DOCKER_IP']
12
- return ENV['DOCKER_IP']
13
- else
14
- throw "Please set the environment variable DOCKER_HOST or DOCKER_IP with the ip address of your docker instance."
15
- end
16
- end
17
-
18
- def self.find_image image_name
19
- found = nil
20
- ::Docker::Image.all.each do | image |
21
- found = image if image.info["RepoTags"].include? image_name
22
- end
23
-
24
- return found
25
- end
26
-
27
- def self.pull_image image_name
28
- puts "Pulling Image: #{image_name}"
29
- puts `docker pull #{image_name}`
30
- end
31
-
32
- def self.get_container args
33
- container = self.find_running_container
34
- if container != nil
35
- return container
36
- else
37
- return self.create_and_start_container(args)
38
- end
39
- end
40
-
41
- def self.find_running_container
42
- containers = ::Docker::Container.all(:all => true)
43
- found = nil
44
-
45
- containers.each do | container |
46
- if container.info["Image"] == "golang" && container.info["Status"].start_with?("Up")
47
- return container
48
- end
49
- end
50
-
51
- return nil
52
- end
53
-
54
- def self.create_and_start_container args
55
- # update the timeout for the Excon Http Client
56
- # set the chunk size to enable streaming of log files
57
- ::Docker.options = {:chunk_size => 1, :read_timeout => 3600}
58
-
59
- container = ::Docker::Container.create(
60
- 'Image' => args['build_args']['image'],
61
- 'Cmd' => ['/bin/bash'],
62
- 'Tty' => true,
63
- "Binds" => ["#{ENV['GOPATH']}/src:/go/src"],
64
- "Env" => args['build_args']['env'],
65
- 'WorkingDir' => args['build_args']['working_directory'])
66
- container.start
67
-
68
- return container
69
- end
70
-
71
- def self.create_and_run_container args, cmd
72
- # update the timeout for the Excon Http Client
73
- # set the chunk size to enable streaming of log files
74
- ::Docker.options = {:chunk_size => 1, :read_timeout => 3600}
75
- container = ::Docker::Container.create(
76
- 'Image' => args[:build_config][:docker][:image],
77
- 'Cmd' => cmd,
78
- "Binds" => args[:build_config][:docker][:binds],
79
- "Env" => args[:build_config][:docker][:env],
80
- 'WorkingDir' => args[:build_config][:docker][:working_directory])
81
-
82
- return_code = 0
83
-
84
- thread = Thread.new {
85
- container.attach { |stream, chunk|
86
- puts "#{chunk}"
87
-
88
- if stream.to_s == "stdout"
89
- return_code = 0
90
- else
91
- return_code = 1
92
- end
93
- }
94
- }
95
- container.start
96
- thread.join
97
-
98
- return container, return_code
99
- end
100
-
101
- def self.delete_container container
102
- if container != nil
103
- begin
104
- container.delete()
105
- rescue => e
106
- puts "Error: Unable to delete container"
107
- end
108
- end
109
- end
110
-
111
- def self.tag_and_push args
112
- image = self.find_image "#{args['go']['application_name']}:latest"
113
- image.tag('repo' => "#{args['docker_registry']['namespace']}/#{args['go']['application_name']}", 'force' => true) unless image.info["RepoTags"].include? "#{args['docker_registry']['namespace']}/#{args['go']['application_name']}:latest"
114
-
115
- system("docker login -u #{args['docker_registry']['user']} -p #{args['docker_registry']['password']} -e #{args['docker_registry']['email']} #{args['docker_registry']['url']}")
116
- abort "Unable to login" unless $?.exitstatus == 0
117
-
118
- system("docker push #{args['docker_registry']['namespace']}/#{args['go']['application_name']}:latest")
119
- abort "Unable to push to registry" unless $?.exitstatus == 0
120
- end
121
- end
122
- end
@@ -1,31 +0,0 @@
1
- module Minke
2
- class DockerCompose
3
- @compose_file = nil
4
-
5
- def initialize compose_file
6
- @compose_file = compose_file
7
- end
8
-
9
- def up
10
- execute "docker-compose -f #{@compose_file} up -d"
11
- sleep 2
12
- end
13
-
14
- def stop
15
- execute "docker-compose -f #{@compose_file} stop"
16
- end
17
-
18
- def rm
19
- execute "echo y | docker-compose -f #{@compose_file} rm -v"
20
- end
21
-
22
- def logs
23
- execute "docker-compose -f #{@compose_file} logs -f"
24
- end
25
-
26
- private
27
- def execute command
28
- system("#{command}")
29
- end
30
- end
31
- end
data/lib/minke/helpers.rb DELETED
@@ -1,56 +0,0 @@
1
- module Minke
2
- class Helpers
3
-
4
- class << self
5
- attr_accessor :config
6
- end
7
-
8
- @config = nil
9
-
10
- def self.wait_until_server_running server, count, successes = 0
11
- begin
12
- response = RestClient.send("get", server)
13
- rescue
14
-
15
- end
16
-
17
- if response == nil || !response.code.to_i == 200
18
- puts "Waiting for server #{server} to start"
19
- sleep 1
20
- if count < 20
21
- self.wait_until_server_running server, count + 1
22
- else
23
- raise 'Server failed to start'
24
- end
25
- else
26
- if successes > 0
27
- puts "Server: #{server} passed health check, #{successes} checks to go..."
28
- sleep 1
29
- self.wait_until_server_running server, count + 1, successes - 1
30
- else
31
- puts "Server: #{server} healthy"
32
- end
33
- end
34
- end
35
-
36
- def self.load_config config_file
37
- @config = YAML.parse(ERB.new(File.read(config_file)).result).transform
38
-
39
- @config[:build_config] = Minke::Commands::Go.new.commands(@config) unless @config['language'] != 'go'
40
- @config[:build_config] = Minke::Commands::Swift.new.commands(@config) unless @config['language'] != 'swift'
41
- end
42
-
43
- def self.copy_files assets
44
- assets.each do |a|
45
- directory = a['to']
46
- if File.directory?(a['to'])
47
- directory = File.dirname(a['to'])
48
- end
49
-
50
- Dir.mkdir directory unless Dir.exist? a['to']
51
- FileUtils.cp a['from'], a['to']
52
- end
53
- end
54
-
55
- end
56
- end