dockerhelper 0.0.4 → 0.0.5

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: cbb11a7f10e11248eaf1ff08f253c41e5352bfc6
4
- data.tar.gz: e663a7ddf2acaf0b77f8531f37998f5b982df1e3
3
+ metadata.gz: 9178187c9e138e25855fd94d4d748f3ec5ba8b23
4
+ data.tar.gz: 87f038059e71d699b79c678cc9f581f22141b625
5
5
  SHA512:
6
- metadata.gz: 0211dbcba6b420356d5b991469790edb34ec41fb85ea779f05f15a1df6032c6ca01f4b4654166ce8788c66c0597ed50852980df35982ed94fa319efca46de96c
7
- data.tar.gz: a19c400f9515c7fb49772ddced168f5731b479d9c60603c8bd218da8b792bb4a55243249241166c34c128fe8d794f49c045b7070ad8957586e0c03b0a1592927
6
+ metadata.gz: e5cb7334b53cc21763ea48a91bcc05237e67d65708e9210071f5a73d8a739f96873a2afa9a6ce79e3a91e4eb5c5281ca421c7dd7f027c7fb28124e697a61c5df
7
+ data.tar.gz: 02744ba8492b5ba8aa96f2218fd6b0d9e5258ea9c43793118ef07f611d7fc52ffc6268e8dc7371103710c582c056b1d570a350527e65c90d876979dad6c426b5
data/README.md CHANGED
@@ -41,6 +41,7 @@ config = Dockerhelper.configure do |c|
41
41
  c.docker_repo_tag_prefix = 'prd-'
42
42
  c.kube_rc_template = File.expand_path('../project-rc.yml.erb', __FILE__)
43
43
  c.kube_rc_dest_dir = File.dirname(__FILE__)
44
+ c.env_vars = %w(REQUIRED_ENV_VAR)
44
45
  end
45
46
 
46
47
  Dockerhelper::Tasks.init(config)
data/lib/dockerhelper.rb CHANGED
@@ -12,8 +12,6 @@ module Dockerhelper
12
12
  module_function :cmd
13
13
 
14
14
  def self.configure(&block)
15
- config = Config.new
16
- block.call(config)
17
- config
15
+ Config.new.tap(&block).tap(&:check_env_vars!)
18
16
  end
19
17
  end
@@ -13,6 +13,9 @@ module Dockerhelper
13
13
  attr_accessor :environment
14
14
  attr_accessor :kube_rc_template
15
15
  attr_accessor :kube_rc_dest_dir
16
+ attr_accessor :kube_rc_version
17
+ attr_accessor :env_vars
18
+ attr_accessor :prebuild_command
16
19
 
17
20
  def initialize
18
21
  # defaults
@@ -28,6 +31,10 @@ module Dockerhelper
28
31
  @docker ||= Docker.new(chdir: git_root)
29
32
  end
30
33
 
34
+ def kubernetes?
35
+ @kube_rc_template && @kube_rc_dest_dir
36
+ end
37
+
31
38
  def kubernetes
32
39
  @kubernetes ||= Kubernetes.new(self)
33
40
  end
@@ -35,5 +42,20 @@ module Dockerhelper
35
42
  def docker_repo_tag
36
43
  @docker_tag || "#{docker_repo_tag_prefix}#{git.latest_rev}"
37
44
  end
45
+
46
+ def check_env_vars!
47
+ return unless env_vars
48
+ unless env_vars.respond_to?(:reject)
49
+ raise ArgumentError.new('Expected an array of env_vars')
50
+ end
51
+ undefined = env_vars.reject(&ENV.method(:has_key?))
52
+ unless undefined.empty?
53
+ raise StandardError.new("The environment must define #{undefined.join ', '}")
54
+ end
55
+ end
56
+
57
+ def prebuild?
58
+ prebuild_command && !prebuild_command.empty?
59
+ end
38
60
  end
39
61
  end
@@ -13,7 +13,7 @@ module Dockerhelper
13
13
  end
14
14
 
15
15
  def app_version
16
- config.docker_repo_tag
16
+ config.kube_rc_version || config.docker_repo_tag
17
17
  end
18
18
 
19
19
  def app_full_name
@@ -39,8 +39,7 @@ module Dockerhelper
39
39
  end
40
40
 
41
41
  def replication_controller_delete
42
- Command.new("kubectl delete -f #{replication_controller_filename}",
43
- label: 'kubectl-delete-rc').run
42
+ Command.new("kubectl delete rc #{current_rc}", label: 'kubectl-delete-rc').run
44
43
  end
45
44
 
46
45
  def replication_controller_yaml
@@ -5,14 +5,21 @@ module Dockerhelper
5
5
  extend ::Rake::DSL
6
6
 
7
7
  def self.init(config)
8
+ build_tasks = [:pull, :docker_build, :repo_tag, :push]
9
+ build_tasks << :'kube:gen_rc' if config.kubernetes?
10
+
8
11
  namespace :docker do
9
12
  namespace(config.environment) do
10
-
11
13
  desc 'Print config info'
12
14
  task :info do
13
15
  puts config.inspect
14
16
  end
15
17
 
18
+ desc 'Prepare to build docker image'
19
+ task :prebuild do
20
+ Command.new(config.prebuild_command, label: 'prebuild').run if config.prebuild?
21
+ end
22
+
16
23
  desc 'Build docker image'
17
24
  task :docker_build do
18
25
  config.docker.build(config.dockerfile, tag: config.docker_image)
@@ -35,34 +42,36 @@ module Dockerhelper
35
42
  end
36
43
 
37
44
  desc 'Git clone, build image, and push image to Docker Hub'
38
- task :build => [:pull, :docker_build, :repo_tag, :push, 'kube:gen_rc']
45
+ task :build => build_tasks
39
46
 
40
- namespace :kube do
41
- desc 'Generate replication controller for the current build'
42
- task :gen_rc do
43
- config.kubernetes.write_replication_controller
44
- puts "Created replication-controller: #{config.kubernetes.replication_controller_filename}"
45
- end
47
+ if config.kubernetes?
48
+ namespace :kube do
49
+ desc 'Generate replication controller for the current build'
50
+ task :gen_rc do
51
+ config.kubernetes.write_replication_controller
52
+ puts "Created replication-controller: #{config.kubernetes.replication_controller_filename}"
53
+ end
46
54
 
47
- desc 'Get current replication controller version'
48
- task :current_rc do
49
- puts config.kubernetes.current_rc
50
- end
55
+ desc 'Get current replication controller version'
56
+ task :current_rc do
57
+ puts config.kubernetes.current_rc
58
+ end
51
59
 
52
- desc 'Run replication controller rolling-update'
53
- task :rolling_update => [:gen_rc] do
54
- config.kubernetes.rolling_update
55
- end
60
+ desc 'Run replication controller rolling-update'
61
+ task :rolling_update => [:gen_rc] do
62
+ config.kubernetes.rolling_update
63
+ end
56
64
 
57
- desc 'Create replication controller'
58
- task :create_rc => [:gen_rc] do
59
- config.kubernetes.replication_controller_create
60
- end
65
+ desc 'Create replication controller'
66
+ task :create_rc => [:gen_rc] do
67
+ config.kubernetes.replication_controller_create
68
+ end
61
69
 
62
- desc 'Delete replication controller (USE WITH CAUTION)'
63
- task :delete_rc do
64
- # TODO add "are you sure?" prompt
65
- config.kubernetes.replication_controller_delete
70
+ desc 'Delete replication controller (USE WITH CAUTION)'
71
+ task :delete_rc do
72
+ # TODO add "are you sure?" prompt
73
+ config.kubernetes.replication_controller_delete
74
+ end
66
75
  end
67
76
  end
68
77
  end
@@ -70,4 +79,3 @@ module Dockerhelper
70
79
  end
71
80
  end
72
81
  end
73
-
@@ -1,3 +1,3 @@
1
1
  module Dockerhelper
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dockerhelper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh McDade
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-16 00:00:00.000000000 Z
11
+ date: 2015-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler