horatio 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +24 -0
  3. data/.rubocop.yml +169 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +25 -0
  6. data/Gemfile +10 -0
  7. data/Guardfile +10 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +73 -0
  10. data/Rakefile +13 -0
  11. data/bin/horatio +33 -0
  12. data/horatio.gemspec +30 -0
  13. data/lib/horatio.rb +64 -0
  14. data/lib/horatio/detector.rb +14 -0
  15. data/lib/horatio/detector/docker.rb +39 -0
  16. data/lib/horatio/detector/dynamic.rb +33 -0
  17. data/lib/horatio/detector/io_handler.rb +44 -0
  18. data/lib/horatio/detector/json_reader.rb +15 -0
  19. data/lib/horatio/detector/json_writer.rb +26 -0
  20. data/lib/horatio/detector/maven.rb +48 -0
  21. data/lib/horatio/detector/node_package.rb +30 -0
  22. data/lib/horatio/detector/null_writer.rb +11 -0
  23. data/lib/horatio/detector/rubygem.rb +32 -0
  24. data/lib/horatio/detector/validator.rb +20 -0
  25. data/lib/horatio/helper/vcs.rb +12 -0
  26. data/lib/horatio/releaser.rb +45 -0
  27. data/lib/horatio/vcs.rb +11 -0
  28. data/lib/horatio/vcs/git.rb +41 -0
  29. data/lib/horatio/vcs/subversion.rb +23 -0
  30. data/lib/horatio/version.rb +3 -0
  31. data/spec/fixtures/dynamic +10 -0
  32. data/spec/fixtures/package.json +105 -0
  33. data/spec/fixtures/pom.xml +822 -0
  34. data/spec/fixtures/test.gemspec +32 -0
  35. data/spec/horatio/detector/docker_spec.rb +30 -0
  36. data/spec/horatio/detector/dynamic_spec.rb +19 -0
  37. data/spec/horatio/detector/maven_spec.rb +27 -0
  38. data/spec/horatio/detector/node_package_spec.rb +19 -0
  39. data/spec/horatio/detector/rubygem_spec.rb +28 -0
  40. data/spec/horatio/releaser_spec.rb +25 -0
  41. data/spec/horatio/vcs/git_spec.rb +22 -0
  42. data/spec/horatio/vcs/subversion_spec.rb +15 -0
  43. data/spec/spec_helper.rb +12 -0
  44. data/spec/support/fixture_copy.rb +28 -0
  45. data/spec/support/reporters.rb +3 -0
  46. metadata +232 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 810e9dd10448c938b943a08cb2d298a08424625e
