brocket 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30dc6163a3b7acbe9cba9792ec3a8245ee1dd674
4
- data.tar.gz: c3830af93db70d56bf2b553e2ea1ee63e694ff9d
3
+ metadata.gz: 22fcf9e97f299b10983753dd1f74abb4ff31e78e
4
+ data.tar.gz: 25a8ecaa347cd4db902508ac1112b6e98bb7e9dc
5
5
  SHA512:
6
- metadata.gz: aa61def37a83d76a6315b5429f97ca0d48a5048b8af736fc898cbae783d559644a595bf0f86128958b23f0424e2b54434c4ddf402d1316ad69aa4e76ad969587
7
- data.tar.gz: 07afa57f839d2c32a4e8a8ea052f2d008aaa0180824ef21f1da84befe20c3b890fb166374649517a8bf4e1147a00ff41d9b7b741818b47aa44590179c4afa09c
6
+ metadata.gz: 20a13369ec5c253483e84cdafe5a42f194727db5fa98e37498404dfb8a9b430d409e5d43861aa2e89878c901b35ae5944287e57fc86fb7eee6a90131dc6f3d59
7
+ data.tar.gz: efb682c5a4332b1685af273e00a17e182a02f0ebc9911ce3a38096fc10fd79f65062a51ed51718879e00782e927f5f4b0f72c2d9c79aa3bc10129be6b715f812
data/lib/brocket/base.rb CHANGED
@@ -4,8 +4,8 @@ require 'thor'
4
4
 
5
5
  module BRocket
6
6
  class Base < Thor
7
- class_option :verbose, :type => :boolean
8
- class_option :dryrun , :type => :boolean
7
+ class_option :verbose, type: :boolean, aliases: "-V"
8
+ class_option :dryrun , type: :boolean, aliases: "-D"
9
9
 
10
10
  no_commands do
11
11
 
@@ -15,19 +15,16 @@ module BRocket
15
15
  task
16
16
  end
17
17
 
18
- def dryrun?
19
- (options || {})[:dryrun]
18
+ def opts
19
+ @opts ||= options || {}
20
20
  end
21
21
 
22
- def verbose?
23
- (options || {})[:verbose]
22
+ def dryrun?
23
+ opts[:dryrun]
24
24
  end
25
25
 
26
- def chdir(dir, &block)
27
- dir ||= "."
28
- verbose("cd #{dir}")
29
- Dir.chdir(dir, &block)
30
- verbose("cd #{Dir.pwd}")
26
+ def verbose?
27
+ opts[:verbose]
31
28
  end
32
29
 
33
30
  def verbose(msg)
data/lib/brocket/cli.rb CHANGED
@@ -18,12 +18,12 @@ module BRocket
18
18
  sub(Docker).build
19
19
  end
20
20
 
21
- desc "release [DIRECTORY]", "build docker image, tag it, push tag and push docker image to docker hub"
22
- def release(dir = nil)
21
+ desc "release", "build docker image, tag it, push tag and push docker image to docker hub"
22
+ def release
23
23
  sub(Git).guard_clean
24
- sub(Docker).build(dir)
24
+ sub(Docker).build
25
25
  sub(Git).push
26
- sub(Docker).push(dir)
26
+ sub(Docker).push
27
27
  end
28
28
 
29
29
  desc "version SUBCOMMAND ...ARGS", "manage VERSION file"
@@ -8,37 +8,37 @@ module BRocket
8
8
  CONFIG_LINE_SEP = "[config]".freeze
9
9
  CONFIG_LINE_HEADER = /\A\#\s*#{Regexp.escape(CONFIG_LINE_SEP)}\s?/.freeze
10
10
 
11
- desc "config [DIRECTORY]", "show configurations in Dockerfile"
12
- def config(dir = nil)
13
- $stdout.puts(YAML.dump(config_hash(dir)))
11
+ desc "config", "show configurations in Dockerfile"
12
+ def config
13
+ $stdout.puts(YAML.dump(config_hash))
14
14
  end
15
15
 
16
- desc "build [DIRECTORY]", "build docker image at DIRECTORY or PWD"
17
- def build(dir = nil)
16
+ desc "build", "build docker image"
17
+ def build
18
18
  info("[docker build] starting")
19
- dir ||= "."
20
- c = config_hash(dir)
19
+ c = config_hash
21
20
  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
21
+ begin
22
+ execute(c['BEFORE_BUILD'])
23
+ version = sub(VersionFile).current
24
+ execute("docker build -t #{img_name}:#{version} .")
25
+ execute(c['ON_BUILD_COMPLETE'])
26
+ rescue
27
+ execute(c['ON_BUILD_ERROR'])
28
+ raise
29
+ ensure
30
+ execute(c['AFTER_BUILD'])
32
31
  end
33
32
  success("[docker build] OK")
34
33
  end
35
34
 
36
- desc "push [DIRECTORY]", "push docker image to docker hub"
37
- def push(dir = nil)
35
+ desc "push", "push docker image to docker hub"
36
+ def push
38
37
  info("[docker push] starting")
39
- c = config_hash(dir || ".")
38
+ c = config_hash
40
39
  img_name = config_image_name(c)
41
- cmd = "docker push #{img_name}:#{VersionFile.current}"
40
+ version = sub(VersionFile).current
41
+ cmd = "docker push #{img_name}:#{version}"
42
42
  sh(cmd)
43
43
  success("[docker push] OK")
44
44
  end
@@ -46,21 +46,18 @@ module BRocket
46
46
  no_commands do
47
47
  def config_image_name(c)
48
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?
49
+ error "No IMAGE_NAME found in Dockerfile. Please add `# #{CONFIG_LINE_SEP} IMAGE_NAME: [IMAGE NAME on DockerHub]` in Dockerfile" if img_name.empty?
50
50
  img_name
51
51
  end
52
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
53
+ def config_hash
54
+ content = read_config_file
55
+ lines = content.lines.select{|line| line =~ CONFIG_LINE_HEADER}.
56
+ map{|line| line.sub(CONFIG_LINE_HEADER, "")}
57
+ return (YAML.load(lines.join("\n")) || {})
61
58
  end
62
59
 
63
- def read_file
60
+ def read_config_file
64
61
  File.read("Dockerfile")
65
62
  end
66
63
 
data/lib/brocket/git.rb CHANGED
@@ -60,7 +60,9 @@ module BRocket
60
60
  end
61
61
 
62
62
  def version_tag
63
- VersionFile.current
63
+ prefix = sub(Docker).config_hash["GIT_TAG_PREFIX"] || ""
64
+ version = sub(VersionFile).current
65
+ "%s%s" % [prefix, version]
64
66
  end
65
67
 
66
68
  end
@@ -1,3 +1,3 @@
1
1
  module BRocket
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -5,7 +5,7 @@ module BRocket
5
5
  FILENAME = "VERSION".freeze
6
6
  INITIAL_VERSION = "0.0.1".freeze
7
7
 
8
- desc "init [VERSION]", "initialize VERSION file in current directory"
8
+ desc "init [VERSION]", "initialize VERSION file in directory for docker"
9
9
  def init(version = nil)
10
10
  write_file(version || INITIAL_VERSION)
11
11
  end
@@ -30,24 +30,22 @@ module BRocket
30
30
  bump_on(:patch, num)
31
31
  end
32
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
33
+ no_commands do
34
+ def filepath
35
+ FILENAME
40
36
  end
41
- end
42
37
 
43
- no_commands do
44
38
  def read_file
45
- self.class.current
39
+ if File.readable?(filepath)
40
+ File.read(filepath).strip
41
+ else
42
+ raise BuildError, "File not found #{filepath}. You can run `#{$0} init`"
43
+ end
46
44
  end
47
- private :read_file
45
+ alias_method :current, :read_file
48
46
 
49
47
  def write_file(version)
50
- File.open(FILENAME, "w"){|f| f.puts(version) }
48
+ File.open(filepath, "w"){|f| f.puts(version) }
51
49
  end
52
50
  private :write_file
53
51
 
@@ -64,7 +62,7 @@ module BRocket
64
62
  ver = parts.join(".")
65
63
  ver << "-" << suffix if suffix
66
64
  write_file(ver)
67
- sub(Git).commit(FILENAME, "bump up #{pos.to_s} version: #{ver}")
65
+ sub(Git).commit(filepath, "bump up #{pos.to_s} version: #{ver}")
68
66
  success("[git #{pos.to_s}] #{ver}")
69
67
  ver
70
68
  end
