go_builder 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +14 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/examples/config.yml +39 -0
- data/go_builder.gemspec +29 -0
- data/lib/go_builder/docker_compose.rb +31 -0
- data/lib/go_builder/go_docker.rb +77 -0
- data/lib/go_builder/helpers.rb +45 -0
- data/lib/go_builder/rake/app.rake +137 -0
- data/lib/go_builder/rake/config.rake +10 -0
- data/lib/go_builder/rake/docker.rake +11 -0
- data/lib/go_builder/version.rb +3 -0
- data/lib/go_builder.rb +11 -0
- metadata +165 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2a5b0d30faaad21c9c6d69b5d3d43d57cfd33821
|
4
|
+
data.tar.gz: 9f819ec499ebc51eba5828729bac96e30da57d18
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bb07810353c21a4f804b4013924da734c1df5df87ee4719ba28b6afac6e340c31b02cffd12ad984af738d0190229622f8204b8ba4bd68cbfe2dd6a5eac0c242b
|
7
|
+
data.tar.gz: 7720f0257d8c9385dc9634d53ad9b584d2e61a07b1a4d8d108035ec589773bb574081cf148f3c57ee8832b437f15b981cb1ca6cc660bc7a66bdb64e38ba8269f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
go_builder
|
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
|
+
api_key:
|
11
|
+
secure: GRtgzVc4BWoriFpF1h57w1ndS8HhIndKyTH3WIXShs/yKtoz6zlTIURtkBRTb0pNsIcb+kla2JbJ0BfECz6MRlKGBKBCTv81HRilKW3qCWS9F3VpOX4NobcBCZVtDrhlMAnumf3/xHF3ZrUAEr7BCNhTfgs1bQLaXvw+K8plMi731DC0odyIA3CHwt+2bmERE6s3FwKIH+kpPZAUuHNyVqPPCInpaHE4lTEJN26sZWrM4QPO6Ms1PQxPBlYe3H6JXtGAEde6c14PGZpOy3kf8xF9o3prMm1ralwwPlQrZIq0FcuqYb27jBXGX7GEfJIUsnaR8UIVKpk1itiHLFWf1x3pG5SAks6iIAM+L9hGQIDFb+geM+GMUxTE/nHDWrjH3st+HOjAs8lkZlNIwNnxZrnngV5rzbaOq1YWPg1FxGhkjAoZRQ225xeJOxD+S7p27cnV2iGrevrqn2Ud3n0uxeaRXcXiXBWxV5Otzc7m/fYG+No/mm87r4F2Jn+BN88puhI2eBk/oO7fgB1BeYEJ7wrV3kjsdHAcIO9MPG59jZ+Dpsut5CJQVK6ASOd3DTYmbTLiiZZlIK9gHf43MsR45GmY0tSk4wwY4hPWKmZtX6wEmLjD9sTGWeeMnPIVomKzB76Zyd60qNm/MzUMesSHGX80AGnHY7yQIc02deyWMYs=
|
12
|
+
gem: go_builder
|
13
|
+
on:
|
14
|
+
repo: nicholasjackson/go_builder
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -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
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,41 @@
|
|
1
|
+
# GoBuilder
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/go_builder`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'go_builder'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install go_builder
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
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.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "go_builder"
|
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
data/examples/config.yml
ADDED
@@ -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
|
+
pass: <%= 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'
|
data/go_builder.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 'go_builder/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "go_builder"
|
8
|
+
spec.version = GoBuilder::VERSION
|
9
|
+
spec.authors = ["Nic Jackson"]
|
10
|
+
spec.email = ["jackson.nic@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Go builder is a set of rake tasks for building and testing your go application with Docker."
|
13
|
+
spec.homepage = "https://github.com/nicholasjackson/go_builder"
|
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
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module GoBuilder
|
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,77 @@
|
|
1
|
+
module GoBuilder
|
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 = 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
|
+
sh "docker login -u #{args[:docker_registry][:user]} -p #{args[:docker_registry][:password]} -e #{args[:docker_registry][:email]} #{args[:docker_registry][:url]}"
|
74
|
+
sh "docker push #{args[:docker_registry][:namespace]}/#{args[:go][:application_name]}:latest"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module GoBuilder
|
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,137 @@
|
|
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 = GoBuilder::Helpers.config
|
7
|
+
container = GoBuilder::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 = GoBuilder::Helpers.config
|
30
|
+
container = GoBuilder::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 = GoBuilder::Helpers.config
|
50
|
+
|
51
|
+
if config['after_build'] != nil && config['after_build']['copy_assets'] != nil
|
52
|
+
GoBuilder::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 = GoBuilder::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 = GoBuilder::Helpers.config
|
71
|
+
compose = GoBuilder::DockerCompose.new config['docker']['compose_file']
|
72
|
+
|
73
|
+
begin
|
74
|
+
compose.up
|
75
|
+
|
76
|
+
if config['run']['consul_loader']['enabled']
|
77
|
+
GoBuilder::Helpers.wait_until_server_running "#{config['run']['consul_loader']['url']}/v1/status/leader", 0
|
78
|
+
loader = ConsulLoader::Loader.new(ConsulLoader::ConfigParser.new)
|
79
|
+
loader.load_config config['run']['consul_loader']['config_file'], config['run']['consul_loader']['url']
|
80
|
+
end
|
81
|
+
|
82
|
+
compose.logs
|
83
|
+
rescue SystemExit, Interrupt
|
84
|
+
compose.stop
|
85
|
+
compose.rm
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
desc "build and run application with Docker Compose"
|
90
|
+
task :build_and_run => [:build_server, :run]
|
91
|
+
|
92
|
+
desc "run end to end Cucumber tests USAGE: rake app:cucumber[@tag]"
|
93
|
+
task :cucumber, [:feature] => ['config:set_docker_env', 'config:load_config'] do |t, args|
|
94
|
+
config = GoBuilder::Helpers.config
|
95
|
+
|
96
|
+
puts "Running cucumber with tags #{args[:feature]}"
|
97
|
+
|
98
|
+
if args[:feature] != nil
|
99
|
+
feature = "--tags #{args[:feature]}"
|
100
|
+
else
|
101
|
+
feature = ""
|
102
|
+
end
|
103
|
+
|
104
|
+
status = 0
|
105
|
+
|
106
|
+
compose = GoBuilder::DockerCompose.new config['docker']['compose_file']
|
107
|
+
begin
|
108
|
+
compose.up
|
109
|
+
|
110
|
+
if config['cucumber']['consul_loader']['enabled']
|
111
|
+
GoBuilder::Helpers.wait_until_server_running "#{config['cucumber']['consul_loader']['url']}/v1/status/leader", 0
|
112
|
+
loader = ConsulLoader::Loader.new(ConsulLoader::ConfigParser.new)
|
113
|
+
loader.load_config config['cucumber']['consul_loader']['config_file'], config['cucumber']['consul_loader']['url']
|
114
|
+
end
|
115
|
+
|
116
|
+
if config['cucumber']['health_check']['enabled']
|
117
|
+
GoBuilder::Helpers.wait_until_server_running config['cucumber']['health_check']['url'], 0
|
118
|
+
end
|
119
|
+
|
120
|
+
sh "cucumber --color -f pretty #{feature}"
|
121
|
+
status = $?.exitstatus
|
122
|
+
ensure
|
123
|
+
compose.stop
|
124
|
+
compose.rm
|
125
|
+
|
126
|
+
abort "Cucumber steps failed" unless status == 0
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
desc "push built image to Docker registry"
|
131
|
+
task :push => [:load_config] do
|
132
|
+
p "Push image to registry"
|
133
|
+
|
134
|
+
config = GoBuilder::Helpers.config
|
135
|
+
GoBuilder::Docker.tag_and_push config
|
136
|
+
end
|
137
|
+
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
|
+
GoBuilder::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
|
+
GoBuilder::GoDocker.pull_image 'golang' unless GoBuilder::GoDocker.find_image 'golang:latest'
|
10
|
+
end
|
11
|
+
end
|
data/lib/go_builder.rb
ADDED
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: go_builder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nic Jackson
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-24 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
|
+
- go_builder.gemspec
|
132
|
+
- lib/go_builder.rb
|
133
|
+
- lib/go_builder/docker_compose.rb
|
134
|
+
- lib/go_builder/go_docker.rb
|
135
|
+
- lib/go_builder/helpers.rb
|
136
|
+
- lib/go_builder/rake/app.rake
|
137
|
+
- lib/go_builder/rake/config.rake
|
138
|
+
- lib/go_builder/rake/docker.rake
|
139
|
+
- lib/go_builder/version.rb
|
140
|
+
homepage: https://github.com/nicholasjackson/go_builder
|
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.1
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: Go builder is a set of rake tasks for building and testing your go application
|
164
|
+
with Docker.
|
165
|
+
test_files: []
|