brocket 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,148 @@
1
+ require 'spec_helper'
2
+
3
+ describe :multi_app_proj do
4
+ context "app1 with absolute path" do
5
+ let(:dockerfile){ File.expand_path("../multi_app_proj/app1/docker/Dockerfile", __FILE__) }
6
+
7
+ describe BRocket::VersionFile do
8
+ let(:version_obj) do
9
+ obj = BRocket::VersionFile.new
10
+ obj.options = {dockerfile: dockerfile}
11
+ obj
12
+ end
13
+ it{ expect(version_obj.current).to eq "1.2.1" }
14
+ end
15
+
16
+ describe BRocket::Git do
17
+ let(:git_obj) do
18
+ obj = BRocket::Git.new
19
+ obj.options = {dockerfile: dockerfile}
20
+ obj
21
+ end
22
+ it{ expect(git_obj.version_tag).to eq "1.2.1" }
23
+ end
24
+ end
25
+
26
+ context "app2 with absolute path" do
27
+ let(:dockerfile){ File.expand_path("../multi_app_proj/app2/Dockerfile", __FILE__) }
28
+
29
+ describe BRocket::VersionFile do
30
+ let(:version_obj) do
31
+ obj = BRocket::VersionFile.new
32
+ obj.options = {dockerfile: dockerfile}
33
+ obj
34
+ end
35
+ it{ expect(version_obj.current).to eq "0.1.0" }
36
+ end
37
+
38
+ describe BRocket::Git do
39
+ let(:git_obj) do
40
+ obj = BRocket::Git.new
41
+ obj.options = {dockerfile: dockerfile}
42
+ obj
43
+ end
44
+ it{ expect(git_obj.version_tag).to eq "app2/0.1.0" }
45
+ end
46
+ end
47
+
48
+ context "app1 with relative path" do
49
+ let(:base_dir){ File.expand_path("../multi_app_proj/app1", __FILE__) }
50
+ let(:docker_relpath){ "docker/Dockerfile" }
51
+
52
+ around do |example|
53
+ Dir.chdir(base_dir) do
54
+ example.run
55
+ end
56
+ end
57
+ before{ allow(BRocket).to receive(:user_pwd).and_return(base_dir) }
58
+
59
+ describe BRocket::VersionFile do
60
+ let(:version_obj) do
61
+ obj = BRocket::VersionFile.new
62
+ obj.options = {dockerfile: docker_relpath}
63
+ obj
64
+ end
65
+ it{ expect(version_obj.current).to eq "1.2.1" }
66
+ end
67
+
68
+ describe BRocket::Git do
69
+ let(:git_obj) do
70
+ obj = BRocket::Git.new
71
+ obj.options = {dockerfile: docker_relpath}
72
+ obj
73
+ end
74
+ it{ expect(git_obj.version_tag).to eq "1.2.1" }
75
+ end
76
+
77
+ describe BRocket::Docker do
78
+ let(:docker_obj) do
79
+ obj = BRocket::Docker.new
80
+ obj.options = {dockerfile: docker_relpath}
81
+ obj
82
+ end
83
+ it{ expect(docker_obj.working_dir).to eq base_dir }
84
+ it{ expect(docker_obj.config_filepath).to eq File.expand_path(docker_relpath, base_dir) }
85
+ it{ expect(docker_obj.config_relpath ).to eq docker_relpath }
86
+ it do
87
+ expect(docker_obj).to receive(:sh).with("docker build -t old_app1:1.2.1 -f docker/Dockerfile .")
88
+ docker_obj.build
89
+ end
90
+ end
91
+ end
92
+
93
+ context "app2 with relative path" do
94
+ let(:base_dir){ File.expand_path("../multi_app_proj/app2", __FILE__) }
95
+ # let(:docker_relpath){ "Dockerfile" }
96
+
97
+ around do |example|
98
+ Dir.chdir(base_dir) do
99
+ example.run
100
+ end
101
+ end
102
+
103
+ before{ allow(BRocket).to receive(:user_pwd).and_return(base_dir) }
104
+
105
+ describe BRocket::VersionFile do
106
+ let(:version_obj) do
107
+ obj = BRocket::VersionFile.new
108
+ # obj.options = {dockerfile: docker_relpath}
109
+ obj
110
+ end
111
+ it{ expect(version_obj.current).to eq "0.1.0" }
112
+ it do
113
+ Dir.chdir(version_obj.working_dir) do
114
+ expect(version_obj.current).to eq "0.1.0"
115
+ end
116
+ end
117
+ end
118
+
119
+ describe BRocket::Git do
120
+ let(:git_obj) do
121
+ obj = BRocket::Git.new
122
+ # obj.options = {dockerfile: docker_relpath}
123
+ obj
124
+ end
125
+ it{ expect(git_obj.version_tag).to eq "app2/0.1.0" }
126
+ it do
127
+ Dir.chdir(git_obj.working_dir) do
128
+ expect(git_obj.version_tag).to eq "app2/0.1.0"
129
+ end
130
+ end
131
+ end
132
+
133
+ describe BRocket::Docker do
134
+ let(:docker_obj) do
135
+ obj = BRocket::Docker.new
136
+ # obj.options = {dockerfile: docker_relpath}
137
+ obj
138
+ end
139
+ it{ expect(docker_obj.working_dir).to eq File.expand_path("..", base_dir) }
140
+ it{ expect(docker_obj.config_filepath).to eq File.expand_path("Dockerfile", base_dir) }
141
+ it{ expect(docker_obj.config_relpath ).to eq "app2/Dockerfile" }
142
+ it do
143
+ expect(docker_obj).to receive(:sh).with("docker build -t new_app2:0.1.0 -f app2/Dockerfile .")
144
+ docker_obj.build
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,18 @@
1
+ #
2
+ # [config] IMAGE_NAME: "test_gem"
3
+ # [config]
4
+ # [config] VERSION_SCRIPT: "ruby -r ./lib/test_gem/version.rb -e 'puts TestGem::VERSION'"
5
+ # [config] GIT_TAG_PREFIX: "test_gem/"
6
+ #
7
+
8
+ FROM ruby:2.3.0
9
+ MAINTAINER tech@groovenauts.jp
10
+
11
+ COPY ./test_gem $TEST_GEM_HOME
12
+
13
+ WORKDIR $TEST_GEM_HOME
14
+
15
+ RUN bundle install --without test development \
16
+ && echo "export PATH=\$TEST_GEM_HOME/docker:\$PATH" >> $HOME/.bashrc
17
+
18
+ CMD [ "/bin/bash" ]
@@ -0,0 +1,7 @@
1
+
2
+ ## Directories
3
+
4
+ - Dockerfile
5
+ - lib/
6
+ - test_gem/
7
+ - version.rb
@@ -0,0 +1,3 @@
1
+ module TestGem
2
+ VERSION = '0.2.1'
3
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe :test_gem do
4
+ let(:dockerfile){ File.expand_path("../test_gem/Dockerfile", __FILE__) }
5
+
6
+ describe BRocket::VersionFile do
7
+ let(:version_obj) do
8
+ obj = BRocket::VersionFile.new
9
+ obj.options = {dockerfile: dockerfile}
10
+ obj
11
+ end
12
+ it{ expect(version_obj.current).to eq "0.2.1" }
13
+ end
14
+
15
+ describe BRocket::Git do
16
+ let(:git_obj) do
17
+ obj = BRocket::Git.new
18
+ obj.options = {dockerfile: dockerfile}
19
+ obj
20
+ end
21
+ it{ expect(git_obj.version_tag).to eq "test_gem/0.2.1" }
22
+ end
23
+ end
@@ -1,8 +1,12 @@
1
+ # coding: utf-8
1
2
  require 'spec_helper'
2
3
 
3
4
  describe BRocket::VersionFile do
4
5
 
5
6
  let(:subject){ BRocket::VersionFile.new }
7
+ let(:dockerfile){ File.expand_path("../Dockerfiles/Dockerfile-basic", __FILE__) }
8
+ let(:version_file){ File.expand_path("../Dockerfiles/VERSION", __FILE__) }
9
+ before{ subject.options = { dockerfile: dockerfile } }
6
10
 
7
11
  describe :init do
8
12
  it :without_arg do
@@ -16,6 +20,29 @@ describe BRocket::VersionFile do
16
20
  end
17
21
  end
18
22
 
23
+ describe :show do
24
+ it do
25
+ expect($stdout).to receive(:puts).with(File.read(version_file).strip)
26
+ subject.show
27
+ end
28
+
29
+ context :invalid do
30
+ let(:dockerfile){ File.expand_path("../Dockerfiles/Dockerfile-invalid-version", __FILE__) }
31
+ it do
32
+ expect{ subject.show }.to raise_error(BRocket::BuildError, /file not found/i)
33
+ end
34
+ end
35
+ end
36
+
37
+ describe :write_file do
38
+ it do
39
+ ver = "1.2.3"
40
+ f = double(:mock_file)
41
+ expect(File).to receive(:open).with(version_file, "w").and_yield(f)
42
+ expect(f).to receive(:puts).with(ver)
43
+ subject.send(:write_file, ver)
44
+ end
45
+ end
19
46
 
