brocket 0.1.0 → 0.2.0
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 +4 -4
- data/.rspec +1 -1
- data/Gemfile +8 -0
- data/README.md +42 -8
- data/lib/brocket.rb +19 -0
- data/lib/brocket/base.rb +5 -11
- data/lib/brocket/cli.rb +1 -1
- data/lib/brocket/configurable.rb +55 -0
- data/lib/brocket/docker.rb +45 -33
- data/lib/brocket/git.rb +20 -12
- data/lib/brocket/version.rb +1 -1
- data/lib/brocket/version_file.rb +14 -6
- data/spec/brocket/Dockerfiles/Dockerfile-gcr +22 -0
- data/spec/brocket/Dockerfiles/Dockerfile-hook +3 -0
- data/spec/brocket/Dockerfiles/Dockerfile-invalid-version +19 -0
- data/spec/brocket/Dockerfiles/Dockerfile-working_dir +21 -0
- data/spec/brocket/Dockerfiles/VERSION +1 -0
- data/spec/brocket/base_spec.rb +39 -0
- data/spec/brocket/docker_spec.rb +99 -7
- data/spec/brocket/git_spec.rb +94 -2
- data/spec/brocket/multi_app_proj/README.md +13 -0
- data/spec/brocket/multi_app_proj/app1/docker/Dockerfile +22 -0
- data/spec/brocket/multi_app_proj/app1/docker/VERSION.txt +1 -0
- data/spec/brocket/multi_app_proj/app2/Dockerfile +23 -0
- data/spec/brocket/multi_app_proj/app2/VERSION +1 -0
- data/spec/brocket/multi_app_proj_spec.rb +148 -0
- data/spec/brocket/test_gem/Dockerfile +18 -0
- data/spec/brocket/test_gem/README.md +7 -0
- data/spec/brocket/test_gem/lib/test_gem/version.rb +3 -0
- data/spec/brocket/test_gem_spec.rb +23 -0
- data/spec/brocket/version_file_spec.rb +33 -4
- data/spec/spec_helper.rb +18 -0
- metadata +49 -17
@@ -0,0 +1,22 @@
|
|
1
|
+
#
|
2
|
+
# [config] IMAGE_NAME: "rails-example"
|
3
|
+
# [config] DOCKER_PUSH_COMMAND: "gcloud docker push"
|
4
|
+
# [config] DOCKER_PUSH_REGISTRY: "asia.gcr.io"
|
5
|
+
# [config] DOCKER_PUSH_USERNAME: "groovenauts"
|
6
|
+
#
|
7
|
+
|
8
|
+
FROM groovenauts/ruby:2.1.2
|
9
|
+
MAINTAINER tech@groovenauts.jp
|
10
|
+
|
11
|
+
ENV RAILS_ENV production
|
12
|
+
|
13
|
+
# for debug via HTTP dicrectly
|
14
|
+
EXPOSE 3000
|
15
|
+
|
16
|
+
ADD . /usr/src/app
|
17
|
+
WORKDIR /usr/src/app
|
18
|
+
VOLUME /usr/src/app/log
|
19
|
+
|
20
|
+
RUN bundle install --system
|
21
|
+
|
22
|
+
CMD ["bundle", "exec", "rails", "s", "-e", "production"]
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#
|
2
|
+
# [config] IMAGE_NAME: "groovenauts/rails-example"
|
3
|
+
# [config] VERSION_FILE: "not-existing"
|
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,21 @@
|
|
1
|
+
#
|
2
|
+
# [config] IMAGE_NAME: "groovenauts/rails-example"
|
3
|
+
# [config]
|
4
|
+
# [config] WORKING_DIR: ".."
|
5
|
+
#
|
6
|
+
|
7
|
+
FROM groovenauts/ruby:2.1.2
|
8
|
+
MAINTAINER tech@groovenauts.jp
|
9
|
+
|
10
|
+
ENV RAILS_ENV production
|
11
|
+
|
12
|
+
# for debug via HTTP dicrectly
|
13
|
+
EXPOSE 3000
|
14
|
+
|
15
|
+
ADD . /usr/src/app
|
16
|
+
WORKDIR /usr/src/app
|
17
|
+
VOLUME /usr/src/app/log
|
18
|
+
|
19
|
+
RUN bundle install --system
|
20
|
+
|
21
|
+
CMD ["bundle", "exec", "rails", "s", "-e", "production"]
|
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BRocket::Base do
|
4
|
+
|
5
|
+
let(:subject){ BRocket::Base.new }
|
6
|
+
|
7
|
+
describe :sh do
|
8
|
+
let(:cmd){ 'echo "FOO"' }
|
9
|
+
it "without dryrun" do
|
10
|
+
expect(LoggerPipe).to receive(:run).with(BRocket.logger, cmd, dry_run: nil)
|
11
|
+
end
|
12
|
+
it "with dryrun" do
|
13
|
+
subject.options = {dryrun: true}
|
14
|
+
expect(LoggerPipe).to receive(:run).with(BRocket.logger, cmd, dry_run: true)
|
15
|
+
end
|
16
|
+
|
17
|
+
after do
|
18
|
+
subject.sh(cmd)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe :verbose do
|
23
|
+
let(:msg){ "FOOO" }
|
24
|
+
it "without verbose" do
|
25
|
+
expect(BRocket.logger).not_to receive(:debug).with(msg)
|
26
|
+
subject.verbose(msg)
|
27
|
+
end
|
28
|
+
it "without verbose" do
|
29
|
+
subject.options = {verbose: true}
|
30
|
+
called = false
|
31
|
+
expect(BRocket.logger).to receive(:debug) do |actual_msg|
|
32
|
+
expect(actual_msg.strip).to match /#{msg}/
|
33
|
+
called = true
|
34
|
+
end
|
35
|
+
subject.verbose(msg)
|
36
|
+
expect(called).to be_truthy
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/brocket/docker_spec.rb
CHANGED
@@ -4,18 +4,30 @@ describe BRocket::Docker do
|
|
4
4
|
|
5
5
|
let(:subject){ BRocket::Docker.new }
|
6
6
|
|
7
|
+
let(:image_name){ "groovenauts/rails-example" }
|
8
|
+
let(:version){ "2.3.4" }
|
9
|
+
|
10
|
+
let(:expected_options){ {"dockerfile"=>"Dockerfile"} }
|
11
|
+
before do
|
12
|
+
version_file = double(:version_file, current: version)
|
13
|
+
allow(version_file).to receive(:options=).with(expected_options)
|
14
|
+
allow(BRocket::VersionFile).to receive(:new).and_return(version_file)
|
15
|
+
end
|
16
|
+
|
7
17
|
describe "Dockerfile-basic" do
|
8
18
|
let(:filepath){ File.expand_path("../Dockerfiles/Dockerfile-basic", __FILE__) }
|
9
|
-
|
10
|
-
let(:version){ "2.3.4" }
|
19
|
+
before{ allow(BRocket).to receive(:user_pwd).and_return(File.dirname(filepath)) }
|
11
20
|
|
12
21
|
before do
|
13
22
|
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
23
|
end
|
16
24
|
|
17
25
|
describe :config do
|
18
26
|
it{ expect(subject.config_hash).to eq({"IMAGE_NAME" => image_name}) }
|
27
|
+
it do
|
28
|
+
expect($stdout).to receive(:puts).with(YAML.dump(subject.config_hash))
|
29
|
+
subject.config
|
30
|
+
end
|
19
31
|
end
|
20
32
|
|
21
33
|
describe :build do
|
@@ -24,22 +36,85 @@ describe BRocket::Docker do
|
|
24
36
|
subject.build
|
25
37
|
end
|
26
38
|
end
|
39
|
+
|
40
|
+
describe :push do
|
41
|
+
it do
|
42
|
+
expect(subject).to receive(:sh).with("docker push #{image_name}:#{version}")
|
43
|
+
subject.push
|
44
|
+
end
|
45
|
+
end
|
27
46
|
end
|
28
47
|
|
48
|
+
describe "Dockerfile-gcr" do
|
49
|
+
let(:original_image_name){ "rails-example" }
|
50
|
+
let(:gcr_image_name){ "asia.gcr.io/groovenauts/rails-example" }
|
51
|
+
let(:filepath){ File.expand_path("../Dockerfiles/Dockerfile-gcr", __FILE__) }
|
52
|
+
before{ allow(BRocket).to receive(:user_pwd).and_return(File.dirname(filepath)) }
|
29
53
|
|
30
|
-
|
54
|
+
before do
|
55
|
+
allow(subject).to receive(:read_config_file).with(any_args).and_return(File.read(filepath))
|
56
|
+
end
|
57
|
+
|
58
|
+
describe :push do
|
59
|
+
it do
|
60
|
+
expected_cmd = [
|
61
|
+
"docker tag -f #{original_image_name}:#{version} #{gcr_image_name}:#{version}",
|
62
|
+
"gcloud docker push #{gcr_image_name}:#{version}"
|
63
|
+
].join(' && ')
|
64
|
+
expect(subject).to receive(:sh).with(expected_cmd)
|
65
|
+
subject.push
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "Dockerfile-working_dir" do
|
71
|
+
let(:filepath){ File.expand_path("../Dockerfiles/Dockerfile-working_dir", __FILE__) }
|
72
|
+
let(:expected_options){ {dockerfile: filepath} }
|
73
|
+
before{ allow(BRocket).to receive(:user_pwd).and_return(File.dirname(filepath)) }
|
74
|
+
|
75
|
+
before do
|
76
|
+
allow(subject).to receive(:read_config_file).with(any_args).and_return(File.read(filepath))
|
77
|
+
end
|
78
|
+
|
79
|
+
describe :config do
|
80
|
+
it{ expect(subject.config_hash).to eq({"IMAGE_NAME" => image_name, "WORKING_DIR" => ".."}) }
|
81
|
+
end
|
82
|
+
|
83
|
+
describe :build do
|
84
|
+
it do
|
85
|
+
dir = File.expand_path("../..", filepath)
|
86
|
+
expect(Dir).to receive(:chdir).with(dir).and_yield
|
87
|
+
expect(subject).to receive(:sh).with("docker build -t #{image_name}:#{version} -f Dockerfiles/Dockerfile-working_dir .")
|
88
|
+
subject.options = {dockerfile: filepath}
|
89
|
+
subject.build
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
describe "Dockerfile not found" do
|
96
|
+
let(:filepath){ File.expand_path("../Dockerfiles/Dockerfile-noexist", __FILE__) }
|
97
|
+
before{ allow(BRocket).to receive(:user_pwd).and_return(File.dirname(filepath)) }
|
98
|
+
|
99
|
+
describe :config do
|
100
|
+
it do
|
101
|
+
expect{ subject.config }.to raise_error(/file not found/i)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "Dockerfile-hook" do
|
31
107
|
let(:filepath){ File.expand_path("../Dockerfiles/Dockerfile-hook", __FILE__) }
|
32
|
-
|
33
|
-
let(:version){ "2.3.4" }
|
108
|
+
before{ allow(BRocket).to receive(:user_pwd).and_return(File.dirname(filepath)) }
|
34
109
|
|
35
110
|
before do
|
36
111
|
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
112
|
end
|
39
113
|
|
40
114
|
describe :config do
|
41
115
|
it do
|
42
116
|
expected = {
|
117
|
+
"WORKING_DIR" => ".",
|
43
118
|
"IMAGE_NAME" => image_name,
|
44
119
|
"BEFORE_BUILD" => ["abc", "def ghi"],
|
45
120
|
"AFTER_BUILD" => ["jkl", "mno"],
|
@@ -74,6 +149,23 @@ describe BRocket::Docker do
|
|
74
149
|
}.to raise_error(error_msg)
|
75
150
|
end
|
76
151
|
end
|
152
|
+
|
153
|
+
describe :call_before_build do
|
154
|
+
it do
|
155
|
+
expect(Dir).to receive(:chdir).with(subject.working_dir).and_yield
|
156
|
+
expect(subject).to receive(:sh).with("abc")
|
157
|
+
expect(subject).to receive(:sh).with("def ghi")
|
158
|
+
subject.call_before_build
|
159
|
+
end
|
160
|
+
end
|
161
|
+
describe :call_after_build do
|
162
|
+
it do
|
163
|
+
expect(Dir).to receive(:chdir).with(subject.working_dir).and_yield
|
164
|
+
expect(subject).to receive(:sh).with("jkl")
|
165
|
+
expect(subject).to receive(:sh).with("mno")
|
166
|
+
subject.call_after_build
|
167
|
+
end
|
168
|
+
end
|
77
169
|
end
|
78
170
|
|
79
171
|
end
|
data/spec/brocket/git_spec.rb
CHANGED
@@ -1,18 +1,27 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
require 'logger_pipe'
|
4
|
+
|
3
5
|
describe BRocket::Git do
|
4
6
|
|
5
7
|
let(:subject){ BRocket::Git.new }
|
6
8
|
|
7
9
|
describe "Dockerfile-basic" do
|
8
10
|
let(:filepath){ File.expand_path("../Dockerfiles/Dockerfile-git-tag", __FILE__) }
|
11
|
+
let(:version_path){ File.expand_path("../Dockerfiles/VERSION", __FILE__) }
|
9
12
|
let(:image_name){ "groovenauts/rails-example" }
|
10
13
|
let(:tag_prefix){ "containers/rails_example/" }
|
11
14
|
let(:version){ "2.3.4" }
|
12
15
|
|
13
16
|
before do
|
14
|
-
|
15
|
-
|
17
|
+
docker = BRocket::Docker.new
|
18
|
+
allow(BRocket::Docker).to receive(:new).and_return(docker)
|
19
|
+
allow(docker).to receive(:read_config_file).with(any_args).and_return(File.read(filepath))
|
20
|
+
|
21
|
+
version_file = double(:version_file)
|
22
|
+
allow(BRocket::VersionFile).to receive(:new).and_return(version_file)
|
23
|
+
allow(version_file).to receive(:options=)
|
24
|
+
allow(version_file).to receive(:current).and_return(version)
|
16
25
|
end
|
17
26
|
|
18
27
|
describe :config do
|
@@ -20,7 +29,90 @@ describe BRocket::Git do
|
|
20
29
|
expect(subject.version_tag).to eq("containers/rails_example/2.3.4")
|
21
30
|
end
|
22
31
|
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "Dockerfile-basic" do
|
35
|
+
let(:filepath){ File.expand_path("../Dockerfiles/Dockerfile-git-tag", __FILE__) }
|
36
|
+
let(:version_path){ File.expand_path("../Dockerfiles/VERSION", __FILE__) }
|
37
|
+
before do
|
38
|
+
subject.options = {dockerfile: filepath}
|
39
|
+
allow(BRocket).to receive(:user_pwd).and_return(File.dirname(filepath))
|
40
|
+
end
|
41
|
+
|
42
|
+
describe :guard_clean do
|
43
|
+
it :clean_and_commited do
|
44
|
+
expect(subject).to receive(:sh).with("git diff --exit-code")
|
45
|
+
expect(subject).to receive(:sh).with("git diff-index --quiet --cached HEAD")
|
46
|
+
expect(subject).to receive(:success).with(an_instance_of(String))
|
47
|
+
subject.guard_clean
|
48
|
+
end
|
49
|
+
|
50
|
+
context :error do
|
51
|
+
it :clean_and_not_commited do
|
52
|
+
expect(subject).to receive(:sh).with("git diff --exit-code")
|
53
|
+
expect(subject).to receive(:sh).with("git diff-index --quiet --cached HEAD").and_raise(LoggerPipe::Failure.new("not committed", nil))
|
54
|
+
end
|
55
|
+
|
56
|
+
it :not_clean_and_commited do
|
57
|
+
expect(subject).to receive(:sh).with("git diff --exit-code").and_raise(LoggerPipe::Failure.new("not clean", nil))
|
58
|
+
allow(subject).to receive(:sh).with("git diff-index --quiet --cached HEAD")
|
59
|
+
end
|
60
|
+
|
61
|
+
it :not_clean_and_not_commited do
|
62
|
+
expect(subject).to receive(:sh).with("git diff --exit-code").and_raise(LoggerPipe::Failure.new("not clean", nil))
|
63
|
+
allow(subject).to receive(:sh).with("git diff-index --quiet --cached HEAD").and_raise(LoggerPipe::Failure.new("not committed", nil))
|
64
|
+
end
|
65
|
+
|
66
|
+
after do
|
67
|
+
expect(subject).to receive(:error).with(an_instance_of(String))
|
68
|
+
expect(subject).not_to receive(:success).with(an_instance_of(String))
|
69
|
+
subject.guard_clean
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe :push do
|
75
|
+
it :valid do
|
76
|
+
expect(subject).to receive(:sh).with("git tag").and_return(%w[0.9.1 0.9.2].join("\n"))
|
77
|
+
expect(subject).to receive(:sh).with("git tag -a -m \"Version containers/rails_example/1.0.0\" containers/rails_example/1.0.0")
|
78
|
+
expect($stdout).to receive(:puts).with(/tagged containers\/rails_example\/1\.0\.0/i)
|
79
|
+
expect(subject).to receive(:sh).with("git push")
|
80
|
+
expect(subject).to receive(:sh).with("git push --tags")
|
81
|
+
expect($stdout).to receive(:puts).with(/pushed/i)
|
82
|
+
subject.push
|
83
|
+
end
|
84
|
+
it :already_tagged do
|
85
|
+
expect(subject).to receive(:sh).with("git tag").and_return(%w[0.9.1 0.9.2 1.0.0 1.0.1].map{|v| "containers/rails_example/#{v}"}.join("\n"))
|
86
|
+
expect($stderr).to receive(:puts).with(/tag .+ already .+ created/i)
|
87
|
+
subject.push
|
88
|
+
end
|
89
|
+
|
90
|
+
context :error do
|
91
|
+
before do
|
92
|
+
expect(subject).to receive(:sh).with("git tag").and_return(%w[0.9.1 0.9.2].join("\n"))
|
93
|
+
end
|
94
|
+
|
95
|
+
it "do untagging on error at git tag" do
|
96
|
+
expect(subject).to receive(:sh).
|
97
|
+
with("git tag -a -m \"Version containers/rails_example/1.0.0\" containers/rails_example/1.0.0").
|
98
|
+
and_raise(LoggerPipe::Failure.new("something wrong", nil))
|
99
|
+
expect($stderr).to receive(:puts).with(/untagging/i)
|
100
|
+
expect(subject).to receive(:sh).with("git tag -d containers/rails_example/1.0.0")
|
101
|
+
expect{ subject.push }.to raise_error(LoggerPipe::Failure)
|
102
|
+
end
|
23
103
|
|
104
|
+
it "do untagging on error at git push" do
|
105
|
+
expect(subject).to receive(:sh).with("git tag -a -m \"Version containers/rails_example/1.0.0\" containers/rails_example/1.0.0")
|
106
|
+
expect($stdout).to receive(:puts).with(/tagged containers\/rails_example\/1\.0\.0/i)
|
107
|
+
expect(subject).to receive(:sh).with("git push").
|
108
|
+
and_raise(LoggerPipe::Failure.new("something wrong", nil))
|
109
|
+
expect($stderr).to receive(:puts).with(/untagging/i)
|
110
|
+
expect(subject).to receive(:sh).with("git tag -d containers/rails_example/1.0.0")
|
111
|
+
expect{ subject.push }.to raise_error(LoggerPipe::Failure)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
24
116
|
end
|
25
117
|
|
26
118
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"app1" is old application and "app2" is newer application.
|
2
|
+
|
3
|
+
"app2" works with "app1" on the container. So the container of app2 includes app1.
|
4
|
+
|
5
|
+
## Directories
|
6
|
+
|
7
|
+
- app1
|
8
|
+
- docker
|
9
|
+
- Dockerfile
|
10
|
+
- VERSION.txt
|
11
|
+
- app2
|
12
|
+
- Dockerfile
|
13
|
+
- VERSION
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#
|
2
|
+
# [config] IMAGE_NAME: "old_app1"
|
3
|
+
# [config]
|
4
|
+
# [config] WORKING_DIR: ".."
|
5
|
+
# [config] VERSION_FILE: "VERSION.txt"
|
6
|
+
#
|
7
|
+
|
8
|
+
FROM groovenauts/ruby:2.1.2
|
9
|
+
MAINTAINER tech@groovenauts.jp
|
10
|
+
|
11
|
+
ENV RAILS_ENV production
|
12
|
+
|
13
|
+
# for debug via HTTP dicrectly
|
14
|
+
EXPOSE 3000
|
15
|
+
|
16
|
+
ADD . /usr/src/app1
|
17
|
+
WORKDIR /usr/src/app1
|
18
|
+
VOLUME /usr/src/app1/log
|
19
|
+
|
20
|
+
RUN bundle install --system
|
21
|
+
|
22
|
+
CMD ["bundle", "exec", "rails", "s", "-e", "production"]
|
@@ -0,0 +1 @@
|
|
1
|
+
1.2.1
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#
|
2
|
+
# [config] IMAGE_NAME: "new_app2"
|
3
|
+
# [config]
|
4
|
+
# [config] WORKING_DIR: ".."
|
5
|
+
# [config] GIT_TAG_PREFIX: "app2/"
|
6
|
+
#
|
7
|
+
|
8
|
+
FROM groovenauts/ruby:2.1.2
|
9
|
+
MAINTAINER tech@groovenauts.jp
|
10
|
+
|
11
|
+
ENV RAILS_ENV production
|
12
|
+
|
13
|
+
# for debug via HTTP dicrectly
|
14
|
+
EXPOSE 3000
|
15
|
+
|
16
|
+
ADD app1 /usr/src/app1
|
17
|
+
ADD app2 /usr/src/app2
|
18
|
+
WORKDIR /usr/src/app2
|
19
|
+
VOLUME /usr/src/app2/log
|
20
|
+
|
21
|
+
RUN bundle install --system
|
22
|
+
|
23
|
+
CMD ["bundle", "exec", "rails", "s", "-e", "production"]
|