4
+ data.tar.gz: d01dbe1c2ccf868cc5a0334afbb084863b1dae2e
5
+ SHA512:
6
+ metadata.gz: adb636fd02c7d411b1a0e39d99ba4bd9d7965a458438b2a46d0be73a0167e32e25983770d82ebbb791ea7a58beb97f39a17bf42e9f0db00628d40fd97cf45d63
7
+ data.tar.gz: 3eb7f85ccc942473c595161bec6d7e62ac2003718f6ee26529b9643dab2d19abc0a5e057e5fddb26f9a9489ff209571a1ab57be0e0fd866994082e6b64ebc7b8
@@ -0,0 +1,24 @@
1
+ Gemfile.lock
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ test
19
+ docker-image.json
20
+ docker-build.json
21
+ horatio.json
22
+ *.gems
23
+ *.bin
24
+ *.swp
@@ -0,0 +1,169 @@
1
+ Lint/DeprecatedClassMethods:
2
+ Exclude:
3
+ - 'lib/horatio/detector/io_handler.rb'
4
+
5
+ Lint/RescueException:
6
+ Exclude:
7
+ - 'bin/horatio'
8
+
9
+ Lint/UselessAssignment:
10
+ Exclude:
11
+ - 'lib/horatio.rb'
12
+
13
+ Metrics/AbcSize:
14
+ Max: 20
15
+
16
+ Metrics/LineLength:
17
+ Max: 201
18
+
19
+ Metrics/MethodLength:
20
+ Max: 11
21
+
22
+ Performance/RedundantMatch:
23
+ Exclude:
24
+ - 'lib/horatio/detector/validator.rb'
25
+
26
+ Style/BracesAroundHashParameters:
27
+ Exclude:
28
+ - 'lib/horatio/releaser.rb'
29
+ - 'spec/horatio/releaser_spec.rb'
30
+ - 'spec/horatio/vcs/git_spec.rb'
31
+
32
+ Style/CommentAnnotation:
33
+ Exclude:
34
+ - 'spec/horatio/releaser_spec.rb'
35
+ - 'spec/horatio/vcs/git_spec.rb'
36
+
37
+ Style/CommentIndentation:
38
+ Exclude:
39
+ - 'spec/horatio/detector/rubygem_spec.rb'
40
+
41
+ Style/Documentation:
42
+ Exclude:
43
+ - 'spec/**/*'
44
+ - 'test/**/*'
45
+ - 'lib/horatio/detector.rb'
46
+ - 'lib/horatio/detector/docker.rb'
47
+ - 'lib/horatio/detector/dynamic.rb'
48
+ - 'lib/horatio/detector/io_handler.rb'
49
+ - 'lib/horatio/detector/json_reader.rb'
50
+ - 'lib/horatio/detector/json_writer.rb'
51
+ - 'lib/horatio/detector/maven.rb'
52
+ - 'lib/horatio/detector/node_package.rb'
53
+ - 'lib/horatio/detector/null_writer.rb'
54
+ - 'lib/horatio/detector/rubygem.rb'
55
+ - 'lib/horatio/detector/validator.rb'
56
+ - 'lib/horatio/releaser.rb'
57
+ - 'lib/horatio/vcs.rb'
58
+ - 'lib/horatio/vcs/git.rb'
59
+ - 'lib/horatio/vcs/subversion.rb'
60
+
61
+ Style/EmptyLinesAroundBlockBody:
62
+ Exclude:
63
+ - 'spec/horatio/vcs/git_spec.rb'
64
+ - 'spec/horatio/vcs/subversion_spec.rb'
65
+
66
+ Style/EmptyLinesAroundClassBody:
67
+ Exclude:
68
+ - 'lib/horatio/releaser.rb'
69
+ - 'lib/horatio/vcs/git.rb'
70
+ - 'lib/horatio/vcs/subversion.rb'
71
+
72
+ Style/EmptyLinesAroundModuleBody:
73
+ Exclude:
74
+ - 'lib/horatio/helper/vcs.rb'
75
+
76
+ Style/ExtraSpacing:
77
+ Exclude:
78
+ - 'spec/spec_helper.rb'
79
+
80
+ Style/IndentArray:
81
+ EnforcedStyle: consistent
82
+
83
+ Style/IndentationWidth:
84
+ Exclude:
85
+ - 'Rakefile'
86
+ - 'lib/horatio/vcs.rb'
87
+ - 'lib/horatio/vcs/git.rb'
88
+
89
+ Style/LeadingCommentSpace:
90
+ Exclude:
91
+ - 'spec/horatio/detector/docker_spec.rb'
92
+ - 'spec/horatio/releaser_spec.rb'
93
+ - 'spec/horatio/vcs/git_spec.rb'
94
+
95
+ Style/MutableConstant:
96
+ Exclude:
97
+ - 'lib/horatio.rb'
98
+ - 'lib/horatio/version.rb'
99
+
100
+ Style/ParallelAssignment:
101
+ Exclude:
102
+ - 'lib/horatio.rb'
103
+
104
+ Style/PercentLiteralDelimiters:
105
+ Exclude:
106
+ - 'horatio.gemspec'
107
+ - 'spec/fixtures/test.gemspec'
108
+
109
+ Style/RedundantReturn:
110
+ Exclude:
111
+ - 'lib/horatio/releaser.rb'
112
+
113
+ Style/RegexpLiteral:
114
+ Exclude:
115
+ - 'Guardfile'
116
+
117
+ Style/GuardClause:
118
+ Exclude:
119
+ - 'lib/horatio.rb'
120
+
121
+ Style/Semicolon:
122
+ Exclude:
123
+ - 'lib/horatio.rb'
124
+
125
+ Style/SpaceAfterComma:
126
+ Exclude:
127
+ - 'bin/horatio'
128
+
129
+ Style/SpaceAfterMethodName:
130
+ Exclude:
131
+ - 'lib/horatio.rb'
132
+
133
+ Style/SpaceAroundBlockParameters:
134
+ Exclude:
135
+ - 'lib/horatio/releaser.rb'
136
+
137
+ Style/SpaceAroundEqualsInParameterDefault:
138
+ EnforcedStyle: no_space
139
+
140
+ Style/SpaceAroundOperators:
141
+ Exclude:
142
+ - 'spec/spec_helper.rb'
143
+
144
+ Style/SpaceInsideBlockBraces:
145
+ Enabled: false
146
+
147
+ Style/SpaceInsideHashLiteralBraces:
148
+ Enabled: false
149
+
150
+ Style/SpaceInsideStringInterpolation:
151
+ Exclude:
152
+ - 'lib/horatio/releaser.rb'
153
+
154
+ Style/StringLiterals:
155
+ Enabled: false
156
+
157
+ Style/SymbolProc:
158
+ Exclude:
159
+ - 'lib/horatio/detector.rb'
160
+ - 'lib/horatio/vcs.rb'
161
+
162
+ Style/UnlessElse:
163
+ Exclude:
164
+ - 'lib/horatio.rb'
165
+
166
+ Style/UnneededPercentQ:
167
+ Exclude:
168
+ - 'horatio.gemspec'
169
+ - 'spec/fixtures/test.gemspec'
@@ -0,0 +1 @@
1
+ 2.2.4
@@ -0,0 +1,25 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1
5
+ - 2.2
6
+ - ruby-head
7
+ - jruby-19mode
8
+ - jruby-head
9
+
10
+ before_install:
11
+ - gem update bundler
12
+
13
+ bundler_args: --without guard
14
+
15
+ script: bundle exec rake
16
+
17
+ matrix:
18
+ allow_failures:
19
+ - rvm: ruby-head
20
+ - rvm: jruby-head
21
+ - rvm: jruby-19mode
22
+ fast_finish: true
23
+
24
+ notifications:
25
+ email: pauly@buzbox.net
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in horatio.gemspec
4
+ gemspec
5
+
6
+ group :guard do
7
+ gem 'guard'
8
+ gem 'guard-minitest'
9
+ gem 'guard-rubocop'
10
+ end
@@ -0,0 +1,10 @@
1
+ guard :minitest do
2
+ watch(%r{^spec/(.*)_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
5
+ end
6
+
7
+ guard :rubocop do
8
+ watch(%r{.+\.rb$})
9
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
10
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Pauly Myjavec
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,73 @@
1
+ # Horatio
2
+
3
+ [![Build Status](https://travis-ci.org/pmyjavec/horatio.svg?branch=master)](https://travis-ci.org/pmyjavec/horatio)
4
+
5
+ Horatio helps you build a Docker image for the project you're working on and produces an artifact (JSON document) which
6
+ contains meta-data about the image produced, this artifact than can be used in your build pipeline to do things like
7
+ deploy containers with a configuration management tool / scheduler of your choice, Ansible for example.
8
+
9
+ Horatio's advantage is that it stays out of your way and let's you get on with building great software.
10
+
11
+ Horatio is most handy if you have an existing build pipeline and just want to try Docker containers out for your project with
12
+ minimal fuss or have a lot of services to build, especially in different languages.
13
+
14
+ ## Automatic Project Detection
15
+
16
+ If, for example, you have a Java project which you build and manage with maven Horatio can parse a POM for you, strip the name and
17
+ version and build and push a Docker container to a registry for you.
18
+
19
+ The automatic project detection is also good if you're nailing up several services in different languages, this helps
20
+ automate building of Docker containers in a fast and simple manner, it's been used this way in the past.
21
+
22
+ ### Supported project types
23
+
24
+ Horatio automatically detects the kind of project you're working with and acts accordingly so far it supports:
25
+
26
+ * Maven
27
+ * Ruby Gems
28
+ * Node JS
29
+
30
+ If you use a Horatio document then Horatio will increment the version, commit
31
+ and push it back the source repository for you. In all other cases Horatio will
32
+ leave your existing version management alone.
33
+
34
+ ## Arbitrary Container Builds
35
+
36
+ This workflow is best if you just would like to build something like a Redis image.
37
+
38
+ If you just need to get an arbitrary project built and pushed somewhere you can simply create a horatio.json, like so:
39
+
40
+ To get started, Create a Horatio spec `horatio.json` in your project root with the contents `{'name': 'misc-project', 'version': '0.0.1'}`
41
+
42
+ _This workflow automatically increments the 'version' in the spec and pushes it back to your repository, this will be
43
+ configurable soon_
44
+
45
+ ## Usage
46
+
47
+ To install
48
+
49
+ ```
50
+ $ gem install horatio
51
+ $ horatio
52
+ ```
53
+
54
+ To prevent caching of a build, export the following environment variable before running horatio
55
+ `DOCKER_BUILD_NO_CACHE=1`
56
+
57
+ ## Dev
58
+
59
+ ```
60
+ bundle install
61
+ guard
62
+ ```
63
+
64
+ ## Why do versions contain source repository revisions
65
+
66
+ Unfortunately the Docker registry handles tags as mutable objects. If you push a
67
+ image to the registry with the same name and version tag you will overwrite the
68
+ previous tag. Inserting the revision from the latest git commit ensures
69
+ we don't end up with collisions.
70
+
71
+ ## Horatio?
72
+
73
+ In honour of [Horatio McAllister](http://simpsons.wikia.com/wiki/Horatio_McCallister)
@@ -0,0 +1,13 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'rubocop/rake_task'
4
+
5
+ RuboCop::RakeTask.new
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << 'lib'
9
+ t.libs << 'spec'
10
+ t.pattern = 'spec/**/*_spec.rb'
11
+ end
12
+
13
+ task default: [:test, :rubocop]
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "horatio"
4
+ require "optparse"
5
+
6
+ options = {}
7
+
8
+ OptionParser.new do |opts|
9
+ opts.banner = "Horatio takes no arguments, only some options, you should run it from the same directory as your Dockerfile.
10
+
11
+ Usage: horatio [options]"
12
+
13
+ opts.on("-g", "--git-repo-url [URL]", String,"The URL of the remote repo. This is only used by the 'horatio' build type to push back an updated horatio.json once the release number is bumped") do |g|
14
+ options['git-repo-url'] = g
15
+ end
16
+
17
+ opts.on("-r", "--registry [URL]", String,"The URL of the docker registry or docker hub username.") do |g|
18
+ options['registry'] = g
19
+ end
20
+
21
+ opts.on_tail("-h", "--help", "Show this message") do
22
+ puts opts
23
+ exit
24
+ end
25
+ end.parse!
26
+
27
+ begin
28
+ releaser = Horatio::Releaser.new(options)
29
+ releaser.run
30
+ rescue Exception => e
31
+ color(ERROR) { Log.fatal e }
32
+ exit 1
33
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'horatio/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "horatio"
8
+ spec.version = Horatio::VERSION
9
+ spec.authors = ["Pauly Myjavec", "Rufus Post"]
10
+ spec.email = ["pauly@buzbox.net", "rufuspost@gmail.com"]
11
+ spec.summary = %q{Horatio, shipping your Docker images}
12
+ spec.description = %q{Horatio, shipping your Docker images from a CI server}
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "nokogiri"
21
+ spec.add_dependency "nori"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "pry"
26
+ spec.add_development_dependency "minitest", "~> 4"
27
+ spec.add_development_dependency "minitest-reporters"
28
+ spec.add_development_dependency "fakefs"
29
+ spec.add_development_dependency "rubocop"
30
+ end
@@ -0,0 +1,64 @@
1
+ require 'logger'
2
+ require 'open3'
3
+ require 'json'
4
+
5
+ ### BEGIN CONFIG ###
6
+ USE = <<-EOS
7
+ ./build_docker_image.rb [<name> <version>]
8
+
9
+ set DRY_RUN=true if you would like debugging output
10
+
11
+ The Dockefile you have specified does not contain the required name and version
12
+ comments nor have you provided any via the CLI, please add the following after
13
+ FROM in you Dockerfile:
14
+
15
+ #name\=awesome-app
16
+ #version=0.0.1
17
+ #test_command=/bin/true
18
+ EOS
19
+
20
+ ERROR = 31
21
+ SUCCESS = 32
22
+ ATTN = 35
23
+
24
+ Log = Logger.new(STDOUT)
25
+ Log.level = Logger::INFO
26
+
27
+ def color (color=SUCCESS)
28
+ printf "\033[#{color}m";
29
+ yield
30
+ printf "\033[0m"
31
+ end
32
+
33
+ begin
34
+ raise if RUBY_VERSION =~ /^1\.8.*$/
35
+ rescue
36
+ color(ERROR) { Log.fatal("This script only works on Ruby > 1.8") }
37
+ exit 1
38
+ end
39
+
40
+ ### END CONFIG ###
41
+
42
+ def sh(cmd)
43
+ o, e, s = nil, nil, nil
44
+ o, e, s = Open3.capture3(*cmd)
45
+ end
46
+
47
+ def run_sh(cmd)
48
+ unless ENV['DRY_RUN']
49
+ color { Log.info "executing command: #{cmd}" }
50
+ o, e, s = sh(cmd)
51
+
52
+ if s.exitstatus == 0
53
+ color { Log.info "succesfully executed command `#{cmd}` output:\n #{o}" }
54
+ else
55
+ raise "execution of `#{cmd}` failed output from STDERR was:\n #{e}\n STDOUT was:\n #{o}"
56
+ end
57
+ else
58
+ color { Log.info "dry run: would've executed command `#{cmd}`" }
59
+ end
60
+ end
61
+
62
+ require 'horatio/releaser'
63
+ require 'horatio/detector'
64
+ require 'horatio/vcs'