20
47
  {
21
48
  major: {
@@ -33,19 +60,21 @@ describe BRocket::VersionFile do
33
60
  }.each do |method_name, patterns|
34
61
 
35
62
  describe method_name do
63
+ let(:git){ subject.sub(BRocket::Git) }
64
+ before do
65
+ allow(BRocket::Git).to receive(:new).and_return(git)
66
+ allow(git).to receive(:guard_clean)
67
+ expect(git).to receive(:sh).with(/git add #{version_file} && git commit -m \".+\"/)
68
+ end
36
69
  it :without_arg do
37
- allow_any_instance_of(BRocket::Git).to receive(:guard_clean)
38
70
  allow(subject).to receive(:read_file).and_return("1.2.3")
39
71
  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
72
  subject.send(method_name)
42
73
  end
43
74
 
44
75
  it :with_arg do
45
- allow_any_instance_of(BRocket::Git).to receive(:guard_clean)
46
76
  allow(subject).to receive(:read_file).and_return("1.2.3")
47
77
  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
78
  subject.send(method_name, "5")
50
79
  end
51
80
  end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,20 @@
1
+ if ENV["COVERAGE"] =~ /true|yes|on|1/i
2
+ require 'simplecov'
3
+ require 'simplecov-rcov'
4
+ SimpleCov.formatters = [
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ SimpleCov::Formatter::RcovFormatter
7
+ ]
8
+ SimpleCov.start do
9
+ add_filter "spec/"
10
+ end
11
+ end
12
+
1
13
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
14
  require 'brocket'
15
+
16
+ logpath = File.expand_path("../../tmp/test.log", __FILE__)
17
+ require 'fileutils'
18
+ FileUtils.mkdir_p(File.dirname(logpath))
19
+ BRocket.logger = Logger.new(logpath)
20
+
metadata CHANGED
@@ -1,80 +1,80 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brocket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - akima
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-07 00:00:00.000000000 Z
11
+ date: 2016-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: thor
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
18
  version: '0'
20
- type: :runtime
19
+ name: thor
21
20
  prerelease: false
21
+ type: :runtime
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: logger_pipe
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - ">="
32
31
  - !ruby/object:Gem::Version
33
32
  version: '0'
34
- type: :runtime
33
+ name: logger_pipe
35
34
  prerelease: false
35
+ type: :runtime
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: bundler
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - "~>"
46
45
  - !ruby/object:Gem::Version
47
46
  version: '1.6'
48
- type: :development
47
+ name: bundler
49
48
  prerelease: false
49
+ type: :development
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.6'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - "~>"
60
59
  - !ruby/object:Gem::Version
61
60
  version: '10.0'
62
- type: :development
61
+ name: rake
63
62
  prerelease: false
63
+ type: :development
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rspec
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
72
  - - ">="
74
73
  - !ruby/object:Gem::Version
75
74
  version: '0'
76
- type: :development
75
+ name: rspec
77
76
  prerelease: false
77
+ type: :development
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
@@ -100,15 +100,31 @@ files:
100
100
  - lib/brocket.rb
101
101
  - lib/brocket/base.rb
102
102
  - lib/brocket/cli.rb
103
+ - lib/brocket/configurable.rb
103
104
  - lib/brocket/docker.rb
104
105
  - lib/brocket/git.rb
105
106
  - lib/brocket/version.rb
106
107
  - lib/brocket/version_file.rb
107
108
  - spec/brocket/Dockerfiles/Dockerfile-basic
109
+ - spec/brocket/Dockerfiles/Dockerfile-gcr
108
110
  - spec/brocket/Dockerfiles/Dockerfile-git-tag
109
111
  - spec/brocket/Dockerfiles/Dockerfile-hook
112
+ - spec/brocket/Dockerfiles/Dockerfile-invalid-version
113
+ - spec/brocket/Dockerfiles/Dockerfile-working_dir
114
+ - spec/brocket/Dockerfiles/VERSION
115
+ - spec/brocket/base_spec.rb
110
116
  - spec/brocket/docker_spec.rb
111
117
  - spec/brocket/git_spec.rb
118
+ - spec/brocket/multi_app_proj/README.md
119
+ - spec/brocket/multi_app_proj/app1/docker/Dockerfile
120
+ - spec/brocket/multi_app_proj/app1/docker/VERSION.txt
121
+ - spec/brocket/multi_app_proj/app2/Dockerfile
122
+ - spec/brocket/multi_app_proj/app2/VERSION
123
+ - spec/brocket/multi_app_proj_spec.rb
124
+ - spec/brocket/test_gem/Dockerfile
125
+ - spec/brocket/test_gem/README.md
126
+ - spec/brocket/test_gem/lib/test_gem/version.rb
127
+ - spec/brocket/test_gem_spec.rb
112
128
  - spec/brocket/version_file_spec.rb
113
129
  - spec/brocket_spec.rb
114
130
  - spec/spec_helper.rb
@@ -116,7 +132,7 @@ homepage: ''
116
132
  licenses:
117
133
  - MIT
118
134
  metadata: {}
119
- post_install_message:
135
+ post_install_message:
120
136
  rdoc_options: []
121
137
  require_paths:
122
138
  - lib
@@ -131,17 +147,33 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
147
  - !ruby/object:Gem::Version
132
148
  version: '0'
133
149
  requirements: []
134
- rubyforge_project:
135
- rubygems_version: 2.4.5
136
- signing_key:
150
+ rubyforge_project:
151
+ rubygems_version: 2.4.8
152
+ signing_key:
137
153
  specification_version: 4
138
154
  summary: supports to build Docker Container with VERSION
139
155
  test_files:
140
156
  - spec/brocket/Dockerfiles/Dockerfile-basic
157
+ - spec/brocket/Dockerfiles/Dockerfile-gcr
141
158
  - spec/brocket/Dockerfiles/Dockerfile-git-tag
142
159
  - spec/brocket/Dockerfiles/Dockerfile-hook
160
+ - spec/brocket/Dockerfiles/Dockerfile-invalid-version
161
+ - spec/brocket/Dockerfiles/Dockerfile-working_dir
162
+ - spec/brocket/Dockerfiles/VERSION
163
+ - spec/brocket/base_spec.rb
143
164
  - spec/brocket/docker_spec.rb
144
165
  - spec/brocket/git_spec.rb
166
+ - spec/brocket/multi_app_proj/README.md
167
+ - spec/brocket/multi_app_proj/app1/docker/Dockerfile
168
+ - spec/brocket/multi_app_proj/app1/docker/VERSION.txt
169
+ - spec/brocket/multi_app_proj/app2/Dockerfile
170
+ - spec/brocket/multi_app_proj/app2/VERSION
171
+ - spec/brocket/multi_app_proj_spec.rb
172
+ - spec/brocket/test_gem/Dockerfile
173
+ - spec/brocket/test_gem/README.md
174
+ - spec/brocket/test_gem/lib/test_gem/version.rb
175
+ - spec/brocket/test_gem_spec.rb
145
176
  - spec/brocket/version_file_spec.rb
146
177
  - spec/brocket_spec.rb
147
178
  - spec/spec_helper.rb
179
+ has_rdoc: