docker_core 0.0.2 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/docker_core.rb +138 -2
  3. metadata +76 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13a32a2bacf84047b2df2e2ca47493766966eecd7fe7e9b51be41503f8194083
4
- data.tar.gz: 522bb5802bc990afb8964ebb5019df41e04ca435bafa2b3c95967ae9a5519d6e
3
+ metadata.gz: 18a1b927ec2c709078daec960fad7bd08f003333be2e76f7367c33aa24511c23
4
+ data.tar.gz: a9020d2876c4bf326e40cdee982f88e658a870b5f2f0472e74820d1ed74c1f3d
5
5
  SHA512:
6
- metadata.gz: 4a8bebc27b7b37e42c89251654a168ce1599f4717aac3189a40df14ba8762f14173c351ea176cd2e79512f2f86a1cac9ae82f2d4826b44b43cdad1a81b676ba8
7
- data.tar.gz: f80a04fa8b6e126bdb2e881d405268ffd6bc8f4418db2584c6eb4ba0fc4dfde52f0979905b9816fe218b41d414d2df6dc365c4f990504d597d15322109d71d18
6
+ metadata.gz: e0c4455fea8ace38ffd9bd7843143cafd6d9e8c48de8e3e61d04ea75ecd035142ecb68f09dd4f1fe4c0ea5ecc8fb1ffd64396f69734b5fe24160cafed3cfacc6
7
+ data.tar.gz: '02852c9ea649dce1b521d927fd28f2e31438646955b6d88e81e6fc1fe89b2f931c00dcf329ea9b36226ddf1aeed367a7e8122d70524ca81e90901638bd541bc5'
data/lib/docker_core.rb CHANGED
@@ -1,5 +1,12 @@
1
+ require('fileutils')
2
+ require('net/http')
3
+ require('json')
4
+ require('zlib')
5
+ require('rubygems/package')
6
+
1
7
  module DockerCore
2
8
  COLOR_CODE = { error: 31, info: 32, warn: 33 }
9
+ ARCH_SUFFIX = { x86: '386', x86_64: 'amd64', armhf: 'armv6', aarch64: 'arm64' }
3
10
 
4
11
  # @param [String] text
5
12
  # @param [Integer] code
@@ -21,9 +28,9 @@ module DockerCore
21
28
  # @param [Array] argumets
22
29
  def self.execute(title, run, *argumets)
23
30
  code = self::COLOR_CODE[:warn]
24
- self.echo(">> #{title}", code)
31
+ self.echo("> #{title}", code)
25
32
  run.call(*argumets)
26
- self.echo("<< #{title}", code)
33
+ self.echo("< #{title}", code)
27
34
  end
28
35
 
29
36
  # @param [String] command
@@ -53,4 +60,133 @@ module DockerCore
53
60
  self.run("addgroup --system --gid=#{gid} core")
54
61
  self.run("adduser --system --disabled-password --no-create-home --ingroup=core --gecos=core --shell=/bin/bash --uid=#{uid} core")
55
62
  end
63
+
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
73
+ def self.mkdir(*arguments)
74
+ arguments.each do |list|
75
+ FileUtils.mkdir_p(list)
76
+ end
77
+ self.chown(*arguments)
78
+ end
79
+
80
+ # @param [String] value
81
+ def self.to_boolean(value)
82
+ return %w[true yes on].include?(value.strip.downcase)
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, 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
+
56
192
  end
metadata CHANGED
@@ -1,15 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.7
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-01 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2021-07-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fileutils
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
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: net/http
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubygems/package
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: zlib
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
13
83
  description:
14
84
  email:
15
85
  executables: []
@@ -17,7 +87,7 @@ extensions: []
17
87
  extra_rdoc_files: []
18
88
  files:
19
89
  - lib/docker_core.rb
20
- homepage:
90
+ homepage: https://gitlab.com/agrozyme-package/ruby/docker_core
21
91
  licenses: []
22
92
  metadata: {}
23
93
  post_install_message:
@@ -28,14 +98,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
28
98
  requirements:
29
99
  - - ">="
30
100
  - !ruby/object:Gem::Version
31
- version: '0'
101
+ version: 2.5.0
32
102
  required_rubygems_version: !ruby/object:Gem::Requirement
33
103
  requirements:
34
104
  - - ">="
35
105
  - !ruby/object:Gem::Version
36
106
  version: '0'
37
107
  requirements: []
38
- rubygems_version: 3.2.15
108
+ rubygems_version: 3.1.6
39
109
  signing_key:
40
110
  specification_version: 4
41
111
  summary: some functions for docker build / run