docker-template 0.8.0 → 0.10.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.
@@ -1,85 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- # Frozen-string-literal: true
3
- # Copyright: 2015 - 2016 Jordon Bedwell - Apache v2.0 License
4
- # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
-
7
- module Docker
8
- module Template
9
- class Rootfs < Builder
10
- extend Forwardable::Extended
11
-
12
- # ----------------------------------------------------------------------
13
-
14
- def data
15
- Template.get(:rootfs, {
16
- :rootfs_base_img => @repo.metadata["rootfs_base_img"]
17
- })
18
- end
19
-
20
- # ----------------------------------------------------------------------
21
-
22
- def builder_data
23
- tpl = "rootfs/#{@repo.metadata.rootfs_template}"
24
- erb = @repo.root.join("rootfs.erb")
25
-
26
- Template.get(
27
- erb.file?? erb : tpl, {
28
- :metadata => @repo.metadata
29
- }
30
- )
31
- end
32
-
33
- # ----------------------------------------------------------------------
34
- # During a simple copy you store all the data (including rootfs) data
35
- # as a single unit, this helps us clean up data that is known to be for
36
- # just the rootfs image and remove it so it doesn't impact.
37
- # ----------------------------------------------------------------------
38
-
39
- def simple_cleanup(dir)
40
- file = dir.join("usr/local/bin/mkimg")
41
-
42
- if file.exist?
43
- then file.delete
44
- end
45
- end
46
-
47
- # ----------------------------------------------------------------------
48
-
49
- def teardown(img: true)
50
- @context.rmtree if @context && @context.directory?
51
- @img.delete "force" => true if @img && img \
52
- rescue nil
53
- end
54
-
55
- # ----------------------------------------------------------------------
56
-
57
- private
58
- def setup_context
59
- @context = @repo.tmpdir("rootfs")
60
- @copy = @context.join(@repo.metadata["copy_dir"])
61
- @context.join("Dockerfile").write(data)
62
-
63
- @copy.join("usr/local/bin").mkdir_p
64
- @copy.join("usr/local/bin/mkimg").write(builder_data)
65
- @copy.join("usr/local/bin/mkimg").chmod(0755)
66
- copy_rootfs
67
- end
68
-
69
- # ----------------------------------------------------------------------
70
-
71
- private
72
- def copy_rootfs
73
- dir = @repo.copy_dir(
74
- "rootfs"
75
- )
76
-
77
- if dir.exist?
78
- @repo.copy_dir("rootfs").safe_copy(@copy, {
79
- :root => Template.root
80
- })
81
- end
82
- end
83
- end
84
- end
85
- end
@@ -1,166 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- # Frozen-string-literal: true
3
- # Copyright: 2015 - 2016 Jordon Bedwell - Apache v2.0 License
4
- # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
-
7
- module Docker
8
- module Template
9
- class Scratch < Builder
10
- attr_reader :rootfs
11
-
12
- # ----------------------------------------------------------------------
13
-
14
- def initialize(*args)
15
- super; @rootfs = Rootfs.new(
16
- repo
17
- )
18
- end
19
-
20
- # ----------------------------------------------------------------------
21
-
22
- def data
23
- Template.get(:scratch, {
24
- :entrypoint => @repo.metadata.entry,
25
- :maintainer => @repo.metadata.maintainer,
26
- :tar_gz => @tar_gz.basename
27
- })
28
- end
29
-
30
- # ----------------------------------------------------------------------
31
-
32
- def teardown(img: false)
33
- @copy.rm_rf if @copy
34
- @context.rm_rf if @context
35
- @tar_gz.rm_rf if @tar_gz
36
-
37
- if @img && img
38
- then @img.delete({
39
- "force" => true
40
- })
41
- end
42
- rescue Docker::Error::NotFoundError
43
- nil
44
- end
45
-
46
- # ----------------------------------------------------------------------
47
-
48
- private
49
- def setup_context
50
- @context = @repo.tmpdir
51
- @tar_gz = @repo.tmpfile "archive", ".tar.gz", root: @context
52
- @copy = @repo.tmpdir "copy"
53
- copy_dockerfile
54
- end
55
-
56
- # ----------------------------------------------------------------------
57
-
58
- private
59
- def copy_dockerfile
60
- data = self.data % @tar_gz.basename
61
- dockerfile = @context.join("Dockerfile")
62
- dockerfile.write(data)
63
- end
64
-
65
- # ----------------------------------------------------------------------
66
-
67
- def copy_cleanup
68
- @rootfs.simple_cleanup(
69
- @copy
70
- )
71
- end
72
-
73
- # ----------------------------------------------------------------------
74
-
75
- def verify_context
76
- if @repo.buildable? && @tar_gz.zero?
77
- raise Error::InvalidTargzFile, @tar_gz
78
- end
79
- end
80
-
81
- # ----------------------------------------------------------------------
82
-
83
- private
84
- def build_context
85
- return unless @repo.buildable?
86
- @rootfs.build
87
-
88
- img = Container.create(create_args)
89
- img.start(start_args).attach(logger_opts, &Logger.new.method(logger_type))
90
- status = img.json["State"]["ExitCode"]
91
-
92
- if status != 0
93
- raise Error::BadExitStatus, status
94
- end
95
- ensure
96
- @rootfs.teardown
97
-
98
- if img
99
- then img.tap(&:stop).delete({
100
- "force" => true
101
- })
102
- end
103
- end
104
-
105
- # ----------------------------------------------------------------------
106
-
107
- private
108
- def logger_type
109
- @repo.metadata["tty"] ? :tty : :simple
110
- end
111
-
112
- # ----------------------------------------------------------------------
113
-
114
- private
115
- def logger_opts
116
- return {
117
- :tty => @repo.metadata["tty"], :stdout => true, :stderr => true
118
- }
119
- end
120
-
121
- # ----------------------------------------------------------------------
122
-
123
- private
124
- def create_args
125
- name = ["rootfs", @repo.name, @repo.tag, "image"].join("-")
126
- env = @repo.to_env(:tar_gz => @tar_gz, :copy_dir => @copy)
127
-
128
- return {
129
- "Env" => env.to_a,
130
- "Tty" => @repo.metadata["tty"],
131
- "Image" => @rootfs.img.id,
132
- "Name" => name,
133
-
134
- "HostConfig" => {
135
- "Binds" => [
136
- "#{@copy}:#{@copy}", "#{@tar_gz}:#{@tar_gz}"
137
- ]
138
- },
139
-
140
- "Volumes" => {
141
- @copy.to_s => {
142
- "source" => @copy.to_s,
143
- "destination" => @copy.to_s
144
- },
145
-
146
- @tar_gz.to_s => {
147
- "source" => @tar_gz.to_s,
148
- "destination" => @tar_gz.to_s
149
- }
150
- }
151
- }
152
- end
153
-
154
- # ----------------------------------------------------------------------
155
-
156
- private
157
- def start_args
158
- {
159
- # "Binds" => [
160
- # "#{@copy}:#{@copy}", "#{@tar_gz}:#{@tar_gz}"
161
- # ]
162
- }
163
- end
164
- end
165
- end
166
- end
data/shas.yml DELETED
@@ -1,11 +0,0 @@
1
- alpine:
2
- apk_tools:
3
- 3.3: { package: apk-tools-static-2.6.5-r1.apk, sha: 03162d70e6d42eea77624a8da76d69e665ca19aa834361c3652414f111884636 }
4
- 3.2: { package: apk-tools-static-2.6.3-r0.apk, sha: ee5f42e06731c7447ce8fae99116a637f261e24f67826ca81dbe60ffbdb5c40e }
5
-
6
- apk_keys:
7
- 3.3: { package: alpine-keys-1.1-r0.apk, sha: bd1f365f1dbda97e02fceb86fe4ff7e220f31ecc9debfd2a0c43764b45d31d0e }
8
- 3.2: { package: alpine-keys-1.1-r0.apk, sha: 26e9296d789fd4cae7392a067bed480b502d4302bcb7289d699af42c100622eb }
9
-
10
- ubuntu:
11
- signing_key_sha: ""