@@ -0,0 +1,20 @@
1
+ #
2
+ # [config] IMAGE_NAME: "groovenauts/rails-example"
3
+ # [config] GIT_TAG_PREFIX: containers/rails_example/
4
+ #
5
+
6
+ FROM groovenauts/ruby:2.1.2
7
+ MAINTAINER tech@groovenauts.jp
8
+
9
+ ENV RAILS_ENV production
10
+
11
+ # for debug via HTTP dicrectly
12
+ EXPOSE 3000
13
+
14
+ ADD . /usr/src/app
15
+ WORKDIR /usr/src/app
16
+ VOLUME /usr/src/app/log
17
+
18
+ RUN bundle install --system
19
+
20
+ CMD ["bundle", "exec", "rails", "s", "-e", "production"]
@@ -10,8 +10,8 @@ describe BRocket::Docker do
10
10
  let(:version){ "2.3.4" }
11
11
 
12
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)
13
+ allow(subject).to receive(:read_config_file).with(any_args).and_return(File.read(filepath))
14
+ allow_any_instance_of(BRocket::VersionFile).to receive(:current).and_return(version)
15
15
  end
16
16
 
17
17
  describe :config do
@@ -33,8 +33,8 @@ describe BRocket::Docker do
33
33
  let(:version){ "2.3.4" }
34
34
 
35
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)
36
+ allow(subject).to receive(:read_config_file).with(any_args).and_return(File.read(filepath))
37
+ allow_any_instance_of(BRocket::VersionFile).to receive(:current).and_return(version)
38
38
  end
39
39
 
40
40
  describe :config do
@@ -62,13 +62,16 @@ describe BRocket::Docker do
62
62
  end
63
63
 
64
64
  it :error do
65
+ error_msg = "build error"
65
66
  expect(subject).to receive(:sh).with("abc")
66
67
  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("docker build -t #{image_name}:#{version} .").and_raise(error_msg)
68
69
  expect(subject).to receive(:sh).with("baz") # not "foo bar"
69
70
  expect(subject).to receive(:sh).with("jkl")
70
71
  expect(subject).to receive(:sh).with("mno")
71
- subject.build
72
+ expect{
73
+ subject.build
74
+ }.to raise_error(error_msg)
72
75
  end
73
76
  end
74
77
  end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe BRocket::Git do
4
+
5
+ let(:subject){ BRocket::Git.new }
6
+
7
+ describe "Dockerfile-basic" do
8
+ let(:filepath){ File.expand_path("../Dockerfiles/Dockerfile-git-tag", __FILE__) }
9
+ let(:image_name){ "groovenauts/rails-example" }
10
+ let(:tag_prefix){ "containers/rails_example/" }
11
+ let(:version){ "2.3.4" }
12
+
13
+ before do
14
+ allow_any_instance_of(BRocket::Docker).to receive(:read_config_file).with(any_args).and_return(File.read(filepath))
15
+ allow_any_instance_of(BRocket::VersionFile).to receive(:current).and_return(version)
16
+ end
17
+
18
+ describe :config do
19
+ it do
20
+ expect(subject.version_tag).to eq("containers/rails_example/2.3.4")
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brocket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - akima
@@ -91,8 +91,10 @@ files:
91
91
  - lib/brocket/version.rb
92
92
  - lib/brocket/version_file.rb
93
93
  - spec/brocket/Dockerfiles/Dockerfile-basic
94
+ - spec/brocket/Dockerfiles/Dockerfile-git-tag
94
95
  - spec/brocket/Dockerfiles/Dockerfile-hook
95
96
  - spec/brocket/docker_spec.rb
97
+ - spec/brocket/git_spec.rb
96
98
  - spec/brocket/version_file_spec.rb
97
99
  - spec/brocket_spec.rb
98
100
  - spec/spec_helper.rb
@@ -122,8 +124,10 @@ specification_version: 4
122
124
  summary: supports to build Docker Container with VERSION
123
125
  test_files:
124
126
  - spec/brocket/Dockerfiles/Dockerfile-basic
127
+ - spec/brocket/Dockerfiles/Dockerfile-git-tag
125
128
  - spec/brocket/Dockerfiles/Dockerfile-hook
126
129
  - spec/brocket/docker_spec.rb
130
+ - spec/brocket/git_spec.rb
127
131
  - spec/brocket/version_file_spec.rb
128
132
  - spec/brocket_spec.rb
129
133
  - spec/spec_helper.rb