docker-template 0.8.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Rakefile +18 -20
- data/bin/docker-template +7 -10
- data/comp/list +7 -10
- data/comp/list.pak +0 -0
- data/lib/docker/template.rb +33 -30
- data/lib/docker/template/auth.rb +72 -0
- data/lib/docker/template/builder.rb +169 -81
- data/lib/docker/template/builder/normal.rb +58 -0
- data/lib/docker/template/builder/rootfs.rb +111 -0
- data/lib/docker/template/builder/scratch.rb +165 -0
- data/lib/docker/template/cache.rb +15 -20
- data/lib/docker/template/cli.rb +77 -20
- data/lib/docker/template/cli/build.rb +23 -8
- data/lib/docker/template/cli/list.rb +10 -10
- data/lib/docker/template/error.rb +12 -43
- data/lib/docker/template/logger.rb +99 -38
- data/lib/docker/template/{metadata.rb → meta.rb} +209 -114
- data/lib/docker/template/notify.rb +55 -12
- data/lib/docker/template/parser.rb +44 -35
- data/lib/docker/template/repo.rb +85 -81
- data/lib/docker/template/version.rb +1 -3
- data/lib/erb/context.rb +5 -8
- data/templates/rootfs/alpine.erb +65 -66
- data/templates/rootfs/ubuntu.erb +71 -42
- metadata +32 -12
- data/lib/docker/template/normal.rb +0 -46
- data/lib/docker/template/rootfs.rb +0 -85
- data/lib/docker/template/scratch.rb +0 -166
- data/shas.yml +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d76a4779cec82a6c13f3be1b64a22bc454f6126
|
4
|
+
data.tar.gz: d0f548b2754f2ba999361a4ce9e6f970dfc69e37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b63c8cfb7fa0f8ebfc6bcebc581fa1d9f1794e71a6f3a5869226d0e254e7e2f88892eefdea66794a0457c23b8f0f35893075d81ca255b694cc551b1648763c5
|
7
|
+
data.tar.gz: 2ccc93f6003d232028ed0541ce8be0515ebdc199d5dbcafe7359ae078089610015e5371100b9cc7fbae71b9265e69fd84ee1079bb37e93c8d864b4e00a54a495
|
data/Gemfile
CHANGED
@@ -9,11 +9,11 @@ gem "rake", :require => false
|
|
9
9
|
gemspec
|
10
10
|
|
11
11
|
group :test do
|
12
|
+
gem "rubocop", :require => false
|
12
13
|
gem "rspec", :require => false
|
13
14
|
gem "luna-rspec-formatters", :require => false
|
14
15
|
gem "codeclimate-test-reporter", :require => false
|
15
16
|
gem "memory_profiler", :require => false, :platform => :mri
|
16
|
-
gem "rubocop", :github => "bbatsov/rubocop", :branch => :master, :require => false
|
17
17
|
gem "rugged", :require => false, :platform => :mri
|
18
18
|
gem "luna-rubocop-formatters", :require => false
|
19
19
|
gem "benchmark-ips", :require => false
|
data/Rakefile
CHANGED
@@ -1,42 +1,41 @@
|
|
1
|
-
# ----------------------------------------------------------------------------
|
2
1
|
# Frozen-string-literal: true
|
3
2
|
# Copyright: 2015 - 2016 Jordon Bedwell - Apache v2.0 License
|
4
3
|
# Encoding: utf-8
|
5
|
-
# ----------------------------------------------------------------------------
|
6
4
|
|
7
5
|
$LOAD_PATH.unshift(File.expand_path(
|
8
6
|
"../lib", __FILE__
|
9
7
|
))
|
10
8
|
|
11
|
-
#
|
9
|
+
# --
|
12
10
|
|
13
11
|
require "simple/ansi"
|
14
12
|
require "rspec/core/rake_task"
|
15
13
|
require "luna/rubocop/rake/task"
|
14
|
+
require "docker/template/cli"
|
16
15
|
require "open3"
|
17
16
|
|
18
|
-
#
|
17
|
+
# --
|
19
18
|
|
20
19
|
task :default => [:spec]
|
21
20
|
RSpec::Core::RakeTask.new :spec
|
22
21
|
task :test => :spec
|
23
22
|
|
24
|
-
#
|
25
|
-
|
23
|
+
# --
|
24
|
+
# TODO: Cleanup and remove this whenever you can.
|
25
|
+
# --
|
26
26
|
module CompList
|
27
27
|
module_function
|
28
28
|
|
29
|
-
#
|
29
|
+
# --
|
30
30
|
# Update the pak file to have all the completions.
|
31
|
-
#
|
32
|
-
|
31
|
+
# --
|
33
32
|
def update(data = get_commands, msgp = data.to_msgpack)
|
34
33
|
pak_file.binwrite(
|
35
34
|
msgp
|
36
35
|
)
|
37
36
|
end
|
38
37
|
|
39
|
-
#
|
38
|
+
# --
|
40
39
|
|
41
40
|
def normalize_command(command)
|
42
41
|
if command.is_a?(Array)
|
@@ -52,10 +51,9 @@ module CompList
|
|
52
51
|
end
|
53
52
|
end
|
54
53
|
|
55
|
-
#
|
54
|
+
# --
|
56
55
|
# Provides the base "_reply" for your auto-complete data output.
|
57
|
-
#
|
58
|
-
|
56
|
+
# --
|
59
57
|
def base(const, skip = %w(help))
|
60
58
|
keys = const.all_commands.keys
|
61
59
|
return "_reply" => normalize_command(keys), "help" => {
|
@@ -63,7 +61,7 @@ module CompList
|
|
63
61
|
}
|
64
62
|
end
|
65
63
|
|
66
|
-
#
|
64
|
+
# --
|
67
65
|
|
68
66
|
def add_opts(out, const)
|
69
67
|
const.all_commands.each do |key, val, command = normalize_command(key)|
|
@@ -92,10 +90,9 @@ module CompList
|
|
92
90
|
out
|
93
91
|
end
|
94
92
|
|
95
|
-
#
|
93
|
+
# --
|
96
94
|
# Recursively pulls out and set's up your commands and opts.
|
97
|
-
#
|
98
|
-
|
95
|
+
# --
|
99
96
|
def get_commands(const = Docker::Template::CLI)
|
100
97
|
out = base(
|
101
98
|
const
|
@@ -113,18 +110,19 @@ module CompList
|
|
113
110
|
)
|
114
111
|
end
|
115
112
|
|
116
|
-
#
|
113
|
+
# --
|
117
114
|
|
118
115
|
def pak_file
|
119
|
-
Pathutil.new("
|
116
|
+
Pathutil.new("comp/list.pak").expand_path.tap(
|
120
117
|
&:touch
|
121
118
|
)
|
122
119
|
end
|
123
120
|
end
|
124
121
|
|
125
|
-
#
|
122
|
+
# --
|
126
123
|
|
127
124
|
namespace :update do
|
125
|
+
desc "Update the completion list."
|
128
126
|
task "comp-list" do
|
129
127
|
require "msgpack"
|
130
128
|
require "docker/template"
|
data/bin/docker-template
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# ----------------------------------------------------------------------------
|
3
2
|
# Frozen-string-literal: true
|
4
3
|
# Copyright: 2015 - 2016 Jordon Bedwell - Apache v2.0 License
|
5
4
|
# Encoding: utf-8
|
6
|
-
# ----------------------------------------------------------------------------
|
7
5
|
|
8
6
|
$LOAD_PATH.unshift(File.expand_path(
|
9
7
|
"../lib", __dir__
|
10
8
|
))
|
11
9
|
|
12
|
-
#
|
10
|
+
# --
|
13
11
|
|
14
12
|
trap :SIGINT do
|
15
13
|
$stderr.puts Simple::Ansi.red(
|
@@ -19,18 +17,17 @@ trap :SIGINT do
|
|
19
17
|
exit
|
20
18
|
end
|
21
19
|
|
22
|
-
#
|
20
|
+
# --
|
23
21
|
|
24
22
|
begin
|
25
|
-
require "docker/template"
|
23
|
+
require "docker/template/cli"
|
26
24
|
rescue LoadError
|
27
|
-
|
25
|
+
# Retry and let it fail if it doesn't work again.
|
26
|
+
%w(bundler/setup docker/template/cli).each do |k|
|
28
27
|
require k
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
32
|
-
# ----------------------------------------------------------------------------
|
33
31
|
# Time to play the game.
|
34
|
-
|
35
|
-
|
36
|
-
Docker::Template::CLI.start
|
32
|
+
Docker::Template::CLI \
|
33
|
+
.start
|
data/comp/list
CHANGED
@@ -1,23 +1,20 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# ----------------------------------------------------------------------------
|
3
2
|
# Frozen-string-literal: true
|
4
3
|
# Copyright: 2016 Jordon Bedwell - MIT License
|
5
|
-
# Encoding: utf-8
|
6
|
-
# ----------------------------------------------------------------------------
|
7
4
|
# rubocop:disable Style/ElseAlignment
|
8
|
-
#
|
5
|
+
# Encoding: utf-8
|
9
6
|
|
10
7
|
ARGV.shift
|
11
8
|
require "pathutil"
|
12
9
|
require "msgpack"
|
13
10
|
|
14
|
-
#
|
11
|
+
# --
|
15
12
|
|
16
13
|
list = MessagePack.unpack(
|
17
14
|
Pathutil.new(__dir__).expand_path.join("list.pak").read
|
18
15
|
)
|
19
16
|
|
20
|
-
#
|
17
|
+
# --
|
21
18
|
|
22
19
|
if ARGV.first == "build"
|
23
20
|
dir = Pathutil.new("repos").expand_path
|
@@ -30,7 +27,7 @@ if ARGV.first == "build"
|
|
30
27
|
end
|
31
28
|
end
|
32
29
|
|
33
|
-
#
|
30
|
+
# --
|
34
31
|
|
35
32
|
def key?(obj, key)
|
36
33
|
obj["_reply"].include?(
|
@@ -38,7 +35,7 @@ def key?(obj, key)
|
|
38
35
|
)
|
39
36
|
end
|
40
37
|
|
41
|
-
#
|
38
|
+
# --
|
42
39
|
|
43
40
|
def contains?(obj, key)
|
44
41
|
result = obj["_reply"].grep(/#{Regexp.escape(
|
@@ -48,13 +45,13 @@ def contains?(obj, key)
|
|
48
45
|
!result.empty?
|
49
46
|
end
|
50
47
|
|
51
|
-
#
|
48
|
+
# --
|
52
49
|
|
53
50
|
def opt?(key)
|
54
51
|
key =~ /\A-{1,2}/
|
55
52
|
end
|
56
53
|
|
57
|
-
#
|
54
|
+
# --
|
58
55
|
|
59
56
|
if ARGV.empty?
|
60
57
|
$stdout.puts list["_reply"].join(
|
data/comp/list.pak
CHANGED
Binary file
|
data/lib/docker/template.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
# ----------------------------------------------------------------------------
|
2
1
|
# Frozen-string-literal: true
|
3
2
|
# Copyright: 2015 - 2016 Jordon Bedwell - Apache v2.0 License
|
4
3
|
# Encoding: utf-8
|
5
|
-
# ----------------------------------------------------------------------------
|
6
4
|
|
7
5
|
require "docker"
|
8
6
|
require "extras/all"
|
@@ -12,35 +10,28 @@ require "simple/ansi"
|
|
12
10
|
require "pathutil"
|
13
11
|
require "set"
|
14
12
|
|
15
|
-
#
|
13
|
+
# --
|
16
14
|
|
17
15
|
Excon.defaults[ :read_timeout] = 1440
|
18
16
|
Excon.defaults[:write_timeout] = 1440
|
19
17
|
|
20
|
-
#
|
18
|
+
# --
|
21
19
|
|
22
20
|
module Docker
|
23
21
|
module Template
|
24
22
|
module_function
|
25
23
|
|
26
|
-
#
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
autoload :Scratch, "docker/template/scratch"
|
38
|
-
autoload :Rootfs, "docker/template/rootfs"
|
39
|
-
autoload :Cache, "docker/template/cache"
|
40
|
-
autoload :Alias, "docker/template/alias"
|
41
|
-
autoload :CLI, "docker/template/cli"
|
42
|
-
|
43
|
-
# ------------------------------------------------------------------------
|
24
|
+
# --
|
25
|
+
|
26
|
+
def project?
|
27
|
+
dir = root.join("docker")
|
28
|
+
any = Builder.all.dup.keep_if(&:projects_allowed?)
|
29
|
+
any = any.map(&:files).reduce(&:|).any? { |file| root.join(file).file? }
|
30
|
+
return true if any && root.join(Meta.opts_file(:force => \
|
31
|
+
:project)).file?
|
32
|
+
end
|
33
|
+
|
34
|
+
# --
|
44
35
|
|
45
36
|
def root
|
46
37
|
@root ||= begin
|
@@ -48,7 +39,7 @@ module Docker
|
|
48
39
|
end
|
49
40
|
end
|
50
41
|
|
51
|
-
#
|
42
|
+
# --
|
52
43
|
|
53
44
|
def gem_root
|
54
45
|
@gem_root ||= begin
|
@@ -58,7 +49,7 @@ module Docker
|
|
58
49
|
end
|
59
50
|
end
|
60
51
|
|
61
|
-
#
|
52
|
+
# --
|
62
53
|
|
63
54
|
def template_root
|
64
55
|
@template_root ||= begin
|
@@ -66,10 +57,10 @@ module Docker
|
|
66
57
|
end
|
67
58
|
end
|
68
59
|
|
69
|
-
#
|
60
|
+
# --
|
70
61
|
# Pull a `template` from the `template_root` to parse it's data.
|
71
|
-
# TODO: Rename this
|
72
|
-
#
|
62
|
+
# TODO: Rename this to get_template!
|
63
|
+
# --
|
73
64
|
|
74
65
|
def get(name, data = {})
|
75
66
|
data = ERB::Context.new(data)
|
@@ -82,7 +73,7 @@ module Docker
|
|
82
73
|
)
|
83
74
|
end
|
84
75
|
|
85
|
-
#
|
76
|
+
# --
|
86
77
|
|
87
78
|
def _require(what)
|
88
79
|
require what
|
@@ -98,12 +89,24 @@ module Docker
|
|
98
89
|
end
|
99
90
|
end
|
100
91
|
|
101
|
-
#
|
92
|
+
# --
|
102
93
|
# Trick extras into merging array's into array's for us so users can inherit.
|
103
|
-
#
|
94
|
+
# --
|
104
95
|
|
105
96
|
class Array
|
106
97
|
def deep_merge(new_)
|
107
98
|
self | new_
|
108
99
|
end
|
109
100
|
end
|
101
|
+
|
102
|
+
# --
|
103
|
+
|
104
|
+
require "docker/template/error"
|
105
|
+
require "docker/template/cache"
|
106
|
+
require "docker/template/notify"
|
107
|
+
require "docker/template/builder"
|
108
|
+
require "docker/template/logger"
|
109
|
+
require "docker/template/parser"
|
110
|
+
require "docker/template/repo"
|
111
|
+
require "docker/template/meta"
|
112
|
+
require "docker/template/auth"
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2015 - 2016 Jordon Bedwell - Apache v2.0 License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
module Docker
|
6
|
+
module Template
|
7
|
+
module Auth
|
8
|
+
module_function
|
9
|
+
|
10
|
+
# --
|
11
|
+
|
12
|
+
DEFAULT_SERVER = "https://index.docker.io/v1/"
|
13
|
+
|
14
|
+
# --
|
15
|
+
|
16
|
+
def auth_with_env?
|
17
|
+
(
|
18
|
+
ENV.key?("DOCKER_USERNAME") && \
|
19
|
+
ENV.key?("DOCKER_PASSWORD") && \
|
20
|
+
ENV.key?("DOCKER_EMAIL")
|
21
|
+
) || \
|
22
|
+
(
|
23
|
+
ENV.key?("bamboo_dockerUsername") && \
|
24
|
+
ENV.key?("bamboo_dockerPassword") && \
|
25
|
+
ENV.key?("bambo_dockerEmail")
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
# --
|
30
|
+
|
31
|
+
def hub
|
32
|
+
return auth_from_env if auth_with_env?
|
33
|
+
|
34
|
+
auth_from_config
|
35
|
+
rescue Docker::Error::AuthenticationError
|
36
|
+
raise Error::UnsuccessfulAuth
|
37
|
+
end
|
38
|
+
|
39
|
+
# --
|
40
|
+
|
41
|
+
def auth_from_env
|
42
|
+
Docker.authenticate!({
|
43
|
+
"username" => ENV["DOCKER_USERNAME"] || ENV["bamboo_dockerUsername"],
|
44
|
+
"serveraddress" => ENV["DOCKER_SERVER"] || ENV["bamboo_dockerServer"] || DEFAULT_SERVER,
|
45
|
+
"password" => ENV["DOCKER_PASSWORD"] || ENV["bamboo_dockerPassword"],
|
46
|
+
"email" => ENV["DOCKER_EMAIL"] || ENV["bamboo_dockerEmail"]
|
47
|
+
})
|
48
|
+
end
|
49
|
+
|
50
|
+
# --
|
51
|
+
|
52
|
+
def auth_from_config
|
53
|
+
credentials = Pathutil.new("~/.docker/config.json")
|
54
|
+
credentials = credentials.expand_path.read_json
|
55
|
+
|
56
|
+
unless credentials.empty?
|
57
|
+
credentials["auths"].each do |server, info|
|
58
|
+
username, password = Base64.decode64(info["auth"])
|
59
|
+
.split(":", 2)
|
60
|
+
|
61
|
+
Docker.authenticate!({
|
62
|
+
"username" => username,
|
63
|
+
"serveraddress" => server,
|
64
|
+
"email" => info["email"],
|
65
|
+
"password" => password
|
66
|
+
})
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -1,44 +1,43 @@
|
|
1
|
-
# ----------------------------------------------------------------------------
|
2
1
|
# Frozen-string-literal: true
|
3
2
|
# Copyright: 2015 - 2016 Jordon Bedwell - Apache v2.0 License
|
4
3
|
# Encoding: utf-8
|
5
|
-
# ----------------------------------------------------------------------------
|
6
4
|
|
7
5
|
module Docker
|
8
6
|
module Template
|
9
7
|
class Builder
|
10
8
|
extend Forwardable::Extended
|
11
9
|
|
12
|
-
#
|
10
|
+
# --
|
13
11
|
|
14
12
|
attr_reader :repo
|
15
13
|
attr_reader :context
|
14
|
+
attr_reader :copy
|
16
15
|
attr_reader :img
|
17
16
|
|
18
|
-
#
|
17
|
+
# --
|
19
18
|
|
20
19
|
ALIAS_SETUP = [:cache_context]
|
21
|
-
SETUP = [:setup_context, :copy_global, :
|
22
|
-
:copy_group, :copy_tag, :copy_cleanup, :build_context,
|
20
|
+
SETUP = [:setup_context, :copy_global, :copy_project,
|
21
|
+
:copy_all, :copy_group, :copy_tag, :copy_cleanup, :copy_git, :build_context,
|
23
22
|
:verify_context, :cache_context].freeze
|
24
23
|
|
25
|
-
#
|
24
|
+
# --
|
26
25
|
|
27
26
|
def initialize(repo)
|
28
27
|
@repo = repo
|
29
28
|
end
|
30
29
|
|
31
|
-
#
|
30
|
+
# --
|
32
31
|
# Checks to see if this repository is an alias. This happens when the
|
33
32
|
# user has alised data inside of their configuration file. At this point
|
34
33
|
# we will not only copy the parent's data but the aliased data.
|
35
|
-
#
|
34
|
+
# --
|
36
35
|
|
37
36
|
def alias?
|
38
37
|
!@repo.complex_alias? && @repo.alias? && !rootfs?
|
39
38
|
end
|
40
39
|
|
41
|
-
#
|
40
|
+
# --
|
42
41
|
|
43
42
|
def rootfs?
|
44
43
|
is_a?(
|
@@ -46,21 +45,21 @@ module Docker
|
|
46
45
|
)
|
47
46
|
end
|
48
47
|
|
49
|
-
#
|
48
|
+
# --
|
50
49
|
|
51
50
|
def normal?
|
52
51
|
@repo.type == "normal" \
|
53
52
|
&& !rootfs?
|
54
53
|
end
|
55
54
|
|
56
|
-
#
|
55
|
+
# --
|
57
56
|
|
58
57
|
def scratch?
|
59
58
|
@repo.type == "scratch" \
|
60
59
|
&& !rootfs?
|
61
60
|
end
|
62
61
|
|
63
|
-
#
|
62
|
+
# --
|
64
63
|
|
65
64
|
def aliased_img
|
66
65
|
if alias?
|
@@ -77,16 +76,15 @@ module Docker
|
|
77
76
|
end
|
78
77
|
end
|
79
78
|
|
80
|
-
#
|
79
|
+
# --
|
81
80
|
|
82
81
|
def push
|
83
82
|
return if rootfs? || !@repo.pushable?
|
84
|
-
Notify.push self
|
85
|
-
auth!
|
86
83
|
|
84
|
+
Notify.push(self); Auth.hub
|
87
85
|
img = @img || Image.get(@repo.to_s)
|
88
|
-
img.push nil, :repo_tag => \
|
89
|
-
|
86
|
+
img.push nil, :repo_tag => @repo.to_s, \
|
87
|
+
&Logger.new(repo).method(:api)
|
90
88
|
|
91
89
|
rescue Docker::Error::NotFoundError
|
92
90
|
$stderr.puts Simple::Ansi.red(
|
@@ -94,7 +92,7 @@ module Docker
|
|
94
92
|
)
|
95
93
|
end
|
96
94
|
|
97
|
-
#
|
95
|
+
# --
|
98
96
|
|
99
97
|
def build
|
100
98
|
Simple::Ansi.clear if @repo.buildable?
|
@@ -102,11 +100,9 @@ module Docker
|
|
102
100
|
setup
|
103
101
|
|
104
102
|
if @repo.buildable?
|
105
|
-
Notify.build(@repo,
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
chdir_build
|
103
|
+
then Notify.build(@repo, :rootfs => rootfs?) do
|
104
|
+
chdir_build
|
105
|
+
end
|
110
106
|
end
|
111
107
|
|
112
108
|
push
|
@@ -121,11 +117,11 @@ module Docker
|
|
121
117
|
end
|
122
118
|
end
|
123
119
|
|
124
|
-
#
|
120
|
+
# --
|
125
121
|
# This method is a default reference. It is called when the image is
|
126
122
|
# done building or when there is an error and we need to clean up some
|
127
123
|
# stuff before exiting, use it... please.
|
128
|
-
#
|
124
|
+
# --
|
129
125
|
|
130
126
|
def teardown(*_)
|
131
127
|
$stderr.puts Ansi.red(
|
@@ -133,7 +129,25 @@ module Docker
|
|
133
129
|
)
|
134
130
|
end
|
135
131
|
|
136
|
-
#
|
132
|
+
# --
|
133
|
+
# The prebuild happens when a user has "setup_context", which typically
|
134
|
+
# only happens with scratch, which will prebuild it's rootfs image so
|
135
|
+
# it can get to building it's actual image.
|
136
|
+
# --
|
137
|
+
|
138
|
+
def setup
|
139
|
+
unless respond_to?(:setup_context, true)
|
140
|
+
raise Error::NoSetupContext
|
141
|
+
end
|
142
|
+
|
143
|
+
SETUP.map do |val|
|
144
|
+
if respond_to?(val, true)
|
145
|
+
send(val)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# --
|
137
151
|
|
138
152
|
private
|
139
153
|
def build_alias
|
@@ -161,26 +175,7 @@ module Docker
|
|
161
175
|
push
|
162
176
|
end
|
163
177
|
|
164
|
-
#
|
165
|
-
# The prebuild happens when a user has "setup_context", which typically
|
166
|
-
# only happens with scratch, which will prebuild it's rootfs image so
|
167
|
-
# it can get to building it's actual image.
|
168
|
-
# ----------------------------------------------------------------------
|
169
|
-
|
170
|
-
private
|
171
|
-
def setup
|
172
|
-
unless respond_to?(:setup_context, true)
|
173
|
-
raise Error::NoSetupContext
|
174
|
-
end
|
175
|
-
|
176
|
-
SETUP.map do |val|
|
177
|
-
if respond_to?(val, true)
|
178
|
-
send(val)
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
# ----------------------------------------------------------------------
|
178
|
+
# --
|
184
179
|
|
185
180
|
private
|
186
181
|
def alias_setup
|
@@ -191,19 +186,32 @@ module Docker
|
|
191
186
|
end
|
192
187
|
end
|
193
188
|
|
194
|
-
#
|
189
|
+
# --
|
195
190
|
|
196
191
|
private
|
197
192
|
def chdir_build
|
198
193
|
@context.chdir do
|
199
|
-
logger = Logger.new(
|
200
|
-
opts = {
|
201
|
-
|
202
|
-
|
194
|
+
logger = Logger.new(repo).method(:api)
|
195
|
+
opts = {
|
196
|
+
:force => @repo.meta.force?,
|
197
|
+
:t => @repo.to_s(rootfs: rootfs?),
|
198
|
+
:squash => @repo.meta.squash?,
|
199
|
+
:nocache => @repo.meta.force?
|
200
|
+
}
|
201
|
+
|
202
|
+
if @repo.meta["tty"]
|
203
|
+
$stderr.puts Simple::Ansi.yellow(
|
204
|
+
"TTY not supported: Ignored."
|
205
|
+
)
|
206
|
+
end
|
207
|
+
|
208
|
+
@img = Docker::Image.build_from_dir(".",
|
209
|
+
opts, &logger
|
210
|
+
)
|
203
211
|
end
|
204
212
|
end
|
205
213
|
|
206
|
-
#
|
214
|
+
# --
|
207
215
|
|
208
216
|
private
|
209
217
|
def cache_context
|
@@ -214,16 +222,46 @@ module Docker
|
|
214
222
|
end
|
215
223
|
end
|
216
224
|
|
217
|
-
#
|
225
|
+
# --
|
226
|
+
# Copy any git repositories the user wishes us to copy.
|
227
|
+
# --
|
228
|
+
|
229
|
+
private
|
230
|
+
def copy_git
|
231
|
+
return if rootfs? || !@repo.meta.git?
|
232
|
+
require "rugged"
|
233
|
+
|
234
|
+
@repo.meta[:git].each do |repo|
|
235
|
+
credentials = Rugged::Credentials::SshKey.new({
|
236
|
+
:privatekey => Pathutil.new(repo[:key]).expand_path.to_s,
|
237
|
+
:publickey => Pathutil.new(repo[:pub]).expand_path.to_s,
|
238
|
+
:username => repo[:user]
|
239
|
+
})
|
240
|
+
|
241
|
+
dir = @copy.join(repo[:clone_to])
|
242
|
+
if !dir.exist?
|
243
|
+
$stderr.puts Simple::Ansi.green("Cloning #{repo[:repo]} to #{repo[:clone_to]}.")
|
244
|
+
Rugged::Repository.clone_at(repo[:repo], dir.to_s, {
|
245
|
+
:credentials => credentials
|
246
|
+
})
|
247
|
+
else
|
248
|
+
$stderr.puts Simple::Ansi.yellow(
|
249
|
+
"Skipping #{repo[:repo]}, exists already."
|
250
|
+
)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
# --
|
218
256
|
# The root can have it's own global copy directory shared across all
|
219
257
|
# repos in your repo container dir so this encapsulates those.
|
220
|
-
#
|
258
|
+
# --
|
221
259
|
|
222
260
|
private
|
223
261
|
def copy_global
|
224
262
|
unless rootfs?
|
225
263
|
dir = Template.root.join(
|
226
|
-
@repo.
|
264
|
+
@repo.meta["copy_dir"]
|
227
265
|
)
|
228
266
|
|
229
267
|
if dir.exist?
|
@@ -234,7 +272,26 @@ module Docker
|
|
234
272
|
end
|
235
273
|
end
|
236
274
|
|
237
|
-
#
|
275
|
+
# --
|
276
|
+
|
277
|
+
private
|
278
|
+
def copy_project
|
279
|
+
if Template.project?
|
280
|
+
ignores = repo.meta["project_copy_ignore"].map do |path|
|
281
|
+
Pathutil.new(path).expand_path(
|
282
|
+
Template.root
|
283
|
+
)
|
284
|
+
end
|
285
|
+
|
286
|
+
Template.root.safe_copy(
|
287
|
+
context.join(repo.meta.project_copy_dir), {
|
288
|
+
:root => Template.root, :ignore => ignores
|
289
|
+
}
|
290
|
+
)
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
# --
|
238
295
|
|
239
296
|
private
|
240
297
|
def copy_tag
|
@@ -249,11 +306,11 @@ module Docker
|
|
249
306
|
end
|
250
307
|
end
|
251
308
|
|
252
|
-
#
|
309
|
+
# --
|
253
310
|
|
254
311
|
private
|
255
312
|
def copy_group
|
256
|
-
build_group = @repo.
|
313
|
+
build_group = @repo.meta["tags"][
|
257
314
|
@repo.tag
|
258
315
|
]
|
259
316
|
|
@@ -268,7 +325,7 @@ module Docker
|
|
268
325
|
end
|
269
326
|
end
|
270
327
|
|
271
|
-
#
|
328
|
+
# --
|
272
329
|
|
273
330
|
private
|
274
331
|
def copy_all
|
@@ -283,33 +340,64 @@ module Docker
|
|
283
340
|
end
|
284
341
|
end
|
285
342
|
|
286
|
-
#
|
343
|
+
# --
|
287
344
|
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
345
|
+
rb_delegate :aliased_tag, :to => "repo.meta"
|
346
|
+
rb_delegate :aliased_repo, {
|
347
|
+
:to => :repo, :alias_of => :aliased
|
348
|
+
}
|
292
349
|
|
293
|
-
|
294
|
-
user, pass = Base64.decode64(info["auth"]).split(
|
295
|
-
":", 2
|
296
|
-
)
|
350
|
+
class << self
|
297
351
|
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
352
|
+
# --
|
353
|
+
# REFERENCE METHOD: This is here to let you know we access files.
|
354
|
+
# --
|
355
|
+
|
356
|
+
def files
|
357
|
+
return [
|
358
|
+
#
|
359
|
+
]
|
304
360
|
end
|
305
|
-
end
|
306
361
|
|
307
|
-
|
362
|
+
# --
|
308
363
|
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
364
|
+
def projects_allowed!
|
365
|
+
return @projects_allowed \
|
366
|
+
= true
|
367
|
+
end
|
368
|
+
|
369
|
+
# --
|
370
|
+
|
371
|
+
def projects_allowed?
|
372
|
+
return !!@projects_allowed
|
373
|
+
end
|
374
|
+
|
375
|
+
# --
|
376
|
+
|
377
|
+
def sub?
|
378
|
+
false
|
379
|
+
end
|
380
|
+
|
381
|
+
# --
|
382
|
+
|
383
|
+
def inherited(klass)
|
384
|
+
(@sub_classes ||= []).push(
|
385
|
+
klass
|
386
|
+
)
|
387
|
+
end
|
388
|
+
|
389
|
+
# --
|
390
|
+
|
391
|
+
def all
|
392
|
+
@sub_classes ||= [
|
393
|
+
#
|
394
|
+
]
|
395
|
+
end
|
396
|
+
end
|
313
397
|
end
|
314
398
|
end
|
315
399
|
end
|
400
|
+
|
401
|
+
require "docker/template/builder/rootfs"
|
402
|
+
require "docker/template/builder/scratch"
|
403
|
+
require "docker/template/builder/normal"
|