brocket 0.2.0 → 0.2.1

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: 54c63386ef0806f1a1e9ac34e9692c8529ad2cc0
4
- data.tar.gz: 5965c22451aec6eb6e003df5bbba94219383d1b8
3
+ metadata.gz: 2cf15efdda61d666c2aa047bdda6db4024ac212e
4
+ data.tar.gz: e90df6e84b87669fe3d7640098028f4a051671c6
5
5
  SHA512:
6
- metadata.gz: 2e80157b476a1ff419dcf54501b44dbaabb419ea62ed3d7e4c842fba6f1a2b46f7d0f1d21072097f2e4597b2642b6e809b212d8334a4ab1bdacbf285adb2bd07
7
- data.tar.gz: 1cfadc60e0bf8e3b6cd42536d31311e394663b619dd6f80b5afcd21481764c709c295aa01a54ab755bc895ddefbb60efeb9635f536168a183c10279878fc3bdb
6
+ metadata.gz: 268c7b07e00950c094bf5e10763e9bb4bb1c3a59fc1f956fe9a94bec10c0d77ce2e4fb42a9c575e8a31f9f826353dfdbf0fa547d7e848626874767a0d37a95c0
7
+ data.tar.gz: b1e6605471f85a84ad8d44f6ca3bf0bb1367f542f658e61791045c79cbdbc4ec6087d280a872fbc2e63585bfa4bf05a9fa819ee0a6e682428f00ca42dda308a8
data/README.md CHANGED
@@ -7,10 +7,10 @@ config IMAGE_NAME and hooks like BEFORE_BUILD and AFTER_BUILD.
7
7
  ## Behavior
8
8
 
9
9
  - `brocket release`
10
- 1. check the local repository si clean and commited
10
+ 1. check the local repository is clean and commited
11
11
  2. same as `brocket docker build`
12
- 3. push by git
13
- 4. push by docker
12
+ 3. same as `brocket git push`
13
+ 4. docker push
14
14
  - `brocket docker build`
15
15
  1. cd WORKING_DIR
16
16
  2. call BEFORE_BUILD
@@ -18,6 +18,10 @@ config IMAGE_NAME and hooks like BEFORE_BUILD and AFTER_BUILD.
18
18
  - call ON_BUILD_COMPLETE on success
19
19
  - call ON_BUILD_ERROR on failure
20
20
  4. call AFTER_BUILD
21
+ - `brocket git push`
22
+ 1. git tag
23
+ 2. git push
24
+ - git tag -d if error
21
25
 
22
26
  ## Installation
23
27
 
@@ -122,6 +126,10 @@ Set the registry host name to push not to hub.docker.com .
122
126
 
123
127
  Set the user name on the registry host to push.
124
128
 
129
+ #### DOCKER_PUSH_EXTRA_TAG
130
+
131
+ Set the another tag to push. e.g. "latest"
132
+
125
133
 
126
134
  ### For more information
127
135
 
data/lib/brocket/base.rb CHANGED
@@ -44,7 +44,11 @@ module BRocket
44
44
  end
45
45
 
46
46
  def sh(cmd)
47
- LoggerPipe.run(logger, cmd, dry_run: dryrun?)
47
+ LoggerPipe.run(logger, cmd, dry_run: dryrun?, returns: :none, logging: :both)
48
+ end
49
+
50
+ def sh_stdout(cmd)
51
+ LoggerPipe.run(logger, cmd, returns: :stdout, logging: :stderr) # ignore dryrun?
48
52
  end
49
53
 
50
54
  end
@@ -71,14 +71,18 @@ module BRocket
71
71
  def build_push_command
72
72
  registry = config_hash['DOCKER_PUSH_REGISTRY']
73
73
  username = config_hash['DOCKER_PUSH_USERNAME']
74
+ extra_tag = config_hash['DOCKER_PUSH_EXTRA_TAG']
74
75
  img_name = [registry, username, config_image_name].compact.join('/')
75
76
  version = sub(VersionFile).current
76
77
  build_cmd = config_hash['DOCKER_PUSH_COMMAND'] || 'docker push'
77
78
  cmd = [
78
79
  (registry || username) ?
79
- "docker tag -f #{config_image_name}:#{version} #{img_name}:#{version}" :
80
- nil,
80
+ "docker tag -f #{config_image_name}:#{version} #{img_name}:#{version}" : nil,
81
+ (registry || username) && extra_tag ?
82
+ "docker tag -f #{config_image_name}:#{version} #{img_name}:#{extra_tag}" : nil,
81
83
  "#{build_cmd} #{img_name}:#{version}",
84
+ extra_tag ?
85
+ "#{build_cmd} #{img_name}:#{extra_tag}" : nil,
82
86
  ].compact.join(' && ')
83
87
  return cmd
84
88
  end
data/lib/brocket/git.rb CHANGED
@@ -61,7 +61,7 @@ module BRocket
61
61
  end
62
62
 
63
63
  def already_tagged?
64
- if sh('git tag').split(/\n/).include?(version_tag)
64
+ if sh_stdout('git tag').split(/\n/).include?(version_tag)
65
65
  $stderr.puts "Tag #{version_tag} has already been created."
66
66
  true
67
67
  end
@@ -1,3 +1,3 @@
1
1
  module BRocket
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -0,0 +1,24 @@
1
+ #
2
+ # [config] IMAGE_NAME: "rails-example"
3
+ # [config]
4
+ # [config] DOCKER_PUSH_COMMAND: "gcloud docker push"
5
+ # [config] DOCKER_PUSH_REGISTRY: "asia.gcr.io"
6
+ # [config] DOCKER_PUSH_USERNAME: "groovenauts"
7
+ # [config] DOCKER_PUSH_EXTRA_TAG: "latest"
8
+ #
9
+
10
+ FROM groovenauts/ruby:2.1.2
11
+ MAINTAINER tech@groovenauts.jp
12
+
13
+ ENV RAILS_ENV production
14
+
15
+ # for debug via HTTP dicrectly
16
+ EXPOSE 3000
17
+
18
+ ADD . /usr/src/app
19
+ WORKDIR /usr/src/app
20
+ VOLUME /usr/src/app/log
21
+
22
+ RUN bundle install --system
23
+
24
+ CMD ["bundle", "exec", "rails", "s", "-e", "production"]
@@ -7,11 +7,11 @@ describe BRocket::Base do
7
7
  describe :sh do
8
8
  let(:cmd){ 'echo "FOO"' }
9
9
  it "without dryrun" do
10
- expect(LoggerPipe).to receive(:run).with(BRocket.logger, cmd, dry_run: nil)
10
+ expect(LoggerPipe).to receive(:run).with(BRocket.logger, cmd, dry_run: nil, returns: :none, logging: :both)
11
11
  end
12
12
  it "with dryrun" do
13
13
  subject.options = {dryrun: true}
14
- expect(LoggerPipe).to receive(:run).with(BRocket.logger, cmd, dry_run: true)
14
+ expect(LoggerPipe).to receive(:run).with(BRocket.logger, cmd, dry_run: true, returns: :none, logging: :both)
15
15
  end
16
16
 
17
17
  after do
@@ -67,6 +67,28 @@ describe BRocket::Docker do
67
67
  end
68
68
  end
69
69
 
70
+ describe "Dockerfile-push-extra-tag" do
71
+ let(:original_image_name){ "rails-example" }
72
+ let(:gcr_image_name){ "asia.gcr.io/groovenauts/rails-example" }
73
+ let(:filepath){ File.expand_path("../Dockerfiles/Dockerfile-push-extra-tag", __FILE__) }
74
+ before{ allow(BRocket).to receive(:user_pwd).and_return(File.dirname(filepath)) }
75
+ before{ subject.options = {dockerfile: filepath} }
76
+ let(:expected_options){ {dockerfile: filepath} }
77
+
78
+ describe :push do
79
+ it do
80
+ expected_cmd = [
81
+ "docker tag -f #{original_image_name}:#{version} #{gcr_image_name}:#{version}",
82
+ "docker tag -f #{original_image_name}:#{version} #{gcr_image_name}:latest",
83
+ "gcloud docker push #{gcr_image_name}:#{version}",
84
+ "gcloud docker push #{gcr_image_name}:latest",
85
+ ].join(' && ')
86
+ expect(subject).to receive(:sh).with(expected_cmd)
87
+ subject.push
88
+ end
89
+ end
90
+ end
91
+
70
92
  describe "Dockerfile-working_dir" do
71
93
  let(:filepath){ File.expand_path("../Dockerfiles/Dockerfile-working_dir", __FILE__) }
72
94
  let(:expected_options){ {dockerfile: filepath} }
@@ -31,7 +31,7 @@ describe BRocket::Git do
31
31
  end
32
32
  end
33
33
 
34
- describe "Dockerfile-basic" do
34
+ describe "Dockerfile-git-tag" do
35
35
  let(:filepath){ File.expand_path("../Dockerfiles/Dockerfile-git-tag", __FILE__) }
36
36
  let(:version_path){ File.expand_path("../Dockerfiles/VERSION", __FILE__) }
37
37
  before do
@@ -73,7 +73,7 @@ describe BRocket::Git do
73
73
 
74
74
  describe :push do
75
75
  it :valid do
76
- expect(subject).to receive(:sh).with("git tag").and_return(%w[0.9.1 0.9.2].join("\n"))
76
+ expect(subject).to receive(:sh_stdout).with("git tag").and_return(%w[0.9.1 0.9.2].join("\n"))
77
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
78
  expect($stdout).to receive(:puts).with(/tagged containers\/rails_example\/1\.0\.0/i)
79
79
  expect(subject).to receive(:sh).with("git push")
@@ -82,14 +82,14 @@ describe BRocket::Git do
82
82
  subject.push
83
83
  end
84
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"))
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
86
  expect($stderr).to receive(:puts).with(/tag .+ already .+ created/i)
87
87
  subject.push
88
88
  end
89
89
 
90
90
  context :error do
91
91
  before do
