docker-template 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +30 -4
- data/LICENSE +1 -1
- data/README.md +79 -14
- data/Rakefile +115 -38
- data/bin/docker-template +24 -10
- data/comp/bin +9 -0
- data/comp/list +83 -0
- data/comp/list.pak +0 -0
- data/lib/docker/template.rb +47 -61
- data/lib/docker/template/builder.rb +302 -0
- data/lib/docker/template/cache.rb +71 -0
- data/lib/docker/template/cli.rb +125 -0
- data/lib/docker/template/error.rb +120 -11
- data/lib/docker/template/logger.rb +128 -0
- data/lib/docker/template/metadata.rb +566 -103
- data/lib/docker/template/normal.rb +46 -0
- data/lib/docker/template/notify.rb +44 -0
- data/lib/docker/template/parser.rb +48 -38
- data/lib/docker/template/repo.rb +131 -97
- data/lib/docker/template/rootfs.rb +51 -41
- data/lib/docker/template/scratch.rb +96 -66
- data/lib/docker/template/version.rb +4 -2
- data/lib/erb/context.rb +29 -0
- data/shas.yml +11 -0
- data/templates/rootfs.erb +5 -0
- data/templates/rootfs/alpine.erb +71 -0
- data/templates/rootfs/ubuntu.erb +76 -0
- data/{lib/docker/template/templates → templates}/scratch.erb +0 -1
- metadata +64 -50
- data/lib/docker/template/alias.rb +0 -28
- data/lib/docker/template/ansi.rb +0 -85
- data/lib/docker/template/auth.rb +0 -25
- data/lib/docker/template/common.rb +0 -130
- data/lib/docker/template/config.rb +0 -80
- data/lib/docker/template/error/bad_exit_status.rb +0 -17
- data/lib/docker/template/error/bad_repo_name.rb +0 -15
- data/lib/docker/template/error/invalid_repo_type.rb +0 -16
- data/lib/docker/template/error/invalid_targz_file.rb +0 -15
- data/lib/docker/template/error/no_rootfs_copy_dir.rb +0 -15
- data/lib/docker/template/error/no_rootfs_mkimg.rb +0 -15
- data/lib/docker/template/error/no_setup_context_found.rb +0 -15
- data/lib/docker/template/error/not_implemented.rb +0 -15
- data/lib/docker/template/error/repo_not_found.rb +0 -16
- data/lib/docker/template/interface.rb +0 -118
- data/lib/docker/template/patches.rb +0 -9
- data/lib/docker/template/patches/array.rb +0 -11
- data/lib/docker/template/patches/hash.rb +0 -71
- data/lib/docker/template/patches/object.rb +0 -9
- data/lib/docker/template/patches/pathname.rb +0 -46
- data/lib/docker/template/patches/string.rb +0 -9
- data/lib/docker/template/routable.rb +0 -28
- data/lib/docker/template/simple.rb +0 -49
- data/lib/docker/template/stream.rb +0 -63
- data/lib/docker/template/templates/rootfs.erb +0 -8
- data/lib/docker/template/util.rb +0 -54
- data/lib/docker/template/util/copy.rb +0 -77
- data/lib/docker/template/util/data.rb +0 -26
@@ -1,80 +0,0 @@
|
|
1
|
-
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2015 Jordon Bedwell - Apache v2.0 License
|
3
|
-
# Encoding: utf-8
|
4
|
-
|
5
|
-
require "json"
|
6
|
-
require "yaml"
|
7
|
-
|
8
|
-
module Docker
|
9
|
-
module Template
|
10
|
-
|
11
|
-
# Configuration is a global version of meatadata, where anything
|
12
|
-
# that can be set on configuration can be optimized and stored globally
|
13
|
-
# in a opts.{json,yml} file in the current working directory.
|
14
|
-
|
15
|
-
class Config
|
16
|
-
extend Forwardable
|
17
|
-
|
18
|
-
def_delegator :@config, :keys
|
19
|
-
def_delegator :@config, :to_h
|
20
|
-
def_delegator :@config, :to_enum
|
21
|
-
def_delegator :@config, :key?, :has_default?
|
22
|
-
def_delegator :@config, :has_key?
|
23
|
-
def_delegator :@config, :key?
|
24
|
-
def_delegator :@config, :each
|
25
|
-
def_delegator :@config, :[]
|
26
|
-
|
27
|
-
DEFAULTS = {
|
28
|
-
"type" => "simple",
|
29
|
-
"user" => "envygeeks",
|
30
|
-
"local_prefix" => "local",
|
31
|
-
"rootfs_base_img" => "envygeeks/ubuntu:tiny",
|
32
|
-
"maintainer" => "Jordon Bedwell <jordon@envygeeks.io>",
|
33
|
-
"dockerhub_copy" => false,
|
34
|
-
"repos_dir" => "repos",
|
35
|
-
"copy_dir" => "copy",
|
36
|
-
"tag" => "latest",
|
37
|
-
|
38
|
-
"env" => { "tag" => {}, "type" => {}, "all" => nil },
|
39
|
-
"pkgs" => { "tag" => {}, "type" => {}, "all" => nil },
|
40
|
-
"entries" => { "tag" => {}, "type" => {}, "all" => nil },
|
41
|
-
"releases" => { "tag" => {}, "type" => {}, "all" => nil },
|
42
|
-
"versions" => { "tag" => {}, "type" => {}, "all" => nil },
|
43
|
-
"aliases" => {},
|
44
|
-
"tags" => {}
|
45
|
-
}.freeze
|
46
|
-
|
47
|
-
EMPTY_DEFAULTS = {
|
48
|
-
"tags" => { "latest" => "normal" }
|
49
|
-
}
|
50
|
-
|
51
|
-
#
|
52
|
-
|
53
|
-
def initialize
|
54
|
-
@config = DEFAULTS.deep_merge(read_config_from)
|
55
|
-
@config = @config.merge(EMPTY_DEFAULTS) do |_, oval, nval|
|
56
|
-
oval.nil? || oval.empty?? nval : oval
|
57
|
-
end
|
58
|
-
|
59
|
-
@config.freeze
|
60
|
-
end
|
61
|
-
|
62
|
-
# Allows you to read a configuration file from a root and get back
|
63
|
-
# either the parsed data or a blank hash that can be merged the way you
|
64
|
-
# wish to merge it (if you even care to merge it.)
|
65
|
-
|
66
|
-
def read_config_from(dir = Docker::Template.root)
|
67
|
-
file = Dir[dir.join("*.{json,yml}")].first
|
68
|
-
return {} unless file && (file = Pathname.new(file)).file?
|
69
|
-
return JSON.parse(file.read).stringify if file.extname == ".json"
|
70
|
-
YAML.load_file(file).stringify
|
71
|
-
end
|
72
|
-
|
73
|
-
#
|
74
|
-
|
75
|
-
def build_types
|
76
|
-
@build_types ||= %W(simple scratch).freeze
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2015 Jordon Bedwell - Apache v2.0 License
|
3
|
-
# Encoding: utf-8
|
4
|
-
|
5
|
-
module Docker
|
6
|
-
module Template
|
7
|
-
module Error
|
8
|
-
class BadExitStatus < StandardError
|
9
|
-
attr_reader :status
|
10
|
-
|
11
|
-
def initialize(status)
|
12
|
-
super "Got bad exit status #{@status = status}"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2015 Jordon Bedwell - Apache v2.0 License
|
3
|
-
# Encoding: utf-8
|
4
|
-
|
5
|
-
module Docker
|
6
|
-
module Template
|
7
|
-
module Error
|
8
|
-
class BadRepoName < StandardError
|
9
|
-
def initialize(name)
|
10
|
-
super "Only a-z0-9_- are allowed. Invalid repo name: #{name}"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2015 Jordon Bedwell - Apache v2.0 License
|
3
|
-
# Encoding: utf-8
|
4
|
-
|
5
|
-
module Docker
|
6
|
-
module Template
|
7
|
-
module Error
|
8
|
-
class InvalidRepoType < StandardError
|
9
|
-
def initialize(type)
|
10
|
-
build_types = Template.config.build_types.join(", ")
|
11
|
-
super "Uknown repo type given '#{type}' not in '#{build_types}'"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2015 Jordon Bedwell - Apache v2.0 License
|
3
|
-
# Encoding: utf-8
|
4
|
-
|
5
|
-
module Docker
|
6
|
-
module Template
|
7
|
-
module Error
|
8
|
-
class InvalidTargzFile < StandardError
|
9
|
-
def initialize(tar_gz)
|
10
|
-
super "No data was given to the tar.gz file '#{tar_gz.basename}'"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2015 Jordon Bedwell - Apache v2.0 License
|
3
|
-
# Encoding: utf-8
|
4
|
-
|
5
|
-
module Docker
|
6
|
-
module Template
|
7
|
-
module Error
|
8
|
-
class NoRootfsCopyDir < StandardError
|
9
|
-
def initialize
|
10
|
-
super "Unable to find your rootfs copy folder."
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2015 Jordon Bedwell - Apache v2.0 License
|
3
|
-
# Encoding: utf-8
|
4
|
-
|
5
|
-
module Docker
|
6
|
-
module Template
|
7
|
-
module Error
|
8
|
-
class NoRootfsMkimg < StandardError
|
9
|
-
def initialize
|
10
|
-
super "Unable to find a mkimg in your rootfs folder."
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2015 Jordon Bedwell - Apache v2.0 License
|
3
|
-
# Encoding: utf-8
|
4
|
-
|
5
|
-
module Docker
|
6
|
-
module Template
|
7
|
-
module Error
|
8
|
-
class NoSetupContextFound < StandardError
|
9
|
-
def initialize
|
10
|
-
super "No #setup_context found."
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2015 Jordon Bedwell - Apache v2.0 License
|
3
|
-
# Encoding: utf-8
|
4
|
-
|
5
|
-
module Docker
|
6
|
-
module Template
|
7
|
-
module Error
|
8
|
-
class NotImplemented < StandardError
|
9
|
-
def initialize
|
10
|
-
super "The feature is not implemented yet, sorry about that."
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2015 Jordon Bedwell - Apache v2.0 License
|
3
|
-
# Encoding: utf-8
|
4
|
-
|
5
|
-
module Docker
|
6
|
-
module Template
|
7
|
-
module Error
|
8
|
-
class RepoNotFound < StandardError
|
9
|
-
def initialize(repo = nil)
|
10
|
-
ending = repo ? "the repo '#{repo}'" : "your repo folder"
|
11
|
-
super "Unable to find #{ending}"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,118 +0,0 @@
|
|
1
|
-
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2015 Jordon Bedwell - Apache v2.0 License
|
3
|
-
# Encoding: utf-8
|
4
|
-
|
5
|
-
module Docker
|
6
|
-
module Template
|
7
|
-
class Interface
|
8
|
-
def initialize(argv = [])
|
9
|
-
@argv = argv
|
10
|
-
end
|
11
|
-
|
12
|
-
#
|
13
|
-
|
14
|
-
def self.push?
|
15
|
-
ARGV.include?("--push")
|
16
|
-
end
|
17
|
-
|
18
|
-
#
|
19
|
-
|
20
|
-
def run
|
21
|
-
unless only_sync?
|
22
|
-
Parser.new(argv_without_flags).parse.map do |repo|
|
23
|
-
repo.disable_sync! if wants_sync?
|
24
|
-
repo.build
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
sync
|
29
|
-
end
|
30
|
-
|
31
|
-
#
|
32
|
-
|
33
|
-
private
|
34
|
-
def sync
|
35
|
-
return unless wants_sync?
|
36
|
-
Parser.new.parse.each do |repo|
|
37
|
-
next unless repo.syncable?
|
38
|
-
repo.builder.tap(&:sync) \
|
39
|
-
.unlink(sync: false)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
#
|
44
|
-
|
45
|
-
private
|
46
|
-
def argv_without_flags
|
47
|
-
@argv.select do |val|
|
48
|
-
!["--sync", "--push"].include?(val)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
#
|
53
|
-
|
54
|
-
private
|
55
|
-
def only_sync?
|
56
|
-
@argv == [
|
57
|
-
"--sync"
|
58
|
-
]
|
59
|
-
end
|
60
|
-
|
61
|
-
#
|
62
|
-
|
63
|
-
private
|
64
|
-
def wants_sync?
|
65
|
-
@argv.include?("--sync")
|
66
|
-
end
|
67
|
-
|
68
|
-
# Determine whether we are the Docker bin so that we can transform
|
69
|
-
# based on that... for example we will pass on commands to `docker` if
|
70
|
-
# we are running as the `docker` binary in place of `docker`.
|
71
|
-
|
72
|
-
private
|
73
|
-
def self.bin?(bin)
|
74
|
-
!bin ? false : File.basename(bin.to_s) == "docker"
|
75
|
-
end
|
76
|
-
|
77
|
-
# Discover the Docker bin using Ruby. This is a highly unoptimized
|
78
|
-
# method and needs to be reworked because it's pretty trashy shit and
|
79
|
-
# it's just flat out ugly to look at, make it better than it is.
|
80
|
-
|
81
|
-
private
|
82
|
-
def self.discover
|
83
|
-
rtn = bins.find do |path|
|
84
|
-
path.basename.fnmatch?("docker") && path.executable_real?
|
85
|
-
end
|
86
|
-
|
87
|
-
if rtn
|
88
|
-
rtn.to_s
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
#
|
93
|
-
|
94
|
-
private
|
95
|
-
def self.start(zero)
|
96
|
-
return new(ARGV[1..-1]).run if ARGV[0] == "template" && bin?(zero)
|
97
|
-
return new(ARGV).run unless bin?(zero)
|
98
|
-
|
99
|
-
exe = discover
|
100
|
-
exec exe.to_s, *ARGV if exe
|
101
|
-
abort "No Docker."
|
102
|
-
rescue Error::StandardError => error_
|
103
|
-
$stderr.puts Ansi.red(error_.message)
|
104
|
-
$stderr.puts Ansi.red("Aborting your build. Bye and good luck.")
|
105
|
-
exit error_.respond_to?(:status) ? error_.status.to_i : 1
|
106
|
-
end
|
107
|
-
|
108
|
-
#
|
109
|
-
|
110
|
-
private
|
111
|
-
def self.bins
|
112
|
-
ENV["PATH"].split(":").each_with_object(Set.new) do |val, array|
|
113
|
-
array.merge(Pathname.new(val).children) rescue next
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2015 Jordon Bedwell - Apache v2.0 License
|
3
|
-
# Encoding: utf-8
|
4
|
-
|
5
|
-
require "docker/template/patches/object"
|
6
|
-
require "docker/template/patches/array"
|
7
|
-
require "docker/template/patches/pathname"
|
8
|
-
require "docker/template/patches/string"
|
9
|
-
require "docker/template/patches/hash"
|
@@ -1,71 +0,0 @@
|
|
1
|
-
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2015 Jordon Bedwell - Apache v2.0 License
|
3
|
-
# Encoding: utf-8
|
4
|
-
|
5
|
-
class Hash
|
6
|
-
def to_env
|
7
|
-
each_with_object({}) do |(key, val), hsh|
|
8
|
-
val = val.is_a?(Array) ? val.join(" ") : val.to_s
|
9
|
-
key = key.to_s.upcase
|
10
|
-
hsh[key] = val
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
#
|
15
|
-
|
16
|
-
def any_keys?(*keys)
|
17
|
-
keys.map(&method(:key?)).any? do |val|
|
18
|
-
val == true
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
#
|
23
|
-
|
24
|
-
def leftover_keys?(*keys)
|
25
|
-
(self.keys - keys).any?
|
26
|
-
end
|
27
|
-
|
28
|
-
#
|
29
|
-
|
30
|
-
def keys?(*keys)
|
31
|
-
return false unless rtn = true && any?
|
32
|
-
while rtn && key = keys.shift
|
33
|
-
rtn = key?(key) || false
|
34
|
-
end
|
35
|
-
rtn
|
36
|
-
end
|
37
|
-
|
38
|
-
#
|
39
|
-
|
40
|
-
def to_env_ary
|
41
|
-
each_with_object([]) do |(key, val), ary|
|
42
|
-
ary << "#{key}=#{val}"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
#
|
47
|
-
|
48
|
-
def deep_merge(newh)
|
49
|
-
merge(newh) do |_, oval, nval|
|
50
|
-
if oval.is_a?(self.class) && nval.is_a?(self.class)
|
51
|
-
then oval.deep_merge(nval) else nval
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
#
|
57
|
-
|
58
|
-
def stringify
|
59
|
-
each_with_object({}) do |(key, val), hsh|
|
60
|
-
hsh[key.to_s] = val.is_a?(Array) || val.is_a?(Hash) ? val.stringify : val.to_s
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
#
|
65
|
-
|
66
|
-
def stringify_keys
|
67
|
-
each_with_object({}) do |(key, val), hsh|
|
68
|
-
hsh[key.to_s] = val
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|