brocket 0.0.2

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: 30dc6163a3b7acbe9cba9792ec3a8245ee1dd674
4
+ data.tar.gz: c3830af93db70d56bf2b553e2ea1ee63e694ff9d
5
+ SHA512:
6
+ metadata.gz: aa61def37a83d76a6315b5429f97ca0d48a5048b8af736fc898cbae783d559644a595bf0f86128958b23f0424e2b54434c4ddf402d1316ad69aa4e76ad969587
7
+ data.tar.gz: 07afa57f839d2c32a4e8a8ea052f2d008aaa0180824ef21f1da84befe20c3b890fb166374649517a8bf4e1147a00ff41d9b7b741818b47aa44590179c4afa09c
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ /VERSION
16
+ /Dockerfile
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in brocket.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Groovenauts, Inc.
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.
data/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # brocket
2
+
3
+ brocket supports to build docker image with VERSION file and git.
4
+ brocket perfoms like rake tasks generated by `bundle gem` command.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'brocket'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install brocket
21
+
22
+ ## Usage
23
+
24
+ ### init
25
+
26
+ ```
27
+ brocket init
28
+ ```
29
+
30
+ Then VERSION file will be created.
31
+
32
+ ### add config
33
+
34
+ add following line to your Dockerfile.
35
+
36
+ ```
37
+ # [config] IMAGE_NAME: "groovenauts/rails-example"
38
+ ```
39
+
40
+ example https://github.com/tengine/brocket/blob/master/spec/brocket/Dockerfiles/Dockerfile-basic#L2
41
+
42
+ ### bump up VERSION
43
+
44
+ When you increment VERSION file, you can use theese commands.
45
+
46
+ ```
47
+ brocket version major # bump up major version of VERSION file
48
+ brocket version minor # bump up minor version of VERSION file
49
+ brocket version bump # bump up last number of VERSION file
50
+ ```
51
+
52
+ ### Hooks
53
+
54
+ You can define commands to execute around build like this:
55
+
56
+ ```
57
+ # [config] IMAGE_NAME: "groovenauts/rails-example"
58
+ # [config]
59
+ # [config] BEFORE_BUILD:
60
+ # [config] - abc
61
+ # [config] - def ghi
62
+ # [config]
63
+ # [config] AFTER_BUILD:
64
+ # [config] - "jkl"
65
+ # [config] - mno
66
+ # [config]
67
+ # [config] ON_BUILD_COMPLETE: foo bar
68
+ # [config]
69
+ # [config] ON_BUILD_ERROR: "baz"
70
+ # [config]
71
+ ```
72
+
73
+
74
+ https://github.com/tengine/brocket/blob/master/spec/brocket/Dockerfiles/Dockerfile-hook
75
+
76
+
77
+ ### For more information
78
+
79
+ ```
80
+ brocket help
81
+ ```
82
+
83
+ or https://github.com/tengine/brocket/tree/master/spec/brocket
84
+
85
+
86
+
87
+ ## Contributing
88
+
89
+ 1. Fork it ( https://github.com/groovenauts/brocket/fork )
90
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
91
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
92
+ 4. Push to the branch (`git push origin my-new-feature`)
93
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # ENV['gem_push'] = "no"
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
data/bin/brocket ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'brocket'
4
+
5
+ begin
6
+ BRocket::Cli.start(ARGV)
7
+ rescue BRocket::BuildError => e
8
+ $stderr.puts("\e[31m#{e.message}\e[0m")
9
+ exit(1)
10
+ rescue => e
11
+ $stderr.puts("\e[31m[#{e.class}] #{e.message}\e[0m\n " << e.backtrace.join("\n "))
12
+ exit(1)
13
+ end
data/brocket.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'brocket/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "brocket"
8
+ spec.version = BRocket::VERSION
9
+ spec.authors = ["akima"]
10
+ spec.email = ["t-akima@groovenauts.jp"]
11
+ spec.summary = %q{supports to build Docker Container with VERSION}
12
+ spec.description = %q{supports to build Docker Container with VERSION}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "thor"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec"
26
+ end
@@ -0,0 +1,72 @@
1
+ require "brocket"
2
+
3
+ require 'thor'
4
+
5
+ module BRocket
6
+ class Base < Thor
7
+ class_option :verbose, :type => :boolean
8
+ class_option :dryrun , :type => :boolean
9
+
10
+ no_commands do
11
+
12
+ def sub(klass)
13
+ task = klass.new
14
+ task.options = self.options
15
+ task
16
+ end
17
+
18
+ def dryrun?
19
+ (options || {})[:dryrun]
20
+ end
21
+
22
+ def verbose?
23
+ (options || {})[:verbose]
24
+ end
25
+
26
+ def chdir(dir, &block)
27
+ dir ||= "."
28
+ verbose("cd #{dir}")
29
+ Dir.chdir(dir, &block)
30
+ verbose("cd #{Dir.pwd}")
31
+ end
32
+
33
+ def verbose(msg)
34
+ $stderr.puts("\e[34m#{msg}\e[0m") if verbose?
35
+ end
36
+
37
+ def info(msg)
38
+ $stderr.puts(msg)
39
+ end
40
+ def success(msg)
41
+ $stderr.puts("\e[32m#{msg}\e[0m")
42
+ end
43
+
44
+ def error(msg)
45
+ raise BuildError, msg
46
+ end
47
+
48
+ def sh(cmd, &block)
49
+ out, code = sh_with_code(cmd, &block)
50
+ code == 0 ? out : error(out.empty? ? "Running `#{cmd}' failed. Run this command directly for more detailed output." : out)
51
+ end
52
+
53
+ def sh_with_code(cmd, &block)
54
+ cmd << " 2>&1"
55
+ verbose(cmd)
56
+ outbuf = ''
57
+ if dryrun?
58
+ block.call(outbuf) if block
59
+ ["DRYRUN", 0]
60
+ else
61
+ outbuf = `#{cmd}`
62
+ if $? == 0
63
+ block.call(outbuf) if block
64
+ end
65
+ [outbuf, $?]
66
+ end
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,39 @@
1
+ require "brocket"
2
+
3
+ module BRocket
4
+ class Cli < Base
5
+
6
+ desc "init", "initialize current directory"
7
+ def init
8
+ sub(VersionFile).init
9
+ end
10
+
11
+ desc "bump", "bump up 3rd number in VERSION"
12
+ def bump
13
+ sub(VersionFile).bump
14
+ end
15
+
16
+ desc "build", "build docker image"
17
+ def build
18
+ sub(Docker).build
19
+ end
20
+
21
+ desc "release [DIRECTORY]", "build docker image, tag it, push tag and push docker image to docker hub"
22
+ def release(dir = nil)
23
+ sub(Git).guard_clean
24
+ sub(Docker).build(dir)
25
+ sub(Git).push
26
+ sub(Docker).push(dir)
27
+ end
28
+
29
+ desc "version SUBCOMMAND ...ARGS", "manage VERSION file"
30
+ subcommand "version", VersionFile
31
+
32
+ desc "docker SUBCOMMAND ...ARGS", "manage docker"
33
+ subcommand "docker", Docker
34
+
35
+ desc "git SUBCOMMAND ...ARGS", "manage git commit"
36
+ subcommand "git", Git
37
+
38
+ end
39
+ end
@@ -0,0 +1,76 @@
1
+ require "brocket"
2
+
3
+ require 'yaml'
4
+ require 'thor'
5
+
6
+ module BRocket
7
+ class Docker < Base
8
+ CONFIG_LINE_SEP = "[config]".freeze
9
+ CONFIG_LINE_HEADER = /\A\#\s*#{Regexp.escape(CONFIG_LINE_SEP)}\s?/.freeze
10
+
11
+ desc "config [DIRECTORY]", "show configurations in Dockerfile"
12
+ def config(dir = nil)
13
+ $stdout.puts(YAML.dump(config_hash(dir)))
14
+ end
15
+
16
+ desc "build [DIRECTORY]", "build docker image at DIRECTORY or PWD"
17
+ def build(dir = nil)
18
+ info("[docker build] starting")
19
+ dir ||= "."
20
+ c = config_hash(dir)
21
+ img_name = config_image_name(c)
22
+ chdir(dir) do
23
+ begin
24
+ execute(c['BEFORE_BUILD'])
25
+ execute("docker build -t #{img_name}:#{VersionFile.current} .")
26
+ execute(c['ON_BUILD_COMPLETE'])
27
+ rescue
28
+ execute(c['ON_BUILD_ERROR'])
29
+ ensure
30
+ execute(c['AFTER_BUILD'])
31
+ end
32
+ end
33
+ success("[docker build] OK")
34
+ end
35
+
36
+ desc "push [DIRECTORY]", "push docker image to docker hub"
37
+ def push(dir = nil)
38
+ info("[docker push] starting")
39
+ c = config_hash(dir || ".")
40
+ img_name = config_image_name(c)
41
+ cmd = "docker push #{img_name}:#{VersionFile.current}"
42
+ sh(cmd)
43
+ success("[docker push] OK")
44
+ end
45
+
46
+ no_commands do
47
+ def config_image_name(c)
48
+ img_name = (c['IMAGE_NAME'] || '').strip
49
+ error "No IMAGE_NAME found in #{dir}/Dockerfile. Please add `# #{CONFIG_LINE_SEP} IMAGE_NAME: [IMAGE NAME on DockerHub]` in #{dir}/Dockerfile" if img_name.empty?
50
+ img_name
51
+ end
52
+
53
+ def config_hash(dir = nil)
54
+ dir ||= "."
55
+ chdir(dir) do
56
+ content = read_file
57
+ lines = content.lines.select{|line| line =~ CONFIG_LINE_HEADER}.
58
+ map{|line| line.sub(CONFIG_LINE_HEADER, "")}
59
+ return (YAML.load(lines.join("\n")) || {})
60
+ end
61
+ end
62
+
63
+ def read_file
64
+ File.read("Dockerfile")
65
+ end
66
+
67
+ def execute(commands)
68
+ return unless commands
69
+ commands = commands.is_a?(Array) ? commands : [commands]
70
+ commands = commands.compact.map(&:strip).reject(&:empty?)
71
+ commands.each{|cmd| sh(cmd) }
72
+ end
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,69 @@
1
+ require "brocket"
2
+
3
+ module BRocket
4
+ class Git < Base
5
+
6
+ desc "guard_clean", "Raise error if some difference exists."
7
+ def guard_clean
8
+ clean? && committed? or error("There are files that need to be committed first. Run `git status`")
9
+ success("[git guard_clean] OK")
10
+ end
11
+
12
+ desc "push", "push commit and tag it"
13
+ def push
14
+ info("[git push] starting")
15
+ tag_version { git_push } unless already_tagged?
16
+ success("[git push] OK")
17
+ end
18
+
19
+ no_commands do
20
+
21
+ def commit(filepath, msg)
22
+ sh("git add #{filepath} && git commit -m \"#{msg}\"")
23
+ end
24
+
25
+ def clean?
26
+ sh_with_code("git diff --exit-code")[1] == 0
27
+ end
28
+
29
+ def committed?
30
+ sh_with_code("git diff-index --quiet --cached HEAD")[1] == 0
31
+ end
32
+
33
+ def tag_version
34
+ sh "git tag -a -m \"Version #{version_tag}\" #{version_tag}"
35
+ $stdout.puts "Tagged #{version_tag}."
36
+ yield if block_given?
37
+ rescue
38
+ $stderr.puts "Untagging #{version_tag} due to error."
39
+ sh_with_code "git tag -d #{version_tag}"
40
+ raise
41
+ end
42
+
43
+ def git_push
44
+ perform_git_push
45
+ perform_git_push ' --tags'
46
+ $stdout.puts "Pushed git commits and tags."
47
+ end
48
+
49
+ def perform_git_push(options = '')
50
+ cmd = "git push #{options}"
51
+ out, code = sh_with_code(cmd)
52
+ error "Couldn't git push. `#{cmd}' failed with the following output:\n\n#{out}\n" unless code == 0
53
+ end
54
+
55
+ def already_tagged?
56
+ if sh('git tag').split(/\n/).include?(version_tag)
57
+ $stderr.puts "Tag #{version_tag} has already been created."
58
+ true
59
+ end
60
+ end
61
+
62
+ def version_tag
63
+ VersionFile.current
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,3 @@
1
+ module BRocket
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,75 @@
1
+ require "brocket"
2
+
3
+ module BRocket
4
+ class VersionFile < Base
5
+ FILENAME = "VERSION".freeze
6
+ INITIAL_VERSION = "0.0.1".freeze
7
+
8
+ desc "init [VERSION]", "initialize VERSION file in current directory"
9
+ def init(version = nil)
10
+ write_file(version || INITIAL_VERSION)
11
+ end
12
+
13
+ desc "show", "show VERSION"
14
+ def show
15
+ $stdout.puts(read_file)
16
+ end
17
+
18
+ desc "major [NUMBER]", "bump up major version of VERSION file"
19
+ def major(num = nil)
20
+ bump_on(:major, num)
21
+ end
22
+
23
+ desc "minor [NUMBER]", "bump up minor version of VERSION file"
24
+ def minor(num = nil)
25
+ bump_on(:minor, num)
26
+ end
27
+
28
+ desc "bump [NUMBER]", "bump up last number of VERSION file"
29
+ def bump(num = nil)
30
+ bump_on(:patch, num)
31
+ end
32
+
33
+ class << self
34
+ def current
35
+ if File.readable?(FILENAME)
36
+ File.read(FILENAME).strip
37
+ else
38
+ error "File not found #{FILENAME}. You can run `#{$0} init`"
39
+ end
40
+ end
41
+ end
42
+
43
+ no_commands do
44
+ def read_file
45
+ self.class.current
46
+ end
47
+ private :read_file
48
+
49
+ def write_file(version)
50
+ File.open(FILENAME, "w"){|f| f.puts(version) }
51
+ end
52
+ private :write_file
53
+
54
+ POS_TO_IDX = {major: 0, minor: 1, patch: 2}.freeze
55
+
56
+ def bump_on(pos, num)
57
+ sub(Git).guard_clean
58
+ current = read_file
59
+ body, suffix = current.split(/-/, 2)
60
+ parts = body.split(/\./)
61
+ idx = POS_TO_IDX[pos]
62
+ error "Invalid position #{pos.inspect}" unless idx
63
+ parts[idx] = num || (parts[idx].to_i + 1).to_s
64
+ ver = parts.join(".")
65
+ ver << "-" << suffix if suffix
66
+ write_file(ver)
67
+ sub(Git).commit(FILENAME, "bump up #{pos.to_s} version: #{ver}")
68
+ success("[git #{pos.to_s}] #{ver}")
69
+ ver
70
+ end
71
+ private :bump_on
72
+ end
73
+
74
+ end
75
+ end
data/lib/brocket.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "brocket/version"
2
+
3
+ module BRocket
4
+ autoload :Cli , "brocket/cli"
5
+ autoload :Base , "brocket/base"
6
+ autoload :VersionFile, "brocket/version_file"
7
+ autoload :Git , "brocket/git"
8
+ autoload :Docker , "brocket/docker"
9
+
10
+ class BuildError < StandardError
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ #
2
+ # [config] IMAGE_NAME: "groovenauts/rails-example"
3
+ #
4
+
5
+ FROM groovenauts/ruby:2.1.2
6
+ MAINTAINER tech@groovenauts.jp
7
+
8
+ ENV RAILS_ENV production
9
+
10
+ # for debug via HTTP dicrectly
11
+ EXPOSE 3000
12
+
13
+ ADD . /usr/src/app
14
+ WORKDIR /usr/src/app
15
+ VOLUME /usr/src/app/log
16
+
17
+ RUN bundle install --system
18
+
19
+ CMD ["bundle", "exec", "rails", "s", "-e", "production"]
@@ -0,0 +1,36 @@
1
+ #
2
+ # [config] IMAGE_NAME: "groovenauts/rails-example"
3
+ # [config]
4
+ # [config] # ビルド前
5
+ # [config] BEFORE_BUILD:
6
+ # [config] - abc
7
+ # [config] - def ghi
8
+ # [config]
9
+ # [config] # ビルド後(失敗時も実行されます)
10
+ # [config] AFTER_BUILD:
11
+ # [config] - "jkl"
12
+ # [config] - mno
13
+ # [config]
14
+ # [config] # ビルド成功時
15
+ # [config] ON_BUILD_COMPLETE: foo bar
16
+ # [config]
17
+ # [config] # 失敗時
18
+ # [config] ON_BUILD_ERROR: "baz"
19
+ # [config]
20
+ #
21
+
22
+ FROM groovenauts/ruby:2.1.2
23
+ MAINTAINER tech@groovenauts.jp
24
+
25
+ ENV RAILS_ENV production
26
+
27
+ # for debug via HTTP dicrectly
28
+ EXPOSE 3000
29
+
30
+ ADD . /usr/src/app
31
+ WORKDIR /usr/src/app
32
+ VOLUME /usr/src/app/log
33
+
34
+ RUN bundle install --system
35
+
36
+ CMD ["bundle", "exec", "rails", "s", "-e", "production"]
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe BRocket::Docker do
4
+
5
+ let(:subject){ BRocket::Docker.new }
6
+
7
+ describe "Dockerfile-basic" do
8
+ let(:filepath){ File.expand_path("../Dockerfiles/Dockerfile-basic", __FILE__) }
9
+ let(:image_name){ "groovenauts/rails-example" }
10
+ let(:version){ "2.3.4" }
11
+
12
+ before do
13
+ allow(subject).to receive(:read_file).with(any_args).and_return(File.read(filepath))
14
+ allow(BRocket::VersionFile).to receive(:current).and_return(version)
15
+ end
16
+
17
+ describe :config do
18
+ it{ expect(subject.config_hash).to eq({"IMAGE_NAME" => image_name}) }
19
+ end
20
+
21
+ describe :build do
22
+ it do
23
+ expect(subject).to receive(:sh).with("docker build -t #{image_name}:#{version} .")
24
+ subject.build
25
+ end
26
+ end
27
+ end
28
+
29
+
30
+ describe "Dockerfile-basic" do
31
+ let(:filepath){ File.expand_path("../Dockerfiles/Dockerfile-hook", __FILE__) }
32
+ let(:image_name){ "groovenauts/rails-example" }
33
+ let(:version){ "2.3.4" }
34
+
35
+ before do
36
+ allow(subject).to receive(:read_file).with(any_args).and_return(File.read(filepath))
37
+ allow(BRocket::VersionFile).to receive(:current).and_return(version)
38
+ end
39
+
40
+ describe :config do
41
+ it do
42
+ expected = {
43
+ "IMAGE_NAME" => image_name,
44
+ "BEFORE_BUILD" => ["abc", "def ghi"],
45
+ "AFTER_BUILD" => ["jkl", "mno"],
46
+ "ON_BUILD_COMPLETE" => "foo bar",
47
+ "ON_BUILD_ERROR" => "baz",
48
+ }
49
+ expect(subject.config_hash).to eq(expected)
50
+ end
51
+ end
52
+
53
+ describe :build do
54
+ it :success do
55
+ expect(subject).to receive(:sh).with("abc")
56
+ expect(subject).to receive(:sh).with("def ghi")
57
+ expect(subject).to receive(:sh).with("docker build -t #{image_name}:#{version} .")
58
+ expect(subject).to receive(:sh).with("foo bar")
59
+ expect(subject).to receive(:sh).with("jkl")
60
+ expect(subject).to receive(:sh).with("mno")
61
+ subject.build
62
+ end
63
+
64
+ it :error do
65
+ expect(subject).to receive(:sh).with("abc")
66
+ expect(subject).to receive(:sh).with("def ghi")
67
+ expect(subject).to receive(:sh).with("docker build -t #{image_name}:#{version} .").and_raise("build error")
68
+ expect(subject).to receive(:sh).with("baz") # not "foo bar"
69
+ expect(subject).to receive(:sh).with("jkl")
70
+ expect(subject).to receive(:sh).with("mno")
71
+ subject.build
72
+ end
73
+ end
74
+ end
75
+
76
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe BRocket::VersionFile do
4
+
5
+ let(:subject){ BRocket::VersionFile.new }
6
+
7
+ describe :init do
8
+ it :without_arg do
9
+ expect(subject).to receive(:write_file).with("0.0.1")
10
+ subject.init
11
+ end
12
+
13
+ it :with_arg do
14
+ expect(subject).to receive(:write_file).with("1.2.3")
15
+ subject.init("1.2.3")
16
+ end
17
+ end
18
+
19
+
20
+ {
21
+ major: {
22
+ without_arg: "2.2.3",
23
+ with_arg: "5.2.3",
24
+ },
25
+ minor: {
26
+ without_arg: "1.3.3",
27
+ with_arg: "1.5.3",
28
+ },
29
+ bump: {
30
+ without_arg: "1.2.4",
31
+ with_arg: "1.2.5",
32
+ },
33
+ }.each do |method_name, patterns|
34
+
35
+ describe method_name do
36
+ it :without_arg do
37
+ allow_any_instance_of(BRocket::Git).to receive(:guard_clean)
38
+ allow(subject).to receive(:read_file).and_return("1.2.3")
39
+ expect(subject).to receive(:write_file).with(patterns[:without_arg])
40
+ allow_any_instance_of(BRocket::Git).to receive(:commit).with("VERSION", instance_of(String))
41
+ subject.send(method_name)
42
+ end
43
+
44
+ it :with_arg do
45
+ allow_any_instance_of(BRocket::Git).to receive(:guard_clean)
46
+ allow(subject).to receive(:read_file).and_return("1.2.3")
47
+ expect(subject).to receive(:write_file).with(patterns[:with_arg])
48
+ allow_any_instance_of(BRocket::Git).to receive(:commit).with("VERSION", instance_of(String))
49
+ subject.send(method_name, "5")
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe BRocket do
4
+ it 'has a version number' do
5
+ expect(BRocket::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'brocket'
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brocket
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - akima
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: 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
+ description: supports to build Docker Container with VERSION
70
+ email:
71
+ - t-akima@groovenauts.jp
72
+ executables:
73
+ - brocket
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/brocket
85
+ - brocket.gemspec
86
+ - lib/brocket.rb
87
+ - lib/brocket/base.rb
88
+ - lib/brocket/cli.rb
89
+ - lib/brocket/docker.rb
90
+ - lib/brocket/git.rb
91
+ - lib/brocket/version.rb
92
+ - lib/brocket/version_file.rb
93
+ - spec/brocket/Dockerfiles/Dockerfile-basic
94
+ - spec/brocket/Dockerfiles/Dockerfile-hook
95
+ - spec/brocket/docker_spec.rb
96
+ - spec/brocket/version_file_spec.rb
97
+ - spec/brocket_spec.rb
98
+ - spec/spec_helper.rb
99
+ homepage: ''
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.2.2
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: supports to build Docker Container with VERSION
123
+ test_files:
124
+ - spec/brocket/Dockerfiles/Dockerfile-basic
125
+ - spec/brocket/Dockerfiles/Dockerfile-hook
126
+ - spec/brocket/docker_spec.rb
127
+ - spec/brocket/version_file_spec.rb
128
+ - spec/brocket_spec.rb
129
+ - spec/spec_helper.rb
130
+ has_rdoc: