dockerhelper 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +35 -11
- data/lib/dockerhelper.rb +1 -1
- data/lib/dockerhelper/command.rb +2 -0
- data/lib/dockerhelper/config.rb +9 -0
- data/lib/dockerhelper/kubernetes.rb +49 -0
- data/lib/dockerhelper/rake.rb +19 -2
- data/lib/dockerhelper/version.rb +1 -1
- metadata +3 -3
- data/lib/dockerhelper/build.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bec3a523719acd104ddce4ae0f3b2180eeae91c
|
4
|
+
data.tar.gz: c428627da6a159c3f0e6fc6b7129d4ee6264e656
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4660d2a114a52144f8d728e2af23c1d41b6341d5e3ce80cf369fb85cfb3420396a854da0254ca9cb8ff18c8be23fd38c1942e39ff55408b0d5588b1a005d6264
|
7
|
+
data.tar.gz: 7c060304e6bb89bca3ef3a7a51ef5b83428ec65cf578a2d96a3296ec6a15efa28db4b1aff11b87089d557f5e4041a8ff00bf050959fab4f4b2e80d8e5c1dab77
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Dockerhelper
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
Helper classes and rake tasks to build Docker images, push them to DockerHub,
|
4
|
+
and deploy updates to Kubernetes. Assumes a rather specific workflow for
|
5
|
+
building Docker images and deploying them to Kubernetes.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,15 +22,39 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
## Development
|
25
|
+
Example usage in a `Rakefile`:
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
```ruby
|
28
|
+
require 'dockerhelper'
|
29
|
+
require 'dockerhelper/rake'
|
30
|
+
|
31
|
+
project_root = File.expand_path('../../', __FILE__)
|
32
|
+
config = Dockerhelper.configure do |c|
|
33
|
+
c.app_name = 'project'
|
34
|
+
c.environment = :production
|
35
|
+
c.git_repo_url = 'git@github.com:org/project.git'
|
36
|
+
c.git_root = File.join(project_root, 'tmp/repo')
|
37
|
+
c.git_branch = ENV['GIT_BRANCH'] || 'master'
|
38
|
+
c.dockerfile = 'docker/Dockerfile.production'
|
39
|
+
c.docker_image = 'project-image-name'
|
40
|
+
c.docker_repo = 'org/project'
|
41
|
+
c.docker_repo_tag_prefix = 'prd-'
|
42
|
+
c.kube_rc_template = File.expand_path('../project-rc.yml.erb', __FILE__)
|
43
|
+
c.kube_rc_dest_dir = File.dirname(__FILE__)
|
44
|
+
end
|
45
|
+
|
46
|
+
Dockerhelper::Tasks.init(config)
|
47
|
+
```
|
32
48
|
|
33
|
-
|
49
|
+
The above will define rake tasks, for example:
|
34
50
|
|
35
|
-
|
51
|
+
```
|
52
|
+
rake docker:production:build # Build docker image
|
53
|
+
rake docker:production:deploy # Git clone, build image, and push image to Docker Hub
|
54
|
+
rake docker:production:info # Print config info
|
55
|
+
rake docker:production:kube:gen_rc # Generate replication controller for the current build
|
56
|
+
rake docker:production:pull # Pull git repo
|
57
|
+
rake docker:production:push # Push docker images to Docker Hub
|
58
|
+
rake docker:production:repo_tag # Tag docker image
|
36
59
|
|
60
|
+
```
|
data/lib/dockerhelper.rb
CHANGED
data/lib/dockerhelper/command.rb
CHANGED
data/lib/dockerhelper/config.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Dockerhelper
|
2
2
|
class Config
|
3
|
+
attr_accessor :app_name
|
3
4
|
attr_accessor :git_root
|
4
5
|
attr_accessor :git_branch
|
5
6
|
attr_accessor :git_repo_url
|
@@ -9,10 +10,14 @@ module Dockerhelper
|
|
9
10
|
attr_accessor :rev_length
|
10
11
|
attr_accessor :dockerfile
|
11
12
|
attr_accessor :docker_repo_tag_prefix
|
13
|
+
attr_accessor :environment
|
14
|
+
attr_accessor :kube_rc_template
|
15
|
+
attr_accessor :kube_rc_dest_dir
|
12
16
|
|
13
17
|
def initialize
|
14
18
|
# defaults
|
15
19
|
@rev_length = 8
|
20
|
+
@kube_rc_dest_dir = Dir.pwd
|
16
21
|
end
|
17
22
|
|
18
23
|
def git
|
@@ -23,6 +28,10 @@ module Dockerhelper
|
|
23
28
|
@docker ||= Docker.new(chdir: git_root)
|
24
29
|
end
|
25
30
|
|
31
|
+
def kubernetes
|
32
|
+
@kubernetes ||= Kubernetes.new(self)
|
33
|
+
end
|
34
|
+
|
26
35
|
def docker_repo_tag
|
27
36
|
@docker_tag || "#{docker_repo_tag_prefix}#{git.latest_rev}"
|
28
37
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Dockerhelper
|
5
|
+
class Kubernetes
|
6
|
+
attr_reader :config
|
7
|
+
def initialize(config)
|
8
|
+
@config = config
|
9
|
+
end
|
10
|
+
|
11
|
+
def app_name
|
12
|
+
config.app_name
|
13
|
+
end
|
14
|
+
|
15
|
+
def app_version
|
16
|
+
config.docker_repo_tag
|
17
|
+
end
|
18
|
+
|
19
|
+
def app_full_name
|
20
|
+
"#{app_name}-#{app_version}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def current_rc
|
24
|
+
out = Command.new("kubectl get rc -l app=#{app_name},environment=#{config.environment}",
|
25
|
+
label: 'kubectl-get-rc').capture
|
26
|
+
|
27
|
+
# assumes rc will be found
|
28
|
+
out.lines[1].match(/^\S+/)[0]
|
29
|
+
end
|
30
|
+
|
31
|
+
def rolling_update
|
32
|
+
Command.new("kubectl rolling-update #{current_rc} -f #{replication_controller_filename}",
|
33
|
+
label: 'kubectl-get-rc').run
|
34
|
+
end
|
35
|
+
|
36
|
+
def replication_controller_yaml
|
37
|
+
yaml_in = File.read(config.kube_rc_template)
|
38
|
+
ERB.new(yaml_in).result(binding)
|
39
|
+
end
|
40
|
+
|
41
|
+
def write_replication_controller
|
42
|
+
File.write(replication_controller_filename, replication_controller_yaml)
|
43
|
+
end
|
44
|
+
|
45
|
+
def replication_controller_filename
|
46
|
+
File.join(config.kube_rc_dest_dir, "#{app_full_name}-rc.yml")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/dockerhelper/rake.rb
CHANGED
@@ -4,9 +4,9 @@ module Dockerhelper
|
|
4
4
|
module Tasks
|
5
5
|
extend ::Rake::DSL
|
6
6
|
|
7
|
-
def self.init(config
|
7
|
+
def self.init(config)
|
8
8
|
namespace :docker do
|
9
|
-
namespace(environment) do
|
9
|
+
namespace(config.environment) do
|
10
10
|
|
11
11
|
desc 'Print config info'
|
12
12
|
task :info do
|
@@ -36,6 +36,23 @@ module Dockerhelper
|
|
36
36
|
|
37
37
|
desc 'Git clone, build image, and push image to Docker Hub'
|
38
38
|
task :deploy => [:pull, :build, :repo_tag, :push]
|
39
|
+
|
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
|
+
end
|
45
|
+
|
46
|
+
desc 'Get current replication controller version'
|
47
|
+
task :current_rc do
|
48
|
+
puts config.kubernetes.current_rc
|
49
|
+
end
|
50
|
+
|
51
|
+
desc 'Run replication controller rolling-update'
|
52
|
+
task :rolling_update do
|
53
|
+
config.kubernetes.rolling_update
|
54
|
+
end
|
55
|
+
end
|
39
56
|
end
|
40
57
|
end
|
41
58
|
end
|
data/lib/dockerhelper/version.rb
CHANGED
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
|
+
version: 0.0.3
|
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-
|
11
|
+
date: 2015-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -53,11 +53,11 @@ files:
|
|
53
53
|
- bin/setup
|
54
54
|
- dockerhelper.gemspec
|
55
55
|
- lib/dockerhelper.rb
|
56
|
-
- lib/dockerhelper/build.rb
|
57
56
|
- lib/dockerhelper/command.rb
|
58
57
|
- lib/dockerhelper/config.rb
|
59
58
|
- lib/dockerhelper/docker.rb
|
60
59
|
- lib/dockerhelper/git.rb
|
60
|
+
- lib/dockerhelper/kubernetes.rb
|
61
61
|
- lib/dockerhelper/rake.rb
|
62
62
|
- lib/dockerhelper/version.rb
|
63
63
|
homepage: https://github.com/joshm1/dockerhelper
|
data/lib/dockerhelper/build.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
module Dockerhelper
|
2
|
-
class Build
|
3
|
-
def initialize(config)
|
4
|
-
@builder = config
|
5
|
-
end
|
6
|
-
|
7
|
-
def git
|
8
|
-
@git ||= Git.new(config.git_repo, rev_length: config.rev_length)
|
9
|
-
end
|
10
|
-
|
11
|
-
def docker
|
12
|
-
@docker ||= Docker.new(chdir: config.git_repo)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|