docker-template 0.20.0 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/docker/template/auth.rb +53 -19
- data/lib/docker/template/builder.rb +2 -1
- data/lib/docker/template/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: deedf46a1eaad06ea4d15d5b8aaa64e18bed91ac1fe60e24ddb7ed2e1a007326
|
4
|
+
data.tar.gz: a8d61651f99f6cb7796003a615d0ad03f75bc0f29a0eb33d1c47a322b244d1cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfca0f56abefaf977c4afb325e1b372de5a73392063f53b7a5d8244263b7bbdfe1c09ba2faa7d76f21811e4ec70f336478ea78db2d3e6dc45e990dc57481ffc4
|
7
|
+
data.tar.gz: 56234609946129e0de47d3dd7607d1b38e4efaab8313e7da31d168ae9ee42da3699276bfbe4bf7446c6ca4fd9fb1c116e64dce0898807e6616c328ac2a40e157
|
data/lib/docker/template/auth.rb
CHANGED
@@ -2,16 +2,20 @@
|
|
2
2
|
# Copyright: 2015 - 2016 Jordon Bedwell - Apache v2.0 License
|
3
3
|
# Encoding: utf-8
|
4
4
|
|
5
|
+
require "open3"
|
6
|
+
require "json"
|
7
|
+
|
5
8
|
module Docker
|
6
9
|
module Template
|
7
|
-
|
8
|
-
module_function
|
9
|
-
|
10
|
-
# --
|
11
|
-
|
10
|
+
class Auth
|
12
11
|
DEFAULT_SERVER = "https://index.docker.io/v1/"
|
12
|
+
def initialize(repo)
|
13
|
+
@repo = repo
|
14
|
+
end
|
13
15
|
|
14
|
-
|
16
|
+
def auth_with_cmd?
|
17
|
+
@repo.user =~ %r!/!
|
18
|
+
end
|
15
19
|
|
16
20
|
def auth_with_env?
|
17
21
|
ENV.key?("DOCKER_USERNAME") && \
|
@@ -20,17 +24,29 @@ module Docker
|
|
20
24
|
end
|
21
25
|
|
22
26
|
# --
|
23
|
-
|
24
|
-
|
25
|
-
return auth_from_env if auth_with_env?
|
26
|
-
|
27
|
+
def auth(skip: nil)
|
28
|
+
return auth_from_cmd if auth_with_cmd? && skip != :cmd
|
29
|
+
return auth_from_env if auth_with_env? && skip != :env
|
27
30
|
auth_from_config
|
31
|
+
|
32
|
+
# Wrap around their error to create ours.
|
28
33
|
rescue Docker::Error::AuthenticationError
|
29
34
|
raise Error::UnsuccessfulAuth
|
35
|
+
# Something went wrong?
|
30
36
|
end
|
31
37
|
|
32
38
|
# --
|
39
|
+
def auth_from_cmd
|
40
|
+
case @repo.user
|
41
|
+
when %r!^gcr\.io/! then auth_from_gcr
|
42
|
+
else
|
43
|
+
auth({
|
44
|
+
skip: :cmd
|
45
|
+
})
|
46
|
+
end
|
47
|
+
end
|
33
48
|
|
49
|
+
# --
|
34
50
|
def auth_from_env
|
35
51
|
Docker.authenticate!({
|
36
52
|
"username" => ENV["DOCKER_USERNAME"],
|
@@ -41,25 +57,43 @@ module Docker
|
|
41
57
|
end
|
42
58
|
|
43
59
|
# --
|
44
|
-
|
45
60
|
def auth_from_config
|
46
|
-
|
47
|
-
|
61
|
+
cred = Pathutil.new("~/.docker/config.json")
|
62
|
+
cred = cred.expand_path.read_json
|
48
63
|
|
49
|
-
unless
|
50
|
-
|
51
|
-
|
52
|
-
.split(":", 2)
|
64
|
+
unless cred.empty?
|
65
|
+
cred["auths"].each do |server, info|
|
66
|
+
next if info.empty?
|
53
67
|
|
68
|
+
user, pass = Base64.decode64(info["auth"]).split(":", 2)
|
54
69
|
Docker.authenticate!({
|
55
|
-
"username" =>
|
70
|
+
"username" => user,
|
56
71
|
"serveraddress" => server,
|
57
72
|
"email" => info["email"],
|
58
|
-
"password" =>
|
73
|
+
"password" => pass
|
59
74
|
})
|
60
75
|
end
|
61
76
|
end
|
62
77
|
end
|
78
|
+
|
79
|
+
private
|
80
|
+
def auth_from_gcr
|
81
|
+
i, o, e, = Open3.popen3("docker-credential-gcr get")
|
82
|
+
server, = @repo.user.split("/", 2)
|
83
|
+
|
84
|
+
i.puts server; i.close
|
85
|
+
val = JSON.parse(o.read.chomp)
|
86
|
+
[o, e].map(&:close)
|
87
|
+
|
88
|
+
if val
|
89
|
+
Docker.authenticate!({
|
90
|
+
"serveraddress" => server,
|
91
|
+
"username" => val["Username"],
|
92
|
+
"email" => "docker-template+opensource@envygeeks.io",
|
93
|
+
"password" => val["Secret"],
|
94
|
+
})
|
95
|
+
end
|
96
|
+
end
|
63
97
|
end
|
64
98
|
end
|
65
99
|
end
|
@@ -81,7 +81,8 @@ module Docker
|
|
81
81
|
def push
|
82
82
|
return if rootfs? || !@repo.pushable?
|
83
83
|
|
84
|
-
Notify.push(self)
|
84
|
+
Notify.push(self)
|
85
|
+
Auth.new(@repo).auth
|
85
86
|
img = @img || Image.get(@repo.to_s)
|
86
87
|
img.push nil, :repo_tag => @repo.to_s, \
|
87
88
|
&Logger.new(repo).method(:api)
|