dockerfilemerge 0.4.6 → 0.5.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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/dockerfilemerge.rb +186 -139
- metadata +36 -32
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ba02da0dcfd5851c24454cc8ac42dba746fb21a26d7c50d034df9b8f71aec990
|
4
|
+
data.tar.gz: 6c1c0a06b24f33be70c6ab21a89f1b1a335080f063419b24f29349e9b2e4f5f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e44b601db031e44d620a160abc8dbfeb847da73e9af61c5cfd977cc2eba780b1eb3694f31a03c8ee47c562ff6f8959e5d8e474be377faf0defd1d1a65d53eb6
|
7
|
+
data.tar.gz: 2529519b5920e59cb9631738b762554855f1611a958932766f8b5438f97fa16256b249f9fd49a26c473881a3018a0c9b30bb46bbee4a88be5d794d6549db226e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/dockerfilemerge.rb
CHANGED
@@ -5,184 +5,231 @@
|
|
5
5
|
require 'lineparser'
|
6
6
|
require 'rxfhelper'
|
7
7
|
|
8
|
-
|
8
|
+
module Dockerfile
|
9
|
+
|
10
|
+
class Merge
|
9
11
|
|
10
|
-
|
12
|
+
attr_reader :to_s
|
11
13
|
|
12
|
-
|
14
|
+
def initialize(raw_s)
|
13
15
|
|
14
|
-
|
16
|
+
s, type = RXFHelper.read(raw_s)
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
18
|
+
patterns = [
|
19
|
+
[:root, /^\s*ADD\s+(?<add>.*)/, :add],
|
20
|
+
[:root, /^\s*COPY\s+(?<copy>.*)/, :copy],
|
21
|
+
[:root, /FROM\s+(?<from>.*)/, :from],
|
22
|
+
[:root, /INCLUDE\s*(?<path>.*)?/, :include],
|
23
|
+
[:include, /(?<path>.*)/, :dockerfile],
|
24
|
+
[:root, /MAINTAINER (?<name>.*)/, :maintainer],
|
25
|
+
[:root, /RUN (?<command>.*)/, :run],
|
26
|
+
[:root, /-\/[^\/]+\/(?:\[[^\]]+\])?/, :del],
|
27
|
+
[:all, /#/, :comment]
|
28
|
+
]
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
s.sub!(/\A# Dockermergefile/,'# Dockerfile')
|
31
|
+
a = LineParser.new(patterns, ignore_blank_lines: false).parse s
|
32
|
+
maintainer = a.grep /MAINTAINER/
|
33
|
+
|
34
|
+
if maintainer.empty? then
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
from = a.assoc :include
|
37
|
+
a.insert(a.index(from) + 1, [:maintainer, {},['MAINTAINER unknown']])
|
38
|
+
end
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
lines = []
|
41
|
+
|
42
|
+
if type == :url then
|
43
|
+
lines << '# Generated ' + Time.now.strftime("%a %d-%b-%Y %-I:%M%P")
|
44
|
+
lines << '# source: ' + raw_s
|
45
|
+
end
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
line = r.first
|
48
|
-
|
49
|
-
case label
|
47
|
+
a.each do |label, h, r, c| # h=hash, r=remaining, c=children
|
50
48
|
|
49
|
+
line = r.first
|
51
50
|
|
52
|
-
|
51
|
+
case label
|
52
|
+
|
53
|
+
|
54
|
+
when :add
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
lines << line
|
57
|
+
lines << ' ' + r[1..-1].join("\n ").rstrip if r.length > 1
|
58
|
+
|
59
|
+
when :comment
|
58
60
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
lines << line
|
62
|
+
lines << '' if r.length > 1
|
63
|
+
|
64
|
+
|
65
|
+
when :copy
|
64
66
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
67
|
+
lines << line
|
68
|
+
lines << ' ' + r[1..-1].join("\n ").rstrip if r.length > 1
|
69
|
+
|
70
|
+
when :from
|
69
71
|
|
70
|
-
|
71
|
-
|
72
|
-
|
72
|
+
lines << line
|
73
|
+
lines << '' if r.length > 1
|
74
|
+
|
73
75
|
|
74
|
-
|
76
|
+
when :include
|
75
77
|
|
76
|
-
|
77
|
-
|
78
|
-
|
78
|
+
h[:path].length > 0 ? merge_file(lines, h[:path]) :
|
79
|
+
c.each {|source| merge_file lines, source[1][:path] }
|
80
|
+
lines << '' if r.length > 1
|
79
81
|
|
80
|
-
|
82
|
+
when :maintainer
|
81
83
|
|
82
|
-
|
84
|
+
maintainers = lines.grep(/MAINTAINER/)
|
83
85
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
86
|
+
if maintainers.length > 0 then
|
87
|
+
|
88
|
+
while maintainers.length > 1 do
|
89
|
+
i = lines.rindex maintainers.pop
|
90
|
+
lines.delete_at i
|
91
|
+
maintainers = lines.grep(/MAINTAINER/)
|
92
|
+
end
|
91
93
|
|
92
|
-
|
94
|
+
i = lines.index maintainers[0]
|
93
95
|
|
94
|
-
|
95
|
-
|
96
|
+
lines[i] = line unless line[/MAINTAINER unknown/]
|
97
|
+
elsif maintainers.empty?
|
96
98
|
|
97
|
-
|
98
|
-
|
99
|
-
|
99
|
+
from = lines.grep /^ *FROM\b/
|
100
|
+
i = lines.index from[0]
|
101
|
+
lines.insert(i+1, line) unless line[/MAINTAINER unknown/]
|
100
102
|
|
101
|
-
|
102
|
-
|
103
|
+
end
|
104
|
+
|
103
105
|
|
104
|
-
|
105
|
-
|
106
|
+
|
107
|
+
when :run
|
106
108
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
109
|
+
lines << line
|
110
|
+
lines << ' ' + r[1..-1].join("\n ").rstrip if r.length > 1
|
111
|
+
|
112
|
+
|
113
|
+
when :del
|
112
114
|
|
113
|
-
|
115
|
+
exp, filter = line.match(/-\/([^\/]+)\/(\[[^\]]+\])?/).captures
|
114
116
|
|
115
|
-
|
117
|
+
name = if filter then
|
116
118
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
119
|
+
case filter[1..-2]
|
120
|
+
when'0..-2'
|
121
|
+
:singlify_last
|
122
|
+
when '1..-1'
|
123
|
+
:singlify_first
|
124
|
+
else
|
125
|
+
puts 'unrecognised selector'
|
126
|
+
end
|
122
127
|
else
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
method(name).call(lines, exp) if name.is_a? Symbol
|
128
|
+
:delete_all
|
129
|
+
end
|
130
|
+
|
131
|
+
method(name).call(lines, exp) if name.is_a? Symbol
|
132
|
+
|
133
|
+
end
|
130
134
|
|
131
|
-
end
|
135
|
+
end
|
136
|
+
|
137
|
+
singlify_first lines, /^\s*FROM /
|
138
|
+
singlify_last lines, /^\s*CMD /
|
139
|
+
s = lines.join("\n")
|
140
|
+
|
141
|
+
rm_sources = /rm -rf \/var\/lib\/apt\/lists\/\*/
|
142
|
+
rm_sources_count = s.scan(rm_sources).length
|
132
143
|
|
144
|
+
if rm_sources_count > 1 then
|
145
|
+
(rm_sources_count - 1).times { remove_command(rm_sources,s) }
|
146
|
+
end
|
147
|
+
|
148
|
+
@to_s = s
|
133
149
|
end
|
134
150
|
|
135
|
-
|
136
|
-
|
137
|
-
|
151
|
+
private
|
152
|
+
|
153
|
+
def delete_all(lines, regex)
|
154
|
+
lines.reject! {|x| x[regex]}
|
155
|
+
end
|
156
|
+
|
157
|
+
def merge_file(lines, path)
|
138
158
|
|
139
|
-
|
140
|
-
|
159
|
+
raw_buffer, type = RXFHelper.read(path)
|
160
|
+
buffer = raw_buffer[/^\bINCLUDE\b/] ? \
|
161
|
+
DockerfileMerge.new(raw_buffer).to_s : raw_buffer
|
162
|
+
|
163
|
+
rows = buffer.lines.map(&:chomp)
|
164
|
+
lines << "\n\n# copied from " + path if type == :url
|
165
|
+
rows.grep(/^# Pull /).each {|x| rows.delete x}
|
166
|
+
|
167
|
+
lines.concat rows
|
168
|
+
end
|
141
169
|
|
142
|
-
|
143
|
-
(
|
170
|
+
def remove_command(regex, s)
|
171
|
+
s.sub!(/(?:\\?\s*&&\s+)#{regex}\s*$|(?:RUN\s+|\s*&&\s+||&&\s*\\\s*)?#{regex}(?:\s+\\)? */,'')
|
144
172
|
end
|
145
173
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
174
|
+
# removes any matching lines after the 1st matching line
|
175
|
+
#
|
176
|
+
def singlify_first(lines, raw_regex)
|
177
|
+
|
178
|
+
regex = raw_regex.is_a?(Regexp) ? raw_regex : Regexp.new(raw_regex)
|
179
|
+
i = 0
|
180
|
+
lines.reject! {|x| found = x[regex]; i += 1 if found; i > 1 and found }
|
181
|
+
end
|
154
182
|
|
155
|
-
|
183
|
+
# removes any matching lines before the last matching line
|
184
|
+
#
|
185
|
+
def singlify_last(lines, raw_regex)
|
186
|
+
|
187
|
+
regex = raw_regex.is_a?(Regexp) ? raw_regex : Regexp.new(raw_regex)
|
188
|
+
lines.grep(regex)[0..-2].each {|x| lines.delete x}
|
189
|
+
end
|
190
|
+
end
|
156
191
|
|
157
|
-
|
158
|
-
buffer = raw_buffer[/^\bINCLUDE\b/] ? \
|
159
|
-
DockerfileMerge.new(raw_buffer).to_s : raw_buffer
|
192
|
+
class Split
|
160
193
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
def remove_command(regex, s)
|
169
|
-
s.sub!(/(?:\\?\s*&&\s+)#{regex}\s*$|(?:RUN\s+|\s*&&\s+||&&\s*\\\s*)?#{regex}(?:\s+\\)? */,'')
|
170
|
-
end
|
171
|
-
|
172
|
-
# removes any matching lines after the 1st matching line
|
173
|
-
#
|
174
|
-
def singlify_first(lines, raw_regex)
|
194
|
+
def initialize(xmlfile='dockerfiles.xml', repository: 'myrepo',
|
195
|
+
filepath: '.' , base_image: nil)
|
196
|
+
|
197
|
+
@repository, @filepath, @xmlfile = repository, filepath, xmlfile
|
198
|
+
@base_image = base_image
|
199
|
+
|
200
|
+
end
|
175
201
|
|
176
|
-
|
177
|
-
|
178
|
-
|
202
|
+
def make()
|
203
|
+
|
204
|
+
s = File.read(@xmlfile)
|
205
|
+
doc = Rexle.new(s)
|
206
|
+
|
207
|
+
a = doc.root.xpath('//dockerfile')
|
208
|
+
a.each.with_index do |entry, i|
|
209
|
+
|
210
|
+
filename = entry.attributes[:id]
|
211
|
+
path2 = File.join(@filepath, filename)
|
212
|
+
FileUtils.mkdir path2
|
213
|
+
File.write File.join(path2, 'Dockerfile'), entry.texts.join.strip\
|
214
|
+
.sub(/<base_image>/, @base_image)
|
215
|
+
|
216
|
+
s = "sudo docker build -t %s/%s ." % [@repository, filename]
|
217
|
+
File.write build_path=File.join(path2, 'build.sh'), s
|
218
|
+
FileUtils.chmod_R 0755, build_path
|
219
|
+
|
220
|
+
if i == 0 then
|
221
|
+
|
222
|
+
builds = "sudo build.sh && " + a[1..-1].map \
|
223
|
+
{|x| "cd ../%s && sudo build.sh" % x.attributes[:id] }.join(" && ")
|
224
|
+
|
225
|
+
File.write buildall_path=File.join(path2, 'buildall.sh'), builds
|
226
|
+
FileUtils.chmod_R 0755, buildall_path
|
227
|
+
end
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
|
232
|
+
end
|
179
233
|
end
|
180
|
-
|
181
|
-
|
182
|
-
#
|
183
|
-
def singlify_last(lines, raw_regex)
|
184
|
-
|
185
|
-
regex = raw_regex.is_a?(Regexp) ? raw_regex : Regexp.new(raw_regex)
|
186
|
-
lines.grep(regex)[0..-2].each {|x| lines.delete x}
|
187
|
-
end
|
188
|
-
end
|
234
|
+
|
235
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dockerfilemerge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -10,28 +10,32 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
13
|
+
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTkwNDA2MjEwMjM3WhcN
|
15
|
+
MjAwNDA1MjEwMjM3WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
|
16
|
+
cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQCaooNV
|
17
|
+
fX7aN+ifLKHmeFeuIJ+nd/sVFa2jGcyKtJWaBYu+aaVm75siS6paZEdAo7zw3NKt
|
18
|
+
CmQwK9nS7TCrbNa0VY07G0RwTM5JJPN6MIBVhZiO+sDG7i19ylqoBzLRjH8Xk62e
|
19
|
+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JzRQH
|
34
|
+
Rwfa6N2cxBitxIs+cca9gMgAMZtQvbWg4LgwqOjio8cKbW6HKc63PXEkIP7/sC5i
|
35
|
+
zfrmvNAOB2nUhx8eE6ES7atIe0Fq1AFX8hX3guVTzqPW9J71heSwNzc7oxQW8u93
|
36
|
+
nByUcsaYHMsVhsqOgbKoqjA5
|
33
37
|
-----END CERTIFICATE-----
|
34
|
-
date:
|
38
|
+
date: 2019-04-06 00:00:00.000000000 Z
|
35
39
|
dependencies:
|
36
40
|
- !ruby/object:Gem::Dependency
|
37
41
|
name: lineparser
|
@@ -42,7 +46,7 @@ dependencies:
|
|
42
46
|
version: '0.1'
|
43
47
|
- - ">="
|
44
48
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.1.
|
49
|
+
version: 0.1.19
|
46
50
|
type: :runtime
|
47
51
|
prerelease: false
|
48
52
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -52,29 +56,29 @@ dependencies:
|
|
52
56
|
version: '0.1'
|
53
57
|
- - ">="
|
54
58
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.1.
|
59
|
+
version: 0.1.19
|
56
60
|
- !ruby/object:Gem::Dependency
|
57
61
|
name: rxfhelper
|
58
62
|
requirement: !ruby/object:Gem::Requirement
|
59
63
|
requirements:
|
60
64
|
- - "~>"
|
61
65
|
- !ruby/object:Gem::Version
|
62
|
-
version: '0.
|
66
|
+
version: '0.9'
|
63
67
|
- - ">="
|
64
68
|
- !ruby/object:Gem::Version
|
65
|
-
version: 0.
|
69
|
+
version: 0.9.4
|
66
70
|
type: :runtime
|
67
71
|
prerelease: false
|
68
72
|
version_requirements: !ruby/object:Gem::Requirement
|
69
73
|
requirements:
|
70
74
|
- - "~>"
|
71
75
|
- !ruby/object:Gem::Version
|
72
|
-
version: '0.
|
76
|
+
version: '0.9'
|
73
77
|
- - ">="
|
74
78
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
79
|
+
version: 0.9.4
|
76
80
|
description:
|
77
|
-
email: james@
|
81
|
+
email: james@jamesrobertson.eu
|
78
82
|
executables: []
|
79
83
|
extensions: []
|
80
84
|
extra_rdoc_files: []
|
@@ -99,9 +103,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
103
|
- !ruby/object:Gem::Version
|
100
104
|
version: '0'
|
101
105
|
requirements: []
|
102
|
-
|
103
|
-
rubygems_version: 2.4.8
|
106
|
+
rubygems_version: 3.0.1
|
104
107
|
signing_key:
|
105
108
|
specification_version: 4
|
106
|
-
summary: Merge 2 or more Dockerfiles into 1 Dockerfile
|
109
|
+
summary: Merge 2 or more Dockerfiles into 1 Dockerfile, or split Dockerfiles apart
|
110
|
+
from an XML file
|
107
111
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|