docker-rake-flow 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +39 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/Rakefile.rb +4 -0
- data/docker-rake-flow.gemspec +20 -0
- data/lib/docker-flow.rb +28 -0
- data/lib/docker-rake-flow.rb +1 -0
- data/lib/rake/rake-builder.rb +83 -0
- data/lib/utils.rb +116 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5ac341521d7a255d7f14672e1ba346ab653fa042
|
4
|
+
data.tar.gz: c00d3226b2310b92e876114bd03a546f53f75882
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 57859c177359501ed7d4a101bd814dc44e5c5fbac769d932a9bbf19f7c887962897566f14f25979fbf2e9dd6cc2a219179c193b030dd1501d890848c283a4a34
|
7
|
+
data.tar.gz: b74dcdbb4140fc2971ff65892799348e5e9997d62847877b26560346315f759f1f22b21102b2fa42a5bbb286488ff08d04a82a451f83c225e0a9b04cd7140f54
|
data/.gitignore
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# JetBrains
|
2
|
+
.idea
|
3
|
+
|
4
|
+
*.gem
|
5
|
+
*.rbc
|
6
|
+
/.config
|
7
|
+
/coverage/
|
8
|
+
/InstalledFiles
|
9
|
+
/pkg/
|
10
|
+
/spec/reports/
|
11
|
+
/spec/examples.txt
|
12
|
+
/test/tmp/
|
13
|
+
/test/version_tmp/
|
14
|
+
/tmp/
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
|
21
|
+
## Documentation cache and generated files:
|
22
|
+
/.yardoc/
|
23
|
+
/_yardoc/
|
24
|
+
/doc/
|
25
|
+
/rdoc/
|
26
|
+
|
27
|
+
## Environment normalization:
|
28
|
+
/.bundle/
|
29
|
+
/vendor/bundle
|
30
|
+
/lib/bundler/man/
|
31
|
+
|
32
|
+
# for a library or gem, you might want to ignore these files since the code is
|
33
|
+
# intended to run in multiple environments; otherwise, check them in:
|
34
|
+
# Gemfile.lock
|
35
|
+
# .ruby-version
|
36
|
+
# .ruby-gemset
|
37
|
+
|
38
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
39
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 VJ Patel
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/Rakefile.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |gem|
|
3
|
+
gem.authors = ['VJ Patel']
|
4
|
+
gem.email = %w{meetthevj@gmail.com}
|
5
|
+
gem.description = 'A workflow helper for using Docker and Rake'
|
6
|
+
gem.summary = 'A workflow helper for using Docker and Rake'
|
7
|
+
gem.homepage = 'https://github.com/vjftw/docker-rake-flow'
|
8
|
+
gem.license = 'MIT'
|
9
|
+
gem.files = `git ls-files`.split($\)
|
10
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
11
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
12
|
+
gem.name = 'docker-rake-flow'
|
13
|
+
gem.require_paths = %w{lib}
|
14
|
+
# gem.version = `git describe --tags`.lines.first.strip
|
15
|
+
gem.version = '0.0.0'
|
16
|
+
gem.add_runtime_dependency 'docker-api', '~> 1.26', '>= 1.26.2'
|
17
|
+
gem.add_runtime_dependency 'ohai', '~> 8.12.1', '>= 8.12.1'
|
18
|
+
# gem.add_development_dependency 'rake'
|
19
|
+
# gem.add_development_dependency 'rspec', '~> 3.0'
|
20
|
+
end
|
data/lib/docker-flow.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'docker-api'
|
2
|
+
|
3
|
+
|
4
|
+
module DockerFlow
|
5
|
+
|
6
|
+
require 'rake/rake-builder'
|
7
|
+
require 'utils'
|
8
|
+
|
9
|
+
def version
|
10
|
+
'0.0.0'
|
11
|
+
end
|
12
|
+
|
13
|
+
def default_options
|
14
|
+
{
|
15
|
+
line_length: 80
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def options
|
20
|
+
@options ||= default_options
|
21
|
+
end
|
22
|
+
|
23
|
+
def options=(new_options)
|
24
|
+
@options = default_options.merge(new_options || {})
|
25
|
+
end
|
26
|
+
|
27
|
+
module_function :version, :options=, :options, :default_options
|
28
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'docker-flow'
|
@@ -0,0 +1,83 @@
|
|
1
|
+
class DockerFlow::RakeBuilder
|
2
|
+
|
3
|
+
|
4
|
+
#@param title [string] The title of the Project
|
5
|
+
#@param repository [string] the docker repository for the project. e.g. vjftw/homomorphic-encryption
|
6
|
+
#@param tag_prefix [string] If the repository has different services, this should be used. e.g. api
|
7
|
+
def initialize(title, repository, tag_prefix='')
|
8
|
+
@title = title
|
9
|
+
@repository = repository
|
10
|
+
@is_ci = DockerFlow::Utils.is_ci
|
11
|
+
@current_branch = DockerFlow::Utils.get_branch
|
12
|
+
@current_version = DockerFlow::Utils.get_commit_version
|
13
|
+
|
14
|
+
@branch_container_tag = @current_branch
|
15
|
+
|
16
|
+
@build_container_tag = "#{@current_branch}-#{@current_version}"
|
17
|
+
if tag_prefix.length > 0
|
18
|
+
@build_container_tag = "#{tag_prefix}-#{@build_container_tag}"
|
19
|
+
@branch_container_tag = "#{tag_prefix}-#{@branch_container_tag}"
|
20
|
+
end
|
21
|
+
|
22
|
+
@build_container_name = "#{repository}:#{@build_container_tag}"
|
23
|
+
@branch_container_name = "#{repository}:#{@branch_container_tag}"
|
24
|
+
|
25
|
+
@info = {
|
26
|
+
:host_type => @is_ci? 'Continuous Integration': 'Development',
|
27
|
+
:branch => @current_branch,
|
28
|
+
:commit_version => @current_version,
|
29
|
+
:repository => @repository,
|
30
|
+
:build_container_tag => @build_container_tag,
|
31
|
+
:branch_container_tag => @branch_container_tag
|
32
|
+
}
|
33
|
+
|
34
|
+
init_print
|
35
|
+
end
|
36
|
+
|
37
|
+
def repository
|
38
|
+
@repository
|
39
|
+
end
|
40
|
+
|
41
|
+
def title
|
42
|
+
@title
|
43
|
+
end
|
44
|
+
|
45
|
+
def is_ci
|
46
|
+
@is_ci
|
47
|
+
end
|
48
|
+
|
49
|
+
def current_branch
|
50
|
+
@current_branch
|
51
|
+
end
|
52
|
+
|
53
|
+
def current_version
|
54
|
+
@current_version
|
55
|
+
end
|
56
|
+
|
57
|
+
def build_container_name
|
58
|
+
@build_container_name
|
59
|
+
end
|
60
|
+
|
61
|
+
def branch_container_name
|
62
|
+
@branch_container_name
|
63
|
+
end
|
64
|
+
|
65
|
+
def build_container_tag
|
66
|
+
@build_container_tag
|
67
|
+
end
|
68
|
+
|
69
|
+
def branch_container_tag
|
70
|
+
@branch_container_tag
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
def init_print
|
75
|
+
DockerFlow::Utils.print_br
|
76
|
+
DockerFlow::Utils.put_project_title @title
|
77
|
+
DockerFlow::Utils.print_br
|
78
|
+
DockerFlow::Utils.put_build_information @info
|
79
|
+
DockerFlow::Utils.print_br
|
80
|
+
DockerFlow::Utils.put_system_info
|
81
|
+
puts "\n\n"
|
82
|
+
end
|
83
|
+
end
|
data/lib/utils.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'ohai'
|
2
|
+
require 'open3'
|
3
|
+
require 'docker'
|
4
|
+
|
5
|
+
|
6
|
+
class DockerFlow::Utils
|
7
|
+
|
8
|
+
def self.get_branch
|
9
|
+
if self.is_ci
|
10
|
+
branch = ENV['GIT_BRANCH'].gsub('origin/', '').strip
|
11
|
+
else
|
12
|
+
branch = self.system_command('git rev-parse --abbrev-ref HEAD').lines.first.strip
|
13
|
+
end
|
14
|
+
|
15
|
+
# make branch name tag-safe by replacing further slashes with .
|
16
|
+
branch.gsub('/', '.')
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.get_commit_version
|
20
|
+
|
21
|
+
begin
|
22
|
+
version = self.system_command 'git describe --tags'
|
23
|
+
rescue
|
24
|
+
version = self.system_command 'git rev-parse --short HEAD'
|
25
|
+
end
|
26
|
+
|
27
|
+
version.lines.first.strip
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.is_ci
|
31
|
+
if ENV.include? 'CI' and ENV['CI'] == 'true'
|
32
|
+
true
|
33
|
+
else
|
34
|
+
false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.get_system_info
|
39
|
+
system = Ohai::System.new
|
40
|
+
system.all_plugins
|
41
|
+
data = system.data
|
42
|
+
|
43
|
+
{
|
44
|
+
:os => "#{data[:platform]} #{data[:os]} #{data[:platform_version]}",
|
45
|
+
:cpu => "#{data[:cpu]['0'][:model_name]}",
|
46
|
+
:ram => "#{(data[:memory][:total].chomp('kB').to_f / 1000 / 1000).round(2)} GB (#{(data[:memory][:free].chomp('kB').to_f / 1000 / 1000).round(2)} GB free)"
|
47
|
+
}
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.put_project_title(title)
|
52
|
+
puts " # Project: #{title}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.put_build_information(info)
|
56
|
+
puts ' # Build information'
|
57
|
+
puts " Host type: #{info[:host_type]}"
|
58
|
+
puts " Git branch: #{info[:branch]} @ #{info[:commit_version]}"
|
59
|
+
puts " Container repository: #{info[:repository]}"
|
60
|
+
puts " Build container tag: #{info[:build_container_tag]}"
|
61
|
+
puts " Branch container tag: #{info[:branch_container_tag]}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.put_system_info
|
65
|
+
puts ' # System information'
|
66
|
+
info = self.get_system_info
|
67
|
+
puts " OS: #{info[:os]}"
|
68
|
+
puts " CPU: #{info[:cpu]}"
|
69
|
+
puts " RAM: #{info[:ram]}"
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.print_br
|
73
|
+
puts '-' * DockerFlow.options[:line_length]
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
def self.system_command(command)
|
78
|
+
output = []
|
79
|
+
Open3.popen3(command) do |stdin, stdout, stderr, thread|
|
80
|
+
pid = thread.pid
|
81
|
+
output << stdout.readline
|
82
|
+
|
83
|
+
exit_status = thread.value
|
84
|
+
|
85
|
+
if exit_status.to_i != 0
|
86
|
+
raise stderr
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
output.join("\n")
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
def self.clean_dirs(dirs)
|
95
|
+
Docker::Image.create('fromImage' => 'alpine:latest') do |chunk|
|
96
|
+
puts JSON.parse(chunk)
|
97
|
+
end
|
98
|
+
|
99
|
+
container = Docker::Container.create({
|
100
|
+
'Image' => 'alpine:latest',
|
101
|
+
'Volumes' => {
|
102
|
+
'/app' => {}
|
103
|
+
},
|
104
|
+
'Binds' => [
|
105
|
+
"#{Dir.getwd}:/app"
|
106
|
+
],
|
107
|
+
'WorkingDir' => '/app',
|
108
|
+
'Cmd': [
|
109
|
+
'/bin/sh', '-c', "rm -rf #{dirs.join(' ')}"
|
110
|
+
]
|
111
|
+
})
|
112
|
+
container.tap(&:start).attach { |stream, chunk| puts "#{stream}: #{chunk}" }
|
113
|
+
container.stop
|
114
|
+
container.delete
|
115
|
+
end
|
116
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: docker-rake-flow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- VJ Patel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: docker-api
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.26'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.26.2
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.26'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.26.2
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: ohai
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 8.12.1
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 8.12.1
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 8.12.1
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 8.12.1
|
53
|
+
description: A workflow helper for using Docker and Rake
|
54
|
+
email:
|
55
|
+
- meetthevj@gmail.com
|
56
|
+
executables: []
|
57
|
+
extensions: []
|
58
|
+
extra_rdoc_files: []
|
59
|
+
files:
|
60
|
+
- ".gitignore"
|
61
|
+
- Gemfile
|
62
|
+
- LICENSE
|
63
|
+
- README.md
|
64
|
+
- Rakefile.rb
|
65
|
+
- docker-rake-flow.gemspec
|
66
|
+
- lib/docker-flow.rb
|
67
|
+
- lib/docker-rake-flow.rb
|
68
|
+
- lib/rake/rake-builder.rb
|
69
|
+
- lib/utils.rb
|
70
|
+
homepage: https://github.com/vjftw/docker-rake-flow
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.4.8
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: A workflow helper for using Docker and Rake
|
94
|
+
test_files: []
|