docker-template 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -10
- data/README.md +1 -73
- data/lib/docker/template.rb +14 -0
- data/lib/docker/template/cli.rb +22 -77
- data/lib/docker/template/cli/build.rb +64 -0
- data/lib/docker/template/cli/list.rb +136 -0
- data/lib/docker/template/metadata.rb +2 -2
- data/lib/docker/template/parser.rb +1 -1
- data/lib/docker/template/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c347557d3339e68e700c711c0d6707864e952d4
|
4
|
+
data.tar.gz: 832e334ab66bc3da1fe09b380dbc11e8adb047d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc72edadc7b070001a11e408deb478bc1c034bba062667df22a5861d4de712595a13dbbbab5632bdd46765c2d3ee8047cfbbf101f2180614a434d1ef05c76f8d
|
7
|
+
data.tar.gz: e8ec4681fa1f842d7d128b639d04ff03f3a3a0236d2dce497fc0c02786ddcbfd5c7b0a29a7f1447c2340e855b03eb6625e7d9ce30a64aeba4c4c4035d4ba160b
|
data/Gemfile
CHANGED
@@ -10,10 +10,11 @@ gemspec
|
|
10
10
|
|
11
11
|
group :test do
|
12
12
|
gem "rspec", :require => false
|
13
|
-
gem "memory_profiler", :require => false
|
14
13
|
gem "luna-rspec-formatters", :require => false
|
15
14
|
gem "codeclimate-test-reporter", :require => false
|
15
|
+
gem "memory_profiler", :require => false, :platform => :mri
|
16
16
|
gem "rubocop", :github => "bbatsov/rubocop", :branch => :master, :require => false
|
17
|
+
gem "rugged", :require => false, :platform => :mri
|
17
18
|
gem "luna-rubocop-formatters", :require => false
|
18
19
|
gem "benchmark-ips", :require => false
|
19
20
|
gem "rspec-helpers", :require => false
|
@@ -28,12 +29,3 @@ group :development do
|
|
28
29
|
}
|
29
30
|
end
|
30
31
|
end
|
31
|
-
|
32
|
-
group :travis, :optional => true do
|
33
|
-
gem "travis"
|
34
|
-
end
|
35
|
-
|
36
|
-
group :site, :optional => true do
|
37
|
-
gem "jekyll-assets", :github => "jekyll/jekyll-assets"
|
38
|
-
gem "jekyll", :github => "jekyll/jekyll"
|
39
|
-
end
|
data/README.md
CHANGED
@@ -10,76 +10,4 @@
|
|
10
10
|
[coverage]: https://codeclimate.com/github/envygeeks/docker-template/coverage
|
11
11
|
[travis]: https://travis-ci.org/envygeeks/docker-template
|
12
12
|
|
13
|
-
Docker Template is an organization and templating system for Docker images. A way to make your life easier and more organized by having repositories within repositories that share data among multiple sets of images. It is currently used to build all the images for Jekyll and EnvyGeeks.
|
14
|
-
|
15
|
-
<!-- TOC depthFrom:1 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 -->
|
16
|
-
|
17
|
-
- [Docker Template](#docker-template)
|
18
|
-
- [Installation](#installation)
|
19
|
-
- [[Organization](https://github.com/envygeeks/docker-template/tree/master/docs/organization.md)](#organizationhttpsgithubcomenvygeeksdocker-templatetreemasterdocsorganizationmd)
|
20
|
-
- [[Metadata](https://github.com/envygeeks/docker-template/tree/master/docs/metadata.md)](#metadatahttpsgithubcomenvygeeksdocker-templatetreemasterdocsmetadatamd)
|
21
|
-
- [[Normal](https://github.com/envygeeks/docker-template/tree/master/docs/templates/normal.md)](#normalhttpsgithubcomenvygeeksdocker-templatetreemasterdocstemplatesnormalmd)
|
22
|
-
- [[Scratch](https://github.com/envygeeks/docker-template/tree/master/docs/templates/scratch.md)](#scratchhttpsgithubcomenvygeeksdocker-templatetreemasterdocstemplatesscratchmd)
|
23
|
-
- [[Copy/](https://github.com/envygeeks/docker-template/tree/master/docs/copy.md)](#copyhttpsgithubcomenvygeeksdocker-templatetreemasterdocscopymd)
|
24
|
-
- [Commands](#commands)
|
25
|
-
- [Build](#build)
|
26
|
-
- [List](#list)
|
27
|
-
|
28
|
-
<!-- /TOC -->
|
29
|
-
|
30
|
-
## Installation
|
31
|
-
|
32
|
-
```bash
|
33
|
-
sudo gem install docker-template
|
34
|
-
```
|
35
|
-
|
36
|
-
From Gemfile
|
37
|
-
|
38
|
-
```ruby
|
39
|
-
gem "docker-template", {
|
40
|
-
:github => "envygeeks/docker-template"
|
41
|
-
}
|
42
|
-
```
|
43
|
-
|
44
|
-
<!--
|
45
|
-
## [Organization](https://github.com/envygeeks/docker-template/tree/master/docs/organization.md)
|
46
|
-
## [Metadata](https://github.com/envygeeks/docker-template/tree/master/docs/metadata.md)
|
47
|
-
## [Normal](https://github.com/envygeeks/docker-template/tree/master/docs/templates/normal.md)
|
48
|
-
## [Scratch](https://github.com/envygeeks/docker-template/tree/master/docs/templates/scratch.md)
|
49
|
-
## [Copy/](https://github.com/envygeeks/docker-template/tree/master/docs/copy.md)
|
50
|
-
-->
|
51
|
-
|
52
|
-
## Commands
|
53
|
-
|
54
|
-
### Build
|
55
|
-
|
56
|
-
You can build a template by sending either `image`, `user/image`, `image:tag` or `user/image:tag`: `docker-template build image`. Build supports the following arguments:
|
57
|
-
|
58
|
-
```
|
59
|
-
Usage:
|
60
|
-
docker-template build [REPOS [OPTS]]
|
61
|
-
|
62
|
-
Options:
|
63
|
-
[--cache-only], [--no-cache-only] # Only cache your repositories, don't build.
|
64
|
-
[--clean-only], [--no-clean-only] # Only clean your repositories, don't build.
|
65
|
-
[--push-only], [--no-push-only] # Only push your repositories, don't build.
|
66
|
-
[--profile], [--no-profile] # Profile Memory.
|
67
|
-
[--tty], [--no-tty] # Enable TTY Output.
|
68
|
-
[--push], [--no-push] # Push Repo After Building.
|
69
|
-
[--cache], [--no-cache] # Cache your repositories to cache.
|
70
|
-
[--mocking], [--no-mocking] # Disable Certain Actions.
|
71
|
-
[--clean], [--no-clean] # Cleanup your caches.
|
72
|
-
|
73
|
-
Build all (or some) of your repositories
|
74
|
-
```
|
75
|
-
|
76
|
-
***You can send as many repos/images as you like, or you can send none, the lack of any repos/images will result in all of the possible images being built from your repos/ folder. This is good for automated building. NOTE: When building images we sort them, in that scratch images are built first, normal images are built second and aliases are done last, so that if you have dependencies within your dependencies hopefully they will get built first, however this is not always likely if your images rely on another normal image. In that case you might want to send a manual list for us.***
|
77
|
-
|
78
|
-
### List
|
79
|
-
|
80
|
-
You can get a list of the possible images that can be built, an example:
|
81
|
-
|
82
|
-
```
|
83
|
-
envygeeks/alpine:3.3
|
84
|
-
envygeeks/alpine:latest -> envygeeks/alpine:3.3
|
85
|
-
```
|
13
|
+
Docker Template is an organization and templating system for Docker images. A way to make your life easier and more organized by having repositories within repositories that share data among multiple sets of images. It is currently used to build all the images for Jekyll and EnvyGeeks. Please see https://github.com/envygeeks/docker-template/wiki for documentation.
|
data/lib/docker/template.rb
CHANGED
@@ -81,6 +81,20 @@ module Docker
|
|
81
81
|
data._binding
|
82
82
|
)
|
83
83
|
end
|
84
|
+
|
85
|
+
# ------------------------------------------------------------------------
|
86
|
+
|
87
|
+
def _require(what)
|
88
|
+
require what
|
89
|
+
if block_given?
|
90
|
+
yield
|
91
|
+
end
|
92
|
+
|
93
|
+
rescue LoadError
|
94
|
+
$stderr.puts "The gem '#{what}' wasn't found."
|
95
|
+
$stderr.puts "You can install it with `gem install #{what}'"
|
96
|
+
abort "Hope you install it so you can report back."
|
97
|
+
end
|
84
98
|
end
|
85
99
|
end
|
86
100
|
|
data/lib/docker/template/cli.rb
CHANGED
@@ -9,12 +9,15 @@ require "thor"
|
|
9
9
|
module Docker
|
10
10
|
module Template
|
11
11
|
class CLI < Thor
|
12
|
+
autoload :Build, "docker/template/cli/build"
|
13
|
+
autoload :List, "docker/template/cli/list"
|
12
14
|
|
13
15
|
# ----------------------------------------------------------------------
|
14
16
|
# docker-template build [repos [opts]]
|
15
17
|
# ----------------------------------------------------------------------
|
16
18
|
|
17
19
|
desc "build [REPOS [OPTS]]", "Build all (or some) of your repositories"
|
20
|
+
option :diff, :type => :boolean, :desc => "Build only modified repositories."
|
18
21
|
option :cache_only, :type => :boolean, :desc => "Only cache your repositories, don't build."
|
19
22
|
option :clean_only, :type => :boolean, :desc => "Only clean your repositories, don't build."
|
20
23
|
option :push_only, :type => :boolean, :desc => "Only push your repositories, don't build."
|
@@ -28,14 +31,24 @@ module Docker
|
|
28
31
|
# ----------------------------------------------------------------------
|
29
32
|
|
30
33
|
def build(*args)
|
31
|
-
|
32
|
-
Parser.new(args, options).parse.tap { |o| o.map(&:build) } \
|
33
|
-
.uniq(&:name).map(&:clean)
|
34
|
-
end
|
35
|
-
|
34
|
+
Build.new(args, options).start
|
36
35
|
rescue Docker::Template::Error::StandardError => e
|
37
36
|
$stderr.puts Simple::Ansi.red(e.message)
|
38
|
-
exit e.respond_to?(:status) ?
|
37
|
+
exit e.respond_to?(:status) ? \
|
38
|
+
e.status : 1
|
39
|
+
|
40
|
+
rescue Excon::Errors::SocketError
|
41
|
+
$stderr.puts "Unable to connect to your Docker Instance."
|
42
|
+
$stderr.puts "Are you absolutely sure that you have the Docker installed?"
|
43
|
+
abort "Unable to build your images."
|
44
|
+
|
45
|
+
rescue Exception
|
46
|
+
raise unless $ERROR_POSITION
|
47
|
+
$ERROR_POSITION.delete_if do |source|
|
48
|
+
source =~ %r!#{Regexp.escape(
|
49
|
+
__FILE__
|
50
|
+
)}!o
|
51
|
+
end
|
39
52
|
end
|
40
53
|
|
41
54
|
# ----------------------------------------------------------------------
|
@@ -43,83 +56,15 @@ module Docker
|
|
43
56
|
# ----------------------------------------------------------------------
|
44
57
|
|
45
58
|
desc "list [OPTS]", "List all possible builds."
|
46
|
-
option :grep, :type => :boolean, :desc => "Make --only a Regexp search."
|
47
|
-
option :only, :type => :string, :desc => "Only a specific repo."
|
48
59
|
|
49
60
|
# ----------------------------------------------------------------------
|
50
61
|
# rubocop:disable Metrics/AbcSize
|
51
62
|
# ----------------------------------------------------------------------
|
52
63
|
|
53
64
|
def list
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|| (only && repo_s == only) || !only
|
58
|
-
|
59
|
-
$stderr.print repo.to_s
|
60
|
-
$stderr.print " -> ", repo.aliased.to_s, "\n" if repo.alias?
|
61
|
-
$stderr.puts unless repo.alias?
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# ----------------------------------------------------------------------
|
66
|
-
# rubocop:enable Metrics/AbcSize
|
67
|
-
# ----------------------------------------------------------------------
|
68
|
-
|
69
|
-
no_tasks do
|
70
|
-
def only
|
71
|
-
return @only ||= begin
|
72
|
-
if !options.grep?
|
73
|
-
then options[
|
74
|
-
:only
|
75
|
-
]
|
76
|
-
|
77
|
-
elsif options.only?
|
78
|
-
Regexp.new(options[
|
79
|
-
:only
|
80
|
-
])
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# --------------------------------------------------------------------
|
86
|
-
# When a user wishes to profile their builds to see memory being used.
|
87
|
-
# rubocop:disable Lint/RescueException
|
88
|
-
# --------------------------------------------------------------------
|
89
|
-
|
90
|
-
def with_profiling
|
91
|
-
if options.profile?
|
92
|
-
begin
|
93
|
-
require "memory_profiler"
|
94
|
-
MemoryProfiler.report(:top => 10_240) { yield }.pretty_print({\
|
95
|
-
:to_file => "mem.txt"
|
96
|
-
})
|
97
|
-
|
98
|
-
rescue LoadError
|
99
|
-
$stderr.puts "The gem 'memory_profiler' wasn't found."
|
100
|
-
$stderr.puts "You can install it with `gem install memory_profiler'"
|
101
|
-
abort "Hope you install it so you can report back."
|
102
|
-
end
|
103
|
-
|
104
|
-
else
|
105
|
-
yield
|
106
|
-
end
|
107
|
-
|
108
|
-
rescue Excon::Errors::SocketError
|
109
|
-
$stderr.puts "Unable to connect to your Docker Instance."
|
110
|
-
$stderr.puts "Are you absolutely sure that you have the Docker installed?"
|
111
|
-
abort "Unable to build your images."
|
112
|
-
|
113
|
-
rescue Exception
|
114
|
-
raise unless $ERROR_POSITION
|
115
|
-
$ERROR_POSITION.delete_if do |source|
|
116
|
-
source =~ %r!#{Regexp.escape(
|
117
|
-
__FILE__
|
118
|
-
)}!o
|
119
|
-
end
|
120
|
-
|
121
|
-
raise
|
122
|
-
end
|
65
|
+
return $stdout.puts(
|
66
|
+
List.build
|
67
|
+
)
|
123
68
|
end
|
124
69
|
end
|
125
70
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Docker
|
2
|
+
module Template
|
3
|
+
class CLI
|
4
|
+
class Build
|
5
|
+
def initialize(args, opts)
|
6
|
+
@opts = Metadata.new(opts || {})
|
7
|
+
@repos = Parser.new(args, opts || {}).parse
|
8
|
+
@args = args
|
9
|
+
end
|
10
|
+
|
11
|
+
# --------------------------------------------------------------------
|
12
|
+
|
13
|
+
def start
|
14
|
+
_profile do
|
15
|
+
reselect_repos if @opts.diff?
|
16
|
+
@repos.tap { |o| o.map(&:build) }.uniq(&:name).map(
|
17
|
+
&:clean
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# --------------------------------------------------------------------
|
23
|
+
|
24
|
+
def reselect_repos
|
25
|
+
Template._require "rugged" do
|
26
|
+
git = Rugged::Repository.new(".")
|
27
|
+
repos_dir = Template.root.join(@opts.repos_dir)
|
28
|
+
walker = Rugged::Walker.new(git)
|
29
|
+
walker.push(git.last_commit)
|
30
|
+
|
31
|
+
repos = git.last_commit.parents.each_with_object(Set.new) do |parent, set|
|
32
|
+
git.last_commit.diff(parent).each_delta do |delta, file = delta.new_file[:path]|
|
33
|
+
if Pathutil.new(file).expand_path(Template.root).in_path?(repos_dir)
|
34
|
+
set.merge(file.split("/").values_at(
|
35
|
+
1
|
36
|
+
))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
@repos = @repos.select do |repo|
|
42
|
+
repos.include?(
|
43
|
+
repo.name
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# --------------------------------------------------------------------
|
50
|
+
|
51
|
+
private
|
52
|
+
def _profile
|
53
|
+
return yield unless @opts.profile?
|
54
|
+
Template._require "memory_profiler" do
|
55
|
+
profiler = MemoryProfiler.report(:top => 10_240) { yield }
|
56
|
+
profiler.pretty_print({
|
57
|
+
:to_file => "profile.txt"
|
58
|
+
})
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
module Docker
|
2
|
+
module Template
|
3
|
+
class CLI
|
4
|
+
class List
|
5
|
+
def self.build
|
6
|
+
return (
|
7
|
+
new.build
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
# --------------------------------------------------------------------
|
12
|
+
|
13
|
+
def initialize(images = Parser.new([], {}).parse)
|
14
|
+
@images = images
|
15
|
+
end
|
16
|
+
|
17
|
+
# ------------------------------------------------------------------------
|
18
|
+
|
19
|
+
def build
|
20
|
+
out = ""
|
21
|
+
|
22
|
+
@images.group_by { |image| image.user }.each do |user, images|
|
23
|
+
out += "[user] " + Simple::Ansi.blue(user) + "\n" + repos(
|
24
|
+
user, images
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
out
|
29
|
+
end
|
30
|
+
|
31
|
+
# ------------------------------------------------------------------------
|
32
|
+
|
33
|
+
def repos(user, images)
|
34
|
+
out = ""
|
35
|
+
|
36
|
+
images.group_by { |image| image.name }.each do |name, image|
|
37
|
+
out += " ├─ [repo] " + Simple::Ansi.green(name) + "\n"
|
38
|
+
out += tags(user, name, images)
|
39
|
+
out += remote_aliases(
|
40
|
+
user, name, images
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
out
|
45
|
+
end
|
46
|
+
|
47
|
+
# --------------------------------------------------------------------
|
48
|
+
|
49
|
+
def tags(user, name, images)
|
50
|
+
out = ""
|
51
|
+
|
52
|
+
images.select { |image| image.name == name && image.user == user \
|
53
|
+
&& !image.alias? }.each do |image|
|
54
|
+
|
55
|
+
out += " │ ├─ [tag] " + Simple::Ansi.magenta(image.tag) + "\n"
|
56
|
+
out += aliases(
|
57
|
+
user, name, image.tag, images
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
out
|
62
|
+
end
|
63
|
+
|
64
|
+
# --------------------------------------------------------------------
|
65
|
+
|
66
|
+
def remote_aliases(user, name, images)
|
67
|
+
out = ""
|
68
|
+
|
69
|
+
images.select { |image| aliased_remote?(image) && image.user == user \
|
70
|
+
&& image.name == name }.group_by { |image| image.metadata[:aliases][image.tag] \
|
71
|
+
}.each do |remote, images_|
|
72
|
+
|
73
|
+
out += " │ ├─ [remote] "
|
74
|
+
out += Simple::Ansi.yellow(remote)
|
75
|
+
out += "\n"
|
76
|
+
|
77
|
+
images_.each do |image|
|
78
|
+
out += " │ │ ├─ [alias] "
|
79
|
+
out += Simple::Ansi.yellow(
|
80
|
+
image.tag
|
81
|
+
)
|
82
|
+
|
83
|
+
out += "\n"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
out
|
88
|
+
end
|
89
|
+
|
90
|
+
# --------------------------------------------------------------------
|
91
|
+
|
92
|
+
def aliases(user, name, tag, images, depth: 0)
|
93
|
+
out = ""
|
94
|
+
|
95
|
+
_aliases(user, name, tag, images).each do |alias_|
|
96
|
+
if alias_.name == name
|
97
|
+
name_ = Simple::Ansi.yellow(
|
98
|
+
alias_.tag
|
99
|
+
)
|
100
|
+
|
101
|
+
else
|
102
|
+
name_ = Simple::Ansi.yellow(
|
103
|
+
"#{alias_.name}:#{alias_.tag}"
|
104
|
+
)
|
105
|
+
end
|
106
|
+
|
107
|
+
out += " │ │ #{"│ " * depth}├─ [alias] #{name_}\n"
|
108
|
+
out += aliases(user, name, alias_.tag, images, {
|
109
|
+
:depth => depth + 1
|
110
|
+
})
|
111
|
+
end
|
112
|
+
|
113
|
+
out
|
114
|
+
end
|
115
|
+
|
116
|
+
# --------------------------------------------------------------------
|
117
|
+
|
118
|
+
private
|
119
|
+
def aliased_remote?(image)
|
120
|
+
return image.alias? && !image.aliased
|
121
|
+
end
|
122
|
+
|
123
|
+
# --------------------------------------------------------------------
|
124
|
+
|
125
|
+
private
|
126
|
+
def _aliases(user, name, tag, images)
|
127
|
+
images.select do |image|
|
128
|
+
image.alias? && image.aliased && image.aliased.tag == tag \
|
129
|
+
&& image.aliased.name == name && image.aliased.user \
|
130
|
+
== user
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -73,7 +73,7 @@ module Docker
|
|
73
73
|
# ----------------------------------------------------------------------
|
74
74
|
|
75
75
|
def self.to_repo_hash(val)
|
76
|
-
data = val.split(SPLIT_REGEXP)
|
76
|
+
data = val.to_s.split(SPLIT_REGEXP)
|
77
77
|
|
78
78
|
return "name" => data[0] if data.one?
|
79
79
|
return "name" => data[0], "tag" => data[1] if val =~ COLON_REGEXP && data.size == 2
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docker-template
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordon Bedwell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -128,6 +128,8 @@ files:
|
|
128
128
|
- lib/docker/template/builder.rb
|
129
129
|
- lib/docker/template/cache.rb
|
130
130
|
- lib/docker/template/cli.rb
|
131
|
+
- lib/docker/template/cli/build.rb
|
132
|
+
- lib/docker/template/cli/list.rb
|
131
133
|
- lib/docker/template/error.rb
|
132
134
|
- lib/docker/template/logger.rb
|
133
135
|
- lib/docker/template/metadata.rb
|