docker_core 0.0.4 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/docker_core.rb +126 -5
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f70d7fa0c2f973490e37183f8b2af082d3ae23c01182982030806442da8b057
|
4
|
+
data.tar.gz: 2d079bfee65ce10d1d73fab1565841aa6f46337891a0057c6af1dbcc1e9978f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d3326c261ce7ebb72226eba403c5e46a1d1a500eda84c530a368c868758717763ed51d1744b3f8cb6b03dd1321105d5fa2296b2c0ef2851d0b59afcbe0c0ed3
|
7
|
+
data.tar.gz: 38fd0d39ac645253844533f1f80c2a95c82efaa8822e0d9a3d88a6b539b2f7eb2809311b292cf9c37fa661beed9edd4d4ce6b004291c8483ddad237b33cac939
|
data/lib/docker_core.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require('fileutils')
|
2
|
+
require('net/http')
|
3
|
+
require('json')
|
4
|
+
require('zlib')
|
5
|
+
require('rubygems/package')
|
2
6
|
|
3
7
|
module DockerCore
|
4
8
|
COLOR_CODE = { error: 31, info: 32, warn: 33 }
|
9
|
+
ARCH_SUFFIX = { x86: '386', x86_64: 'amd64', armhf: 'armv6', aarch64: 'arm64' }
|
5
10
|
|
6
11
|
# @param [String] text
|
7
12
|
# @param [Integer] code
|
@@ -23,9 +28,9 @@ module DockerCore
|
|
23
28
|
# @param [Array] argumets
|
24
29
|
def self.execute(title, run, *argumets)
|
25
30
|
code = self::COLOR_CODE[:warn]
|
26
|
-
self.echo("
|
31
|
+
self.echo("> #{title}", code)
|
27
32
|
run.call(*argumets)
|
28
|
-
self.echo("
|
33
|
+
self.echo("< #{title}", code)
|
29
34
|
end
|
30
35
|
|
31
36
|
# @param [String] command
|
@@ -56,16 +61,132 @@ module DockerCore
|
|
56
61
|
self.run("adduser --system --disabled-password --no-create-home --ingroup=core --gecos=core --shell=/bin/bash --uid=#{uid} core")
|
57
62
|
end
|
58
63
|
|
59
|
-
# @param [Array] arguments
|
64
|
+
# @param [Array<String>] arguments
|
65
|
+
def self.chown(*arguments)
|
66
|
+
arguments.each do |list|
|
67
|
+
FileUtils.chown_R('core', 'core', list)
|
68
|
+
end
|
69
|
+
return
|
70
|
+
end
|
71
|
+
|
72
|
+
# @param [Array<String>] arguments
|
60
73
|
def self.mkdir(*arguments)
|
61
74
|
arguments.each do |list|
|
62
75
|
FileUtils.mkdir_p(list)
|
63
|
-
FileUtils.chown_R('core', 'core', list)
|
64
76
|
end
|
77
|
+
self.chown(*arguments)
|
65
78
|
end
|
66
79
|
|
67
80
|
# @param [String] value
|
68
81
|
def self.to_boolean(value)
|
69
82
|
return %w[true yes on].include?(value.strip.downcase)
|
70
83
|
end
|
84
|
+
|
85
|
+
# @param [String] stdout
|
86
|
+
# @param [String] stderr
|
87
|
+
def self.link_log(stdout = '', stderr = '')
|
88
|
+
if '' != stdout
|
89
|
+
File.symlink('/dev/stdout', stdout)
|
90
|
+
end
|
91
|
+
|
92
|
+
if '' != stderr
|
93
|
+
File.symlink('/dev/stderr', stderr)
|
94
|
+
end
|
95
|
+
return
|
96
|
+
end
|
97
|
+
|
98
|
+
# @param [Array<String>] arguments
|
99
|
+
def self.clear_path(*arguments)
|
100
|
+
arguments.each do |list|
|
101
|
+
FileUtils.rm_rf(list)
|
102
|
+
end
|
103
|
+
|
104
|
+
self.mkdir(*arguments)
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.arch_suffix
|
108
|
+
arch = "#{`apk --print-arch`}".strip
|
109
|
+
return ARCH_SUFFIX.fetch(arch.to_sym, arch)
|
110
|
+
end
|
111
|
+
|
112
|
+
# @param [String] repository
|
113
|
+
def self.github_latest_version(repository)
|
114
|
+
body = Net::HTTP.get(URI("https://api.github.com/repos/#{repository}/releases/latest"))
|
115
|
+
return JSON.parse(body)['tag_name']
|
116
|
+
end
|
117
|
+
|
118
|
+
# @param [String] uri
|
119
|
+
# @param [Integer] max_redirect
|
120
|
+
def self.uri_resolve(uri, max_redirect = 10)
|
121
|
+
response = Net::HTTP.get_response(URI.parse(uri))
|
122
|
+
|
123
|
+
if false == response.is_a?(Net::HTTPRedirection)
|
124
|
+
return uri
|
125
|
+
end
|
126
|
+
|
127
|
+
max_redirect = max_redirect - 1
|
128
|
+
|
129
|
+
if 0 == max_redirect
|
130
|
+
raise('maximum redirect reached')
|
131
|
+
else return self.uri_resolve(response['location'], max_redirect)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# @param [String] uri
|
136
|
+
# @param [String] file
|
137
|
+
def self.download_file(uri, file)
|
138
|
+
uri = self.uri_resolve(uri)
|
139
|
+
content = Net::HTTP.get(URI(uri))
|
140
|
+
return File.binwrite(file, content)
|
141
|
+
end
|
142
|
+
|
143
|
+
# @param [String] file
|
144
|
+
# @param [String] path
|
145
|
+
def self.ungzip(file, path)
|
146
|
+
longlink = '././@LongLink'
|
147
|
+
|
148
|
+
# @type [Gem::Package::TarReader] tar
|
149
|
+
Gem::Package::TarReader.new(Zlib::GzipReader.open(file)) do |tar|
|
150
|
+
target = nil
|
151
|
+
tar.rewind
|
152
|
+
|
153
|
+
tar.each do |entry|
|
154
|
+
name = entry.full_name
|
155
|
+
|
156
|
+
if name == longlink
|
157
|
+
target = File.join(path, "#{entry.read}".strip)
|
158
|
+
next
|
159
|
+
end
|
160
|
+
|
161
|
+
target ||= File.join(path, name)
|
162
|
+
|
163
|
+
# @type [Gem::Package::TarHeader] header
|
164
|
+
header = entry.header
|
165
|
+
typeflag = header.typeflag
|
166
|
+
end_slash = name.end_with?('/')
|
167
|
+
|
168
|
+
if entry.directory? || ('' == typeflag && end_slash)
|
169
|
+
if File.file?(target)
|
170
|
+
File.delete(target)
|
171
|
+
end
|
172
|
+
|
173
|
+
FileUtils.mkdir_p(target, mode: header.mode)
|
174
|
+
elsif entry.file? || ('' == typeflag && !end_slash)
|
175
|
+
if File.directory?(target)
|
176
|
+
FileUtils.rm_rf(target)
|
177
|
+
end
|
178
|
+
|
179
|
+
FileUtils.mkdir_p(File.dirname(target))
|
180
|
+
File.binwrite(target, entry.read)
|
181
|
+
FileUtils.chmod(header.mode, target)
|
182
|
+
elsif '2' == typeflag #Symlink!
|
183
|
+
File.symlink(header.linkname, target)
|
184
|
+
else raise("Unkown tar entry: #{name} type: #{typeflag}.")
|
185
|
+
end
|
186
|
+
|
187
|
+
target = nil
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
71
192
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docker_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- agrozyme
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fileutils
|
@@ -25,7 +25,21 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: zlib
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
@@ -63,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
77
|
- !ruby/object:Gem::Version
|
64
78
|
version: '0'
|
65
79
|
requirements: []
|
66
|
-
rubygems_version: 3.
|
80
|
+
rubygems_version: 3.1.6
|
67
81
|
signing_key:
|
68
82
|
specification_version: 4
|
69
83
|
summary: some functions for docker build / run
|