minke 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NzY3ZDEwYjE1YjU5NjA0YmU3ZmIzNDAzMzNmYTQxMGYzZTU4M2M1ZA==
5
+ data.tar.gz: !binary |-
6
+ NGNmZjY2ZmM4MDM1ZGU0ZDUwZTJmMzE5OGM3ZjdjZTA1MjE0ZDdiOA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OGY2NDA2Mzg1NjhhMDZjYmUxYmNhNWUwMjVkNjg5OWIyZGE3ODFlMTI3MzE5
10
+ OTQ1YTMzNjkxN2I2NjFmODZkMjczZTY2YmM3NjQwYzZiNzVlZDYzYzA1YmU2
11
+ OGRkYWQyMDVhMmYyMmQ4YzFlODZhODdkYWViYTAxMzQzZGU3ZDU=
12
+ data.tar.gz: !binary |-
13
+ NDEwOWUwZTJkMzYwYzIyOWE0Mzc5MjQzODQ4NDQ5ZDRhZGMwYjJiZDEzOWNi
14
+ MGQzYzM4NjY0NTdhZWVhNWM1ZDYxNjA3YzZlMTY3OTQ5NGNmZmEyYjA0ZTky
15
+ N2QyMzFkOWFhOTJkZWNjY2M3ZmUzMzBlMDBhOGUyZDRkMjcwMmQ=
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ minke
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.4
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.4
4
+ install: bundle
5
+ script:
6
+ - rake test
7
+ - rake build
8
+ deploy:
9
+ provider: rubygems
10
+ gem: minke
11
+ on:
12
+ repo: nicholasjackson/minke
13
+ api_key:
14
+ secure: NfDL67sdeJ0FOSYns+VKjPPk/ZAhJa/wpffw5RiXG94gst5XUtZauik1nVIrTpWYhw5e34hqHPH9mE+v8AkXQRmGyUkYbW+0ePFuqBHidsSFGUOzg3h0+wYrOkvA60REJAg1EM97IDx7PmhcxfO3NFsDvr6RKOXaNc3cLxmiIdD9PVktm75hk2BvoiuO3d12ph2Wr9RjSuidX/0z2H8oOdDs8e14x9QPqX3LuRiTe+A3h+hjZ1OhH9aT5blJ2ZI65iDMY1K6hzcDuUY7CzCbKZF2pPEkDgtT5FgRX1klu28Ehxebef/vvAFmOt5ztuXyE6nEdoI8NACE7XXQQC+6H5PzE6hWoHKk7/vMn5u2pdMRUykArAJ6++JxRSitaKSXn0xZfRKvszp00WhHiG4kPtQXgNKiJiuOKX9huy+gHssYfP3sxcd0LNrslnxaGRAn0igRHuBeaIi8kxL+03q1tCSjOcc6OV9qPIgZAiGUdeeolefrXFTovptcG5PiDzq6jJoQSO51kRMhG/XGfuf2T+vpl5ouT2dsYSz8qDchX5LEjcjuBXb3J1/Xz5s1oQjGI1w+bSrZ1OAFv0d5v8jcD9IyF4C7iVuqCtlc0bNkm9ZgwG+iHHj/SxezFPCttVFBS2or6YizA2xAONXkuy2g+yUDZplcX56fe0oIQsOJOjc=
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in go_builder.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Nic Jackson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,145 @@
1
+ # Minke
2
+ [![Build Status](https://travis-ci.org/nicholasjackson/go_builder.svg?branch=master)](https://travis-ci.org/nicholasjackson/go_builder)
3
+
4
+ Minke is an opinionated build system for Microservices and Docker, like a little envelope of quality it scaffolds the build, run and test (unit test and functional tests) phases of your microservice project allowing you to simply run and test your images using Docker Compose. Currently supporting Google's Go, extensions are planned for Node.js or HTML / Javascript sites with Grunt or Gulp based builds.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'minke'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install minke
21
+
22
+ ## Dependencies
23
+
24
+ ### Docker
25
+ You need to have docker, docker-machine, and docker-compose installed on your build machine and the docker environment variables must be set. If using the docker-toolkit on a mac you can set these by running...
26
+ ```bash
27
+ eval "$(docker-machine env default)"
28
+ ```
29
+
30
+ ## Usage
31
+ Include the rake tasks in your Rakefile
32
+ ```ruby
33
+ require 'minke'
34
+
35
+ spec = Gem::Specification.find_by_name 'minke'
36
+ Rake.add_rakelib "#{spec.gem_dir}/lib/minke/rake"
37
+ ```
38
+
39
+ By default Go builder looks for a config file (config.yml) in the same folder as your Rakefile
40
+
41
+ Go builder provides the following tasks...
42
+
43
+ ### rake app:test
44
+ Gets your packages dependencies then executes go test against the package.
45
+
46
+ ### rake app:build
47
+ Creates a linux binary for your application, runs app:test before execution.
48
+
49
+ ### rake app:build_server
50
+ Creates a docker image for your application, runs app:build before execution.
51
+
52
+ ### rake app:build_and_run
53
+ Creates a docker image for your application then starts the application using docker-compose, runs app:build_server before execution.
54
+
55
+ ### rake app:cucumber[optional feature tag]
56
+ Starts the application and then runs cucumber to execute your features, you can optionally pass a feature tag to this command to configure which part of your test suite you would like to run. Does not build the server before running, this needs to be done when you change your source code with app:build_server.
57
+
58
+ ### rake app:push
59
+ Pushes the built image to the configured registry, does not build the image before execution, this can be done manually with app:build_server.
60
+
61
+ ## Config File
62
+ The config file config.yml is where you set the various configuration for the build process.
63
+
64
+ ### Example Config File
65
+ ```yaml
66
+ go:
67
+ namespace: 'github.com/nicholasjackson'
68
+ application_name: 'event-sauce'
69
+ docker_registry:
70
+ url: <%= ENV['DOCKER_REGISTRY_URL'] %>
71
+ user: <%= ENV['DOCKER_REGISTRY_USER'] %>
72
+ password: <%= ENV['DOCKER_REGISTRY_PASS'] %>
73
+ email: <%= ENV['DOCKER_REGISTRY_EMAIL'] %>
74
+ namespace: <%= ENV['DOCKER_NAMESPACE'] %>
75
+ docker:
76
+ docker_file: './'
77
+ compose_file: './'
78
+ build_args:
79
+ image: 'golang:latest'
80
+ env:
81
+ - 'CGO_ENABLED=0' # used for alpine linux static linking
82
+ working_directory: '/go/src/github.com/nicholasjackson/event-sauce'
83
+ run:
84
+ consul_loader:
85
+ enabled: true
86
+ config_file: './config.yml'
87
+ url: <%= "http://#{ENV['DOCKER_IP']}:9500" %>
88
+ cucumber:
89
+ consul_loader:
90
+ enabled: true
91
+ config_file: './config.yml'
92
+ url: <%= "http://#{ENV['DOCKER_IP']}:9500" %>
93
+ health_check:
94
+ enabled: true
95
+ url: <%= "http://#{ENV['DOCKER_IP']}:8001/v1/health" %>
96
+ after_start:
97
+ - 'wait_for_elastic_search'
98
+ after_build:
99
+ copy_assets:
100
+ -
101
+ from: <%= "#{ENV['GOPATH']}/src/github.com/nicholasjackson/event-sauce/event-sauce" %>
102
+ to: './docker/event-sauce'
103
+ -
104
+ from: './swagger_spec/swagger.yml'
105
+ to: './dockerfile/event-sauce/swagger_spec/swagger.yml'
106
+ ```
107
+
108
+ #### go:
109
+ This section contains the configuration for the build process.
110
+ **namespace:** namespace for your application code within your GOPATH, this is generally the same as your repository.
111
+ **application_name:** name of the built binary.
112
+
113
+ #### docker_registry:
114
+ This section contains the configuration for the docker registry to push the image to. Images are pushed to the registry prefixed with the namespace and application_name, e.g. nicholasjackson/event-sauce:latest.
115
+ **url:** url for the docker registry.
116
+ **user:** username to use when logging into the registry.
117
+ **password:** password to use when logging into the registry.
118
+ **email:** email address to use when logging into the registry.
119
+ **namespace:** namespace of your image to use when pushing the image to the registry.
120
+
121
+ #### docker:
122
+ This section contains configuration for the Docker build and run process.
123
+ **docker_file:** path to the folder containing your Dockerfile used by the build_server task.
124
+ **compose_file:** path to your docker-compose file for run and cucumber tasks.
125
+
126
+ #### run:
127
+ ##### consul_loader:
128
+ When the application is run using docker-compose you can load some default config into your consul server. Told you this was opinionated, if you are building microservices you are using consul right?
129
+ **enabled:** boolean determining if this feature is enabled.
130
+ **config_file:** path to a yaml file containing the key values you would like to load into consul. consul_loader flattens the structure of your yaml file and converts this into key values. For more information please see []()
131
+
132
+ ## Development
133
+
134
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
135
+
136
+ 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).
137
+
138
+ ## Contributing
139
+
140
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/go_builder. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
141
+
142
+
143
+ ## License
144
+
145
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+ task :test => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "minke"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,39 @@
1
+ go:
2
+ namespace: 'github.com/nicholasjackson'
3
+ application_name: 'event-sauce'
4
+ comand: '/usr/local/go/bin/go'
5
+ docker_registry:
6
+ url: <%= ENV['DOCKER_REGISTRY_URL'] %>
7
+ user: <%= ENV['DOCKER_REGISTRY_USER'] %>
8
+ password: <%= ENV['DOCKER_REGISTRY_PASS'] %>
9
+ email: <%= ENV['DOCKER_REGISTRY_EMAIL'] %>
10
+ namespace: <%= ENV['DOCKER_NAMESPACE'] %>
11
+ docker:
12
+ docker_file: './'
13
+ compose_file: './'
14
+ build_args:
15
+ image: 'golang:latest'
16
+ env:
17
+ - 'CGO_ENABLED=0' # used for alpine linux static linking
18
+ working_directory: '/go/src/github.com/nicholasjackson/event-sauce'
19
+ run:
20
+ consul_loader:
21
+ enabled: true
22
+ config_file: './config.yml'
23
+ url: <%= "http://#{ENV['DOCKER_IP']}:9500" %>
24
+ cucumber:
25
+ consul_loader:
26
+ enabled: true
27
+ config_file: './config.yml'
28
+ url: <%= "http://#{ENV['DOCKER_IP']}:9500" %>
29
+ health_check:
30
+ enabled: true
31
+ url: <%= "http://#{ENV['DOCKER_IP']}:8001/v1/health" %>
32
+ after_build:
33
+ copy_assets:
34
+ -
35
+ from: <%= "#{ENV['GOPATH']}/src/github.com/nicholasjackson/event-sauce/event-sauce" %>
36
+ to: './docker/event-sauce'
37
+ -
38
+ from: './swagger_spec/swagger.yml'
39
+ to: './dockerfile/event-sauce/swagger_spec/swagger.yml'
@@ -0,0 +1,31 @@
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"
24
+ end
25
+
26
+ private
27
+ def execute command
28
+ system("#{command}")
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,80 @@
1
+ module Minke
2
+ class GoDocker
3
+ def self.get_docker_ip_address
4
+ if !ENV['DOCKER_HOST']
5
+ return "127.0.0.1"
6
+ else
7
+ # dockerhost set
8
+ host = ENV['DOCKER_HOST'].dup
9
+ host.gsub!(/tcp:\/\//, '')
10
+ host.gsub!(/:\d+/,'')
11
+
12
+ return host
13
+ end
14
+ end
15
+
16
+ def self.find_image image_name
17
+ found = nil
18
+ Docker::Image.all.each do | image |
19
+ found = image if image.info["RepoTags"].include? image_name
20
+ end
21
+
22
+ return found
23
+ end
24
+
25
+ def self.pull_image image_name
26
+ puts "Pulling Image: #{image_name}"
27
+ puts `docker pull #{image_name}`
28
+ end
29
+
30
+ def self.get_container args
31
+ container = self.find_running_container
32
+ if container != nil
33
+ return container
34
+ else
35
+ return self.create_and_start_container(args)
36
+ end
37
+ end
38
+
39
+ def self.find_running_container
40
+ containers = Docker::Container.all(:all => true)
41
+ found = nil
42
+
43
+ containers.each do | container |
44
+ if container.info["Image"] == "golang" && container.info["Status"].start_with?("Up")
45
+ return container
46
+ end
47
+ end
48
+
49
+ return nil
50
+ end
51
+
52
+ def self.create_and_start_container args
53
+ # update the timeout for the Excon Http Client
54
+ # set the chunk size to enable streaming of log files
55
+ Docker.options = {:chunk_size => 1, :read_timeout => 3600}
56
+
57
+ container = Docker::Container.create(
58
+ 'Image' => args['build_args']['image'],
59
+ 'Cmd' => ['/bin/bash'],
60
+ 'Tty' => true,
61
+ "Binds" => ["#{ENV['GOPATH']}/src:/go/src"],
62
+ "Env" => args['build_args']['env'],
63
+ 'WorkingDir' => args['build_args']['working_directory'])
64
+ container.start
65
+
66
+ return container
67
+ end
68
+
69
+ def self.tag_and_push args
70
+ image = self.find_image "#{args['go']['application_name']}:latest"
71
+ 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"
72
+
73
+ system("docker login -u #{args['docker_registry']['user']} -p #{args['docker_registry']['password']} -e #{args['docker_registry']['email']} #{args['docker_registry']['url']}")
74
+ abort "Unable to login" unless $?.exitstatus == 0
75
+
76
+ system("docker push #{args['docker_registry']['namespace']}/#{args['go']['application_name']}:latest")
77
+ abort "Unable to push to registry" unless $?.exitstatus == 0
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,45 @@
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
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
+ end
26
+ end
27
+
28
+ def self.load_config config_file
29
+ @config = YAML.parse(ERB.new(File.read(config_file)).result).transform
30
+ end
31
+
32
+ def self.copy_files assets
33
+ assets.each do |a|
34
+ directory = a['to']
35
+ if File.directory?(a['to'])
36
+ directory = File.dirname(a['to'])
37
+ end
38
+
39
+ Dir.mkdir directory unless Dir.exist? a['to']
40
+ FileUtils.cp a['from'], a['to']
41
+ end
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,153 @@
1
+ namespace :app do
2
+ desc "run unit tests"
3
+ task :test => ['config:set_docker_env', 'config:load_config', 'docker:fetch_images'] do
4
+ p "Test application"
5
+
6
+ config = Minke::Helpers.config
7
+ container = Minke::GoDocker.get_container config['docker']
8
+
9
+ begin
10
+ # Get go packages
11
+ ret = container.exec(['go','get','-t','-v','./...']) { |stream, chunk| puts "#{stream}: #{chunk}" }
12
+ raise Exception, 'Error running command' unless ret[2] == 0
13
+
14
+ # Test application
15
+ ret = container.exec(['go','test','./...']) do |stream, chunk|
16
+ puts "#{stream}: #{chunk}"
17
+ end
18
+
19
+ raise Exception, 'Error running command' unless ret[2] == 0
20
+ ensure
21
+ container.delete(:force => true)
22
+ end
23
+ end
24
+
25
+ desc "build and test application"
26
+ task :build => [:test] do
27
+ p "Build for Linux"
28
+
29
+ config = Minke::Helpers.config
30
+ container = Minke::GoDocker.get_container config['docker']
31
+
32
+ begin
33
+ # Build go server
34
+ ret = container.exec(
35
+ ['go','build','-a','-installsuffix','cgo','-ldflags','\'-s\'','-o', config['go']['application_name']]
36
+ ) do |stream, chunk|
37
+ puts "#{stream}: #{chunk}"
38
+ end
39
+
40
+ raise Exception, 'Error running command' unless ret[2] == 0
41
+ ensure
42
+ container.delete(:force => true)
43
+ end
44
+ end
45
+
46
+ task :copy_assets do
47
+ p "Copy assets"
48
+
49
+ config = Minke::Helpers.config
50
+
51
+ if config['after_build'] != nil && config['after_build']['copy_assets'] != nil
52
+ Minke::Helpers.copy_files config['after_build']['copy_assets']
53
+ end
54
+ end
55
+
56
+ desc "build Docker image for application"
57
+ task :build_server => [:build, :copy_assets] do
58
+ config = Minke::Helpers.config
59
+
60
+ p "Building Docker image: #{config['go']['application_name']}"
61
+
62
+ Docker.options = {:read_timeout => 6200}
63
+ image = Docker::Image.build_from_dir config['docker']['docker_file'], {:t => config['go']['application_name']}
64
+ end
65
+
66
+ desc "run application with Docker Compose"
67
+ task :run => ['config:set_docker_env', 'config:load_config'] do
68
+ p "Run application with docker compose"
69
+
70
+ config = Minke::Helpers.config
71
+ compose = Minke::DockerCompose.new config['docker']['compose_file']
72
+
73
+ begin
74
+ compose.up
75
+
76
+ # do we need to run any tasks after the server starts?
77
+ if config['run']['after_start'] != nil
78
+ config['run']['after_start'].each do |task|
79
+ puts "Running after_start task: #{task}"
80
+ Rake::Task[task].invoke
81
+ end
82
+ end
83
+
84
+ if config['run']['consul_loader']['enabled']
85
+ Minke::Helpers.wait_until_server_running "#{config['run']['consul_loader']['url']}/v1/status/leader", 0
86
+ loader = ConsulLoader::Loader.new(ConsulLoader::ConfigParser.new)
87
+ loader.load_config config['run']['consul_loader']['config_file'], config['run']['consul_loader']['url']
88
+ end
89
+
90
+ compose.logs
91
+ rescue SystemExit, Interrupt
92
+ compose.stop
93
+ compose.rm
94
+ end
95
+ end
96
+
97
+ desc "build and run application with Docker Compose"
98
+ task :build_and_run => [:build_server, :run]
99
+
100
+ desc "run end to end Cucumber tests USAGE: rake app:cucumber[@tag]"
101
+ task :cucumber, [:feature] => ['config:set_docker_env', 'config:load_config'] do |t, args|
102
+ config = Minke::Helpers.config
103
+
104
+ puts "Running cucumber with tags #{args[:feature]}"
105
+
106
+ if args[:feature] != nil
107
+ feature = "--tags #{args[:feature]}"
108
+ else
109
+ feature = ""
110
+ end
111
+
112
+ status = 0
113
+
114
+ compose = Minke::DockerCompose.new config['docker']['compose_file']
115
+ begin
116
+ compose.up
117
+
118
+ # do we need to run any tasks after the server starts?
119
+ if config['run']['after_start'] != nil
120
+ config['run']['after_start'].each do |task|
121
+ puts "Running after_start task: #{task}"
122
+ Rake::Task[task].invoke
123
+ end
124
+ end
125
+
126
+ if config['cucumber']['consul_loader']['enabled']
127
+ Minke::Helpers.wait_until_server_running "#{config['cucumber']['consul_loader']['url']}/v1/status/leader", 0
128
+ loader = ConsulLoader::Loader.new(ConsulLoader::ConfigParser.new)
129
+ loader.load_config config['cucumber']['consul_loader']['config_file'], config['cucumber']['consul_loader']['url']
130
+ end
131
+
132
+ if config['cucumber']['health_check']['enabled']
133
+ Minke::Helpers.wait_until_server_running config['cucumber']['health_check']['url'], 0
134
+ end
135
+
136
+ sh "cucumber --color -f pretty #{feature}"
137
+ status = $?.exitstatus
138
+ ensure
139
+ compose.stop
140
+ compose.rm
141
+
142
+ abort "Cucumber steps failed" unless status == 0
143
+ end
144
+ end
145
+
146
+ desc "push built image to Docker registry"
147
+ task :push => ['config:load_config'] do
148
+ p "Push image to registry"
149
+
150
+ config = Minke::Helpers.config
151
+ Minke::GoDocker.tag_and_push config
152
+ end
153
+ end
@@ -0,0 +1,10 @@
1
+ namespace :config do
2
+ task :load_config do
3
+ Minke::Helpers.load_config './config.yml'
4
+ end
5
+
6
+ task :set_docker_env do
7
+ DOCKER_IP = Minke::GoDocker.get_docker_ip_address
8
+ ENV['DOCKER_IP'] = DOCKER_IP
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ namespace :docker do
2
+ desc "updates build images for swagger and golang will overwrite existing images"
3
+ task :update_images do
4
+ Minke::GoDocker.pull_image 'golang:latest'
5
+ end
6
+
7
+ desc "pull images for golang from Docker registry if not already downloaded"
8
+ task :fetch_images do
9
+ Minke::GoDocker.pull_image 'golang' unless Minke::GoDocker.find_image 'golang:latest'
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Minke
2
+ VERSION = "0.7.0"
3
+ end
data/lib/minke.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'docker'
2
+ require 'yaml'
3
+ require 'rest-client'
4
+ require 'consul_loader'
5
+ require 'rake'
6
+ require "erb"
7
+
8
+ require 'minke/version'
9
+ require 'minke/go_docker'
10
+ require 'minke/docker_compose'
11
+ require 'minke/helpers'
data/minke.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'minke/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "minke"
8
+ spec.version = Minke::VERSION
9
+ spec.authors = ["Nic Jackson"]
10
+ spec.email = ["jackson.nic@gmail.com"]
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"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rspec"
23
+
24
+ spec.add_runtime_dependency 'cucumber'
25
+ spec.add_runtime_dependency 'rake', "~> 10.0"
26
+ spec.add_runtime_dependency 'docker-api'
27
+ spec.add_runtime_dependency 'rest-client', '~> 1.8'
28
+ spec.add_runtime_dependency 'consul_loader', '~> 1.0'
29
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minke
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.0
5
+ platform: ruby
6
+ authors:
7
+ - Nic Jackson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-27 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: cucumber
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: docker-api
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'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rest-client
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.8'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '1.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: consul_loader
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
111
+ description:
112
+ email:
113
+ - jackson.nic@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .rspec
120
+ - .ruby-gemset
121
+ - .ruby-version
122
+ - .travis.yml
123
+ - CODE_OF_CONDUCT.md
124
+ - Gemfile
125
+ - LICENSE.txt
126
+ - README.md
127
+ - Rakefile
128
+ - bin/console
129
+ - bin/setup
130
+ - examples/config.yml
131
+ - lib/minke.rb
132
+ - lib/minke/docker_compose.rb
133
+ - lib/minke/go_docker.rb
134
+ - lib/minke/helpers.rb
135
+ - lib/minke/rake/app.rake
136
+ - lib/minke/rake/config.rake
137
+ - lib/minke/rake/docker.rake
138
+ - lib/minke/version.rb
139
+ - minke.gemspec
140
+ homepage: https://github.com/nicholasjackson/minke
141
+ licenses:
142
+ - MIT
143
+ metadata: {}
144
+ post_install_message:
145
+ rdoc_options: []
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ requirements: []
159
+ rubyforge_project:
160
+ rubygems_version: 2.4.5
161
+ signing_key:
162
+ specification_version: 4
163
+ summary: Minke is a suite of rake tasks for building and testing microservices with
164
+ Docker. Currently supporting Google Go, Node.js services are coming soon.
165
+ test_files: []