92
- expect(subject).to receive(:sh).with("git tag").and_return(%w[0.9.1 0.9.2].join("\n"))
92
+ expect(subject).to receive(:sh_stdout).with("git tag").and_return(%w[0.9.1 0.9.2].join("\n"))
93
93
  end
94
94
 
95
95
  it "do untagging on error at git tag" do
@@ -112,6 +112,23 @@ describe BRocket::Git do
112
112
  end
113
113
  end
114
114
 
115
+ context "with dryrun" do
116
+ it do
117
+ subject.options = {dryrun: true}.update(subject.options)
118
+ # Call `git tag` even if --dryrun is given
119
+ expect(LoggerPipe).to receive(:run).
120
+ with(BRocket.logger, "git tag", returns: :stdout, logging: :stderr).
121
+ and_return(%w[0.9.1 0.9.2].join("\n"))
122
+ opts = {dry_run: true, returns: :none, logging: :both}
123
+ expect(LoggerPipe).to receive(:run).with(BRocket.logger, "git tag -a -m \"Version containers/rails_example/1.0.0\" containers/rails_example/1.0.0", opts)
124
+ expect($stdout).to receive(:puts).with(/tagged containers\/rails_example\/1\.0\.0/i)
125
+ expect(LoggerPipe).to receive(:run).with(BRocket.logger, "git push", opts)
126
+ expect(LoggerPipe).to receive(:run).with(BRocket.logger, "git push --tags", opts)
127
+ expect($stdout).to receive(:puts).with(/pushed/i)
128
+ subject.push
129
+ end
130
+ end
131
+
115
132
  end
116
133
  end
117
134
 
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - akima
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-02 00:00:00.000000000 Z
11
+ date: 2016-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: thor
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
17
  - - ">="
17
18
  - !ruby/object:Gem::Version
18
19
  version: '0'
19
- name: thor
20
- prerelease: false
21
20
  type: :runtime
21
+ prerelease: false
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
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - ">="
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
- name: logger_pipe
34
- prerelease: false
35
34
  type: :runtime
35
+ prerelease: false
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
42
43
  requirement: !ruby/object:Gem::Requirement
43
44
  requirements:
44
45
  - - "~>"
45
46
  - !ruby/object:Gem::Version
46
47
  version: '1.6'
47
- name: bundler
48
- prerelease: false
49
48
  type: :development
49
+ prerelease: false
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
56
57
  requirement: !ruby/object:Gem::Requirement
57
58
  requirements:
58
59
  - - "~>"
59
60
  - !ruby/object:Gem::Version
60
61
  version: '10.0'
61
- name: rake
62
- prerelease: false
63
62
  type: :development
63
+ prerelease: false
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
70
71
  requirement: !ruby/object:Gem::Requirement
71
72
  requirements:
72
73
  - - ">="
73
74
  - !ruby/object:Gem::Version
74
75
  version: '0'
75
- name: rspec
76
- prerelease: false
77
76
  type: :development
77
+ prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
@@ -110,6 +110,7 @@ files:
110
110
  - spec/brocket/Dockerfiles/Dockerfile-git-tag
111
111
  - spec/brocket/Dockerfiles/Dockerfile-hook
112
112
  - spec/brocket/Dockerfiles/Dockerfile-invalid-version
113
+ - spec/brocket/Dockerfiles/Dockerfile-push-extra-tag
113
114
  - spec/brocket/Dockerfiles/Dockerfile-working_dir
114
115
  - spec/brocket/Dockerfiles/VERSION
115
116
  - spec/brocket/base_spec.rb
@@ -132,7 +133,7 @@ homepage: ''
132
133
  licenses:
133
134
  - MIT
134
135
  metadata: {}
135
- post_install_message:
136
+ post_install_message:
136
137
  rdoc_options: []
137
138
  require_paths:
138
139
  - lib
@@ -147,9 +148,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
148
  - !ruby/object:Gem::Version
148
149
  version: '0'
149
150
  requirements: []
150
- rubyforge_project:
151
- rubygems_version: 2.4.8
152
- signing_key:
151
+ rubyforge_project:
152
+ rubygems_version: 2.5.1
153
+ signing_key:
153
154
  specification_version: 4
154
155
  summary: supports to build Docker Container with VERSION
155
156
  test_files:
@@ -158,6 +159,7 @@ test_files:
158
159
  - spec/brocket/Dockerfiles/Dockerfile-git-tag
159
160
  - spec/brocket/Dockerfiles/Dockerfile-hook
160
161
  - spec/brocket/Dockerfiles/Dockerfile-invalid-version
162
+ - spec/brocket/Dockerfiles/Dockerfile-push-extra-tag
161
163
  - spec/brocket/Dockerfiles/Dockerfile-working_dir
162
164
  - spec/brocket/Dockerfiles/VERSION
163
165
  - spec/brocket/base_spec.rb
@@ -176,4 +178,4 @@ test_files:
176
178
  - spec/brocket/version_file_spec.rb
177
179
  - spec/brocket_spec.rb
178
180
  - spec/spec_helper.rb
179
- has_rdoc:
181
+ has_rdoc: