brocket 0.0.2 → 0.0.3
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/base.rb +8 -11
- data/lib/brocket/cli.rb +4 -4
- data/lib/brocket/docker.rb +28 -31
- data/lib/brocket/git.rb +3 -1
- data/lib/brocket/version.rb +1 -1
- data/lib/brocket/version_file.rb +12 -14
- data/spec/brocket/Dockerfiles/Dockerfile-git-tag +20 -0
- data/spec/brocket/docker_spec.rb +9 -6
- data/spec/brocket/git_spec.rb +26 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22fcf9e97f299b10983753dd1f74abb4ff31e78e
|
4
|
+
data.tar.gz: 25a8ecaa347cd4db902508ac1112b6e98bb7e9dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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, :
|
8
|
-
class_option :dryrun , :
|
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
|
19
|
-
|
18
|
+
def opts
|
19
|
+
@opts ||= options || {}
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
|
22
|
+
def dryrun?
|
23
|
+
opts[:dryrun]
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
27
|
-
|
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
|
22
|
-
def release
|
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
|
24
|
+
sub(Docker).build
|
25
25
|
sub(Git).push
|
26
|
-
sub(Docker).push
|
26
|
+
sub(Docker).push
|
27
27
|
end
|
28
28
|
|
29
29
|
desc "version SUBCOMMAND ...ARGS", "manage VERSION file"
|
data/lib/brocket/docker.rb
CHANGED
@@ -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
|
12
|
-
def config
|
13
|
-
$stdout.puts(YAML.dump(config_hash
|
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
|
17
|
-
def build
|
16
|
+
desc "build", "build docker image"
|
17
|
+
def build
|
18
18
|
info("[docker build] starting")
|
19
|
-
|
20
|
-
c = config_hash(dir)
|
19
|
+
c = config_hash
|
21
20
|
img_name = config_image_name(c)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
37
|
-
def push
|
35
|
+
desc "push", "push docker image to docker hub"
|
36
|
+
def push
|
38
37
|
info("[docker push] starting")
|
39
|
-
c = config_hash
|
38
|
+
c = config_hash
|
40
39
|
img_name = config_image_name(c)
|
41
|
-
|
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
|
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
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
60
|
+
def read_config_file
|
64
61
|
File.read("Dockerfile")
|
65
62
|
end
|
66
63
|
|
data/lib/brocket/git.rb
CHANGED
data/lib/brocket/version.rb
CHANGED
data/lib/brocket/version_file.rb
CHANGED
@@ -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
|
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
|
-
|
34
|
-
def
|
35
|
-
|
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
|
-
|
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
|
-
|
45
|
+
alias_method :current, :read_file
|
48
46
|
|
49
47
|
def write_file(version)
|
50
|
-
File.open(
|
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(
|
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"]
|
data/spec/brocket/docker_spec.rb
CHANGED
@@ -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(:
|
14
|
-
|
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(:
|
37
|
-
|
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(
|
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
|
-
|
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.
|
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
|