brocket 0.2.1 → 0.2.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 +4 -4
- data/lib/brocket/configurable.rb +2 -0
- data/lib/brocket/docker.rb +17 -5
- data/lib/brocket/git.rb +16 -2
- data/lib/brocket/version.rb +1 -1
- data/spec/brocket/docker_spec.rb +61 -1
- data/spec/brocket/git_spec.rb +32 -0
- data/spec/brocket/multi_app_proj_spec.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11877a1035cefbf2e5fc03974785020abe76f506
|
4
|
+
data.tar.gz: 7aa8e5b2ea41dabf1340bb7aa3ec88dec609c703
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38588fe126cef222d6a46d947c16431707b8ffb49c7f10ba47c408a69e8c32c92e1849c4a5b7cebb080d036efdc20a66070a97e580622edea37ac8c28b517525
|
7
|
+
data.tar.gz: 26c84f52932368579a46644ca90e76a8a2ac81a2d72556cfa833dcf62e36a51d56fb3a3edea1c467f2060fa9e6512f610aa0afe61f9011905af7b71ce9e39994
|
data/lib/brocket/configurable.rb
CHANGED
@@ -10,6 +10,8 @@ module BRocket
|
|
10
10
|
CONFIG_LINE_HEADER = /\A\#\s*#{Regexp.escape(CONFIG_LINE_SEP)}\s?/.freeze
|
11
11
|
|
12
12
|
class_option :dockerfile, aliases: '-f', type: :string, default: "Dockerfile", desc: "Dockerfile to build"
|
13
|
+
# This option is used in Brocket::Docker, but it can set via BRocket::Cli
|
14
|
+
class_option :use_sudo_for_docker, aliases: '-S', type: :string, default: "auto", desc: "auto, true, false"
|
13
15
|
|
14
16
|
no_commands do
|
15
17
|
def config_image_name
|
data/lib/brocket/docker.rb
CHANGED
@@ -57,7 +57,7 @@ module BRocket
|
|
57
57
|
def build_build_command
|
58
58
|
img_name = config_image_name
|
59
59
|
version = sub(VersionFile).current
|
60
|
-
cmd = "docker build -t #{img_name}:#{version}"
|
60
|
+
cmd = sudo("docker build -t #{img_name}:#{version}")
|
61
61
|
if options[:dockerfile]
|
62
62
|
fp = config_relpath
|
63
63
|
unless fp == "Dockerfile"
|
@@ -77,12 +77,12 @@ module BRocket
|
|
77
77
|
build_cmd = config_hash['DOCKER_PUSH_COMMAND'] || 'docker push'
|
78
78
|
cmd = [
|
79
79
|
(registry || username) ?
|
80
|
-
"docker tag -f #{config_image_name}:#{version} #{img_name}:#{version}" : nil,
|
80
|
+
sudo("docker tag -f #{config_image_name}:#{version} #{img_name}:#{version}") : nil,
|
81
81
|
(registry || username) && extra_tag ?
|
82
|
-
"docker tag -f #{config_image_name}:#{version} #{img_name}:#{extra_tag}" : nil,
|
83
|
-
"#{build_cmd} #{img_name}:#{version}",
|
82
|
+
sudo("docker tag -f #{config_image_name}:#{version} #{img_name}:#{extra_tag}") : nil,
|
83
|
+
sudo("#{build_cmd} #{img_name}:#{version}"),
|
84
84
|
extra_tag ?
|
85
|
-
"#{build_cmd} #{img_name}:#{extra_tag}" : nil,
|
85
|
+
sudo("#{build_cmd} #{img_name}:#{extra_tag}") : nil,
|
86
86
|
].compact.join(' && ')
|
87
87
|
return cmd
|
88
88
|
end
|
@@ -93,6 +93,18 @@ module BRocket
|
|
93
93
|
commands = commands.compact.map(&:strip).reject(&:empty?)
|
94
94
|
commands.each{|cmd| sh(cmd) }
|
95
95
|
end
|
96
|
+
|
97
|
+
def sudo(cmd)
|
98
|
+
if @sudo_required.nil?
|
99
|
+
@sudo_required =
|
100
|
+
case options[:use_sudo_for_docker]
|
101
|
+
when /auto/i then !system("docker ps >/dev/null 2>/dev/null")
|
102
|
+
when /true/i then true
|
103
|
+
else false
|
104
|
+
end
|
105
|
+
end
|
106
|
+
@sudo_required ? "sudo #{cmd}" : cmd
|
107
|
+
end
|
96
108
|
end
|
97
109
|
|
98
110
|
end
|
data/lib/brocket/git.rb
CHANGED
@@ -7,9 +7,15 @@ module BRocket
|
|
7
7
|
|
8
8
|
desc "guard_clean", "Raise error if some difference exists."
|
9
9
|
def guard_clean
|
10
|
-
(clean? && committed?)
|
11
|
-
|
10
|
+
if (clean? && committed?)
|
11
|
+
if already_tagged? && !same_commit_as?(version_tag)
|
12
|
+
error("#{version_tag} is already tagged to another commit")
|
13
|
+
else
|
14
|
+
success("[git guard_clean] OK")
|
15
|
+
end
|
16
|
+
else
|
12
17
|
error("There are files that need to be committed first. Run `git status`")
|
18
|
+
end
|
13
19
|
end
|
14
20
|
|
15
21
|
desc "push", "push commit and tag it"
|
@@ -73,6 +79,14 @@ module BRocket
|
|
73
79
|
"%s%s" % [prefix, version]
|
74
80
|
end
|
75
81
|
|
82
|
+
def same_commit_as?(tag)
|
83
|
+
get_sha(tag) == get_sha("HEAD")
|
84
|
+
end
|
85
|
+
|
86
|
+
def get_sha(obj)
|
87
|
+
sh_stdout("git show #{obj} --format=\"%H\" --quiet").strip
|
88
|
+
end
|
89
|
+
|
76
90
|
end
|
77
91
|
|
78
92
|
end
|
data/lib/brocket/version.rb
CHANGED
data/spec/brocket/docker_spec.rb
CHANGED
@@ -10,10 +10,12 @@ describe BRocket::Docker do
|
|
10
10
|
let(:expected_options){ {"dockerfile"=>"Dockerfile"} }
|
11
11
|
before do
|
12
12
|
version_file = double(:version_file, current: version)
|
13
|
-
allow(version_file).to receive(:options=).with(
|
13
|
+
allow(version_file).to receive(:options=).with(Hash)
|
14
14
|
allow(BRocket::VersionFile).to receive(:new).and_return(version_file)
|
15
15
|
end
|
16
16
|
|
17
|
+
before{ allow(subject).to receive(:system).with("docker ps >/dev/null 2>/dev/null").and_return(true) }
|
18
|
+
|
17
19
|
describe "Dockerfile-basic" do
|
18
20
|
let(:filepath){ File.expand_path("../Dockerfiles/Dockerfile-basic", __FILE__) }
|
19
21
|
before{ allow(BRocket).to receive(:user_pwd).and_return(File.dirname(filepath)) }
|
@@ -190,4 +192,62 @@ describe BRocket::Docker do
|
|
190
192
|
end
|
191
193
|
end
|
192
194
|
|
195
|
+
describe "use_sudo_for_docker" do
|
196
|
+
let(:filepath){ File.expand_path("../Dockerfiles/Dockerfile-basic", __FILE__) }
|
197
|
+
before{ allow(BRocket).to receive(:user_pwd).and_return(File.dirname(filepath)) }
|
198
|
+
before{ subject.options = {dockerfile: filepath} }
|
199
|
+
|
200
|
+
context "auto and need sudo" do
|
201
|
+
before{ subject.options = {use_sudo_for_docker: "auto"}.update(subject.options) }
|
202
|
+
before{ allow(subject).to receive(:system).with("docker ps >/dev/null 2>/dev/null").and_return(false) }
|
203
|
+
it :build do
|
204
|
+
expect(subject).to receive(:sh).with("sudo docker build -t #{image_name}:#{version} -f Dockerfile-basic .")
|
205
|
+
subject.build
|
206
|
+
end
|
207
|
+
it :push do
|
208
|
+
expect(subject).to receive(:sh).with("sudo docker push #{image_name}:#{version}")
|
209
|
+
subject.push
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
context "auto and don't need sudo" do
|
214
|
+
before{ subject.options = {use_sudo_for_docker: "auto"}.update(subject.options) }
|
215
|
+
before{ allow(subject).to receive(:system).with("docker ps >/dev/null 2>/dev/null").and_return(true) }
|
216
|
+
it :build do
|
217
|
+
expect(subject).to receive(:sh).with("docker build -t #{image_name}:#{version} -f Dockerfile-basic .")
|
218
|
+
subject.build
|
219
|
+
end
|
220
|
+
it :push do
|
221
|
+
expect(subject).to receive(:sh).with("docker push #{image_name}:#{version}")
|
222
|
+
subject.push
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
context "true" do
|
227
|
+
before{ subject.options = {use_sudo_for_docker: "true"}.update(subject.options) }
|
228
|
+
before{ allow(subject).to receive(:system).with("docker ps >/dev/null 2>/dev/null").and_return(false) }
|
229
|
+
it :build do
|
230
|
+
expect(subject).to receive(:sh).with("sudo docker build -t #{image_name}:#{version} -f Dockerfile-basic .")
|
231
|
+
subject.build
|
232
|
+
end
|
233
|
+
it :push do
|
234
|
+
expect(subject).to receive(:sh).with("sudo docker push #{image_name}:#{version}")
|
235
|
+
subject.push
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
context "false" do
|
240
|
+
before{ subject.options = {use_sudo_for_docker: "false"}.update(subject.options) }
|
241
|
+
before{ allow(subject).to receive(:system).with("docker ps >/dev/null 2>/dev/null").and_return(true) }
|
242
|
+
it :build do
|
243
|
+
expect(subject).to receive(:sh).with("docker build -t #{image_name}:#{version} -f Dockerfile-basic .")
|
244
|
+
subject.build
|
245
|
+
end
|
246
|
+
it :push do
|
247
|
+
expect(subject).to receive(:sh).with("docker push #{image_name}:#{version}")
|
248
|
+
subject.push
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
193
253
|
end
|
data/spec/brocket/git_spec.rb
CHANGED
@@ -40,6 +40,11 @@ describe BRocket::Git do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
describe :guard_clean do
|
43
|
+
before do
|
44
|
+
allow(subject).to receive(:sh_stdout).with("git tag").and_return(%w[0.9.1 0.9.2].map{|v| "containers/rails_example/#{v}"}.join("\n"))
|
45
|
+
allow($stderr).to receive(:puts).with(/tag .+ already .+ created/i)
|
46
|
+
end
|
47
|
+
|
43
48
|
it :clean_and_commited do
|
44
49
|
expect(subject).to receive(:sh).with("git diff --exit-code")
|
45
50
|
expect(subject).to receive(:sh).with("git diff-index --quiet --cached HEAD")
|
@@ -69,6 +74,33 @@ describe BRocket::Git do
|
|
69
74
|
subject.guard_clean
|
70
75
|
end
|
71
76
|
end
|
77
|
+
|
78
|
+
context :already_tagged do
|
79
|
+
let(:sha01){ "7693b087d10319df5eaa78f016fd705a53f1d448" }
|
80
|
+
let(:sha02){ "a8dd73a3d43dd19077e333b71db8f2d86140df9e" }
|
81
|
+
|
82
|
+
before do
|
83
|
+
expect(subject).to receive(:sh).with("git diff --exit-code")
|
84
|
+
expect(subject).to receive(:sh).with("git diff-index --quiet --cached HEAD")
|
85
|
+
expect(subject).to receive(:sh_stdout).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
|
+
end
|
87
|
+
|
88
|
+
it "The SHAs are the same" do
|
89
|
+
expect(subject).to receive(:sh_stdout).with('git show containers/rails_example/1.0.0 --format="%H" --quiet').and_return(sha01)
|
90
|
+
expect(subject).to receive(:sh_stdout).with('git show HEAD --format="%H" --quiet').and_return(sha01)
|
91
|
+
expect(subject).to receive(:success).with(an_instance_of(String))
|
92
|
+
expect(subject).not_to receive(:error).with(an_instance_of(String))
|
93
|
+
subject.guard_clean
|
94
|
+
end
|
95
|
+
|
96
|
+
it "The HEAD SHA is different from the tag SHA" do
|
97
|
+
expect(subject).to receive(:sh_stdout).with('git show containers/rails_example/1.0.0 --format="%H" --quiet').and_return(sha01)
|
98
|
+
expect(subject).to receive(:sh_stdout).with('git show HEAD --format="%H" --quiet').and_return(sha02)
|
99
|
+
expect(subject).not_to receive(:success).with(an_instance_of(String))
|
100
|
+
expect(subject).to receive(:error).with(/already tagged/)
|
101
|
+
subject.guard_clean
|
102
|
+
end
|
103
|
+
end
|
72
104
|
end
|
73
105
|
|
74
106
|
describe :push do
|
@@ -136,6 +136,7 @@ describe :multi_app_proj do
|
|
136
136
|
# obj.options = {dockerfile: docker_relpath}
|
137
137
|
obj
|
138
138
|
end
|
139
|
+
before{ allow(docker_obj).to receive(:system).with("docker ps >/dev/null 2>/dev/null").and_return(true) }
|
139
140
|
it{ expect(docker_obj.working_dir).to eq File.expand_path("..", base_dir) }
|
140
141
|
it{ expect(docker_obj.config_filepath).to eq File.expand_path("Dockerfile", base_dir) }
|
141
142
|
it{ expect(docker_obj.config_relpath ).to eq "app2/Dockerfile" }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brocket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akima
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|