rumrunner 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -0
- data/README.md +350 -0
- data/lib/rumrunner/docker.rb +7 -0
- data/lib/rumrunner/dsl_definition.rb +2 -2
- data/lib/rumrunner/manifest.rb +45 -30
- data/lib/rumrunner/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: baac9f7a8524654ef3c90b7ffe5ee1d726ce01252d4cb2af7e0dae09d8fec667
|
4
|
+
data.tar.gz: 66e87c6cba9dbe2c7ea7ce09c0fdfd16ca83861bf19e83b6c9139fced65d4435
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b70c6649583bc4f282d3c630c7fd35e307ac66c09ae8b5a70c08349a615418b0b96b9cc84816d9ad371bb0948e25a3dcd3ff575102cde6684db379558cb9b48
|
7
|
+
data.tar.gz: 12f2b6fcc92a637bacc670cc424a1b1d75b57b05c10ce7bc66410c2755777dff2c0f2ff9a555195b90726bd38ed88a9b728545768c3a43aba0055e2fa8c2c9ff
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 Alexander Mancevice
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,350 @@
|
|
1
|
+
[![Rum Runner](https://github.com/amancevice/rumrunner/blob/master/rum-runner.png?raw=true)](https://github.com/amancevice/rumrunner)
|
2
|
+
[![Build Status](https://travis-ci.com/amancevice/rumrunner.svg?branch=master)](https://travis-ci.com/amancevice/rumrunner)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rumrunner.svg)](https://badge.fury.io/rb/rumrunner)
|
4
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/4b56853acc5cbb254125/test_coverage)](https://codeclimate.com/github/amancevice/rumrunner/test_coverage)
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/4b56853acc5cbb254125/maintainability)](https://codeclimate.com/github/amancevice/rumrunner/maintainability)
|
6
|
+
|
7
|
+
<sub>logo by [seenamavaddat.com](http://seenamavaddat.com/)</sub>
|
8
|
+
|
9
|
+
Rum Runner is a Rake-based utility for building multi-stage Dockerfiles.
|
10
|
+
|
11
|
+
Users can pair a multi-stage Dockerfile with a Rumfile that uses a Rake-like DSL to customize each stage's build options and dependencies.
|
12
|
+
|
13
|
+
The `rum` executable allows users to easily invoke builds, shell-into specific stages for debugging, and export artifacts from built containers.
|
14
|
+
|
15
|
+
Rum Runner has the following features:
|
16
|
+
* Fully compatible with Rake
|
17
|
+
* Rake-like DSL/CLI that enable simple annotation and execution of builds
|
18
|
+
* Rumfiles are completely defined in standard Ruby syntax, like Rakefiles
|
19
|
+
* Users can chain Docker build stages with prerequisites
|
20
|
+
* Artifacts can be exported from stages
|
21
|
+
* Shell tasks are automatically provided for every stage
|
22
|
+
* Stage, artifact, and shell, steps can be customized
|
23
|
+
|
24
|
+
**Origins**
|
25
|
+
|
26
|
+
This project was born from using Makefiles to drive multi-stage builds. For the most part this worked really well, but it became a bit of an ordeal to write for more complex projects. This tool is an attempt to recreate that general technique with minimal annotation and limited assumptions.
|
27
|
+
|
28
|
+
View the docs on [rubydoc.info](https://www.rubydoc.info/github/amancevice/rumrunner)
|
29
|
+
|
30
|
+
## Installation
|
31
|
+
|
32
|
+
```bash
|
33
|
+
gem install rumrunner
|
34
|
+
```
|
35
|
+
|
36
|
+
## Quickstart
|
37
|
+
|
38
|
+
If you have a multi-stage Dockerfile in your project and are unsure where to begin, use the `rum init` helper to create a template Rumfile for your project:
|
39
|
+
|
40
|
+
```bash
|
41
|
+
gem install rumrunner
|
42
|
+
rum init > Rumfile
|
43
|
+
rum --tasks
|
44
|
+
```
|
45
|
+
|
46
|
+
The `init` command will parse a Dockerfile in the current directory and output a simple Rumfile with each stage and its dependencies declared.
|
47
|
+
|
48
|
+
## Example
|
49
|
+
|
50
|
+
Imagine a simple multi-stage Dockerfile:
|
51
|
+
|
52
|
+
```Dockerfile
|
53
|
+
FROM ruby AS build
|
54
|
+
# Run build steps here...
|
55
|
+
|
56
|
+
FROM ruby AS test
|
57
|
+
# Run test steps here...
|
58
|
+
|
59
|
+
FROM ruby AS deploy
|
60
|
+
# Run deploy steps here...
|
61
|
+
```
|
62
|
+
|
63
|
+
Create `Rumfile` and describe your build:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
rum :image_name do
|
67
|
+
tag "1.2.3"
|
68
|
+
|
69
|
+
stage :build
|
70
|
+
stage :test => :build
|
71
|
+
stage :deploy => :test
|
72
|
+
|
73
|
+
# rum build => docker build --target build --tag image_name:1.2.3-build .
|
74
|
+
# rum test => docker build --target test --tag image_name:1.2.3-test .
|
75
|
+
# rum deploy => docker build --target deploy --tag image_name:1.2.3-deploy .
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
Run `rum --tasks` to view the installed tasks:
|
80
|
+
|
81
|
+
```bash
|
82
|
+
rum build # Build `build` stage
|
83
|
+
rum clean # Remove any temporary images and products
|
84
|
+
rum clean:build # Remove any temporary images and products through `build` stage
|
85
|
+
rum clean:deploy # Remove any temporary images and products through `deploy` stage
|
86
|
+
rum clean:test # Remove any temporary images and products through `test` stage
|
87
|
+
rum clobber # Remove any generated files
|
88
|
+
rum deploy # Build `deploy` stage
|
89
|
+
rum shell:build[shell] # Shell into `build` stage
|
90
|
+
rum shell:deploy[shell] # Shell into `deploy` stage
|
91
|
+
rum shell:test[shell] # Shell into `test` stage
|
92
|
+
rum test # Build `test` stage
|
93
|
+
```
|
94
|
+
|
95
|
+
## Customize Shells
|
96
|
+
|
97
|
+
By default, all stages have a `:shell` task that can be invoked to build and shell into a container for a stage. By default the container is run as an ephemeral container (`--rm`) in interactive with TTY allocated and a bash shell open.
|
98
|
+
|
99
|
+
Customize the shell for a stage with the `shell` method:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
rum :image_name do
|
103
|
+
stage :dev
|
104
|
+
|
105
|
+
shell :dev do
|
106
|
+
entrypoint "/bin/zsh"
|
107
|
+
rm false
|
108
|
+
volume "#{Dir.pwd}:/var/task/"
|
109
|
+
end
|
110
|
+
|
111
|
+
# rum dev => docker run --entrypoint /bin/zsh --volume $PWD:/var/task/ ...
|
112
|
+
end
|
113
|
+
```
|
114
|
+
|
115
|
+
## Customize Stages
|
116
|
+
|
117
|
+
Stages can be customized with blocks:
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
rum :image_name do
|
121
|
+
tag "1.2.3"
|
122
|
+
|
123
|
+
stage :build
|
124
|
+
|
125
|
+
stage :test => :build
|
126
|
+
|
127
|
+
stage :deploy => :test do
|
128
|
+
build_arg :AWS_ACCESS_KEY_ID
|
129
|
+
build_arg :AWS_SECRET_ACCESS_KEY
|
130
|
+
build_arg :AWS_DEFAULT_REGION => "us-east-1"
|
131
|
+
label :Fizz
|
132
|
+
end
|
133
|
+
end
|
134
|
+
```
|
135
|
+
|
136
|
+
Methods invoked inside the stage block are interpreted as options for the eventual `docker build` command.
|
137
|
+
|
138
|
+
## Export Artifacts
|
139
|
+
|
140
|
+
Use the `artifact` method to specify an artifact to be exported from the image.
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
rum :image_name do
|
144
|
+
stage :build
|
145
|
+
|
146
|
+
artifact "package.zip" => :build
|
147
|
+
end
|
148
|
+
```
|
149
|
+
|
150
|
+
By default the container simply `cat`s the file from the container to the local file system, but more complex exports can be defined:
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
rum :image_name do
|
154
|
+
stage :build
|
155
|
+
|
156
|
+
artifact "package.zip" => :build do
|
157
|
+
workdir "/var/task/"
|
158
|
+
cmd %w[zip -r - .]
|
159
|
+
end
|
160
|
+
end
|
161
|
+
```
|
162
|
+
|
163
|
+
Methods invoked inside the artifact block are interpreted as options for the eventual `docker run` command.
|
164
|
+
|
165
|
+
## Default Task
|
166
|
+
|
167
|
+
Every `rum` declaration has a default task associated with it so that simply executing `rum` on the command line does something.
|
168
|
+
|
169
|
+
In the most simple case, the default task simply builds the image:
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
rum :image_name
|
173
|
+
# rum => docker build --tag image_name .
|
174
|
+
```
|
175
|
+
|
176
|
+
Use the `default` method inside the main block to set a default task or tasks:
|
177
|
+
|
178
|
+
```ruby
|
179
|
+
rum :image_name do
|
180
|
+
stage :build
|
181
|
+
stage :plan => :build
|
182
|
+
|
183
|
+
artifact "package.zip" => :build
|
184
|
+
|
185
|
+
default ["package.zip", :plan]
|
186
|
+
end
|
187
|
+
# rum => docker build --target build ...
|
188
|
+
# docker run ... > package.zip
|
189
|
+
# docker build --target plan ...
|
190
|
+
```
|
191
|
+
## Shared ENV variables
|
192
|
+
|
193
|
+
The `env` method can be invoked in the `rum` block to declare a value that will be passed to all stages/artifacts/shells. For stages, the value will be passed using the `--build-arg` option; for artifacts and shells, the `--env` option.
|
194
|
+
|
195
|
+
```ruby
|
196
|
+
rum :image_name do
|
197
|
+
env :FIZZ => :BUZZ
|
198
|
+
|
199
|
+
stage :build
|
200
|
+
|
201
|
+
# rum build => docker build --build-arg FIZZ=BUZZ ...
|
202
|
+
end
|
203
|
+
```
|
204
|
+
|
205
|
+
## Shells
|
206
|
+
|
207
|
+
Run a stage task to build the image up to that stage and cache the image digest.
|
208
|
+
|
209
|
+
Run with the `:shell` suffix to build the image and then shell into an instance of the image running as a temporary container.
|
210
|
+
|
211
|
+
The default shell is `/bin/sh`, but this can be overridden at runtime with the task arg, eg. `rum build:shell[/bin/bash]`
|
212
|
+
|
213
|
+
## Build vs. Run
|
214
|
+
|
215
|
+
At the core, every directive within the `rum` block will eventually be interpreted as either a `docker build` or a `docker run` command. The type of directive is simply a way of specifying defaults for the command.
|
216
|
+
|
217
|
+
If you simply wish to define a named task that executes a build or a run, you can use the `build` or `run` directives:
|
218
|
+
|
219
|
+
```ruby
|
220
|
+
rum :image_name do
|
221
|
+
env :JAZZ => "fuzz"
|
222
|
+
|
223
|
+
build :fizz do
|
224
|
+
tag "image_name"
|
225
|
+
path "."
|
226
|
+
end
|
227
|
+
|
228
|
+
run :buzz do
|
229
|
+
rm true
|
230
|
+
image "image_name"
|
231
|
+
cmd %w[echo hello]
|
232
|
+
end
|
233
|
+
|
234
|
+
# rum fizz => docker build --build-arg JAZZ=fuzz --tag image_name .
|
235
|
+
# rum buzz => docker run --rm --env JAZZ=fuzz image_name echo hello
|
236
|
+
end
|
237
|
+
```
|
238
|
+
|
239
|
+
Note that the build/run commands will still import any shared ENV values defined above.
|
240
|
+
|
241
|
+
If this is undesirable, use the `clear_options` method inside your block to clear ALL the default options:
|
242
|
+
|
243
|
+
```ruby
|
244
|
+
rum :image_name do
|
245
|
+
|
246
|
+
env :JAZZ => "fuzz"
|
247
|
+
|
248
|
+
run :buzz do
|
249
|
+
clear_options
|
250
|
+
image "image_name"
|
251
|
+
cmd %w[echo hello]
|
252
|
+
end
|
253
|
+
|
254
|
+
# rum buzz => docker run image_name echo hello
|
255
|
+
end
|
256
|
+
```
|
257
|
+
|
258
|
+
## Blocks
|
259
|
+
|
260
|
+
The methods inside blocks for `build`, `run`, `stage`, `artifact`, and `shell` tasks are dynamically handled. Any option you might pass to the `docker run` or `docker build` command can be used.
|
261
|
+
|
262
|
+
Simply drop any leading `-`s from the option and convert to snake-case.
|
263
|
+
|
264
|
+
Eg,
|
265
|
+
|
266
|
+
`--build-arg` becomes `build_arg`
|
267
|
+
|
268
|
+
`--env-file` becomes `env_file`.
|
269
|
+
|
270
|
+
## Task Naming Convention
|
271
|
+
|
272
|
+
As of v0.3, rum runner uses a "verb-first" naming convention (eg. `clean:stage`) for tasks.
|
273
|
+
|
274
|
+
To revert to the previous convention of "stage-first" (eg. `stage:clean`) use the environmental variable `RUM_TASK_NAMES`:
|
275
|
+
|
276
|
+
```bash
|
277
|
+
export RUM_TASK_NAMES=STAGE_FIRST # => rum stage:clean
|
278
|
+
export RUM_TASK_NAMES=VERB_FIRST # => rum clean:stage (default)
|
279
|
+
```
|
280
|
+
|
281
|
+
## Image Naming Convention
|
282
|
+
|
283
|
+
The name of the images are taken from the first argument to the main block and appended with the name of the stage.
|
284
|
+
|
285
|
+
In the above example, built images would build be named:
|
286
|
+
|
287
|
+
- `image_name:1.2.3-build`
|
288
|
+
- `image_name:1.2.3-test`
|
289
|
+
- `image_name:1.2.3-deploy`
|
290
|
+
|
291
|
+
The first argument to the main block can be any Docker image reference:
|
292
|
+
|
293
|
+
```ruby
|
294
|
+
rum :"registry:5000/username/image" do
|
295
|
+
#...
|
296
|
+
end
|
297
|
+
```
|
298
|
+
|
299
|
+
## Dockerfile Location
|
300
|
+
|
301
|
+
Images built use the current working directory as the default path to the Dockerfile, but this can be modified:
|
302
|
+
|
303
|
+
```ruby
|
304
|
+
rum :image_name => "some/dockerfile/dir" do
|
305
|
+
# ...
|
306
|
+
end
|
307
|
+
```
|
308
|
+
|
309
|
+
The default Dockerfile path can also be set using the `RUM_PATH` environmental variable.
|
310
|
+
|
311
|
+
|
312
|
+
## Docker Image Digest Location
|
313
|
+
|
314
|
+
Images build with the `stage` task have their digests cached for easy lookup.
|
315
|
+
|
316
|
+
The default location for the digests is in `.docker`, but that can be modified:
|
317
|
+
|
318
|
+
```ruby
|
319
|
+
rum :image_name => [".", "tmp"] do
|
320
|
+
# ...
|
321
|
+
end
|
322
|
+
```
|
323
|
+
|
324
|
+
Note that in this case you must also explicitly define the Dockerfile path.
|
325
|
+
|
326
|
+
The default digest path can also be set using the `RUM_HOME` environmental variable.
|
327
|
+
|
328
|
+
## Integrate with Rake
|
329
|
+
|
330
|
+
It isn't strictly necessary to include a `Rumfile` in your project. Rum Runner can be included in any `Rakefile` and run with the `rake` command:
|
331
|
+
|
332
|
+
```ruby
|
333
|
+
# ./Rakefile
|
334
|
+
|
335
|
+
require "rumrunner"
|
336
|
+
|
337
|
+
namespace :rum do
|
338
|
+
rum :image_name do
|
339
|
+
stage :build
|
340
|
+
stage :test => :build
|
341
|
+
end
|
342
|
+
end
|
343
|
+
```
|
344
|
+
|
345
|
+
```bash
|
346
|
+
$ rake --tasks
|
347
|
+
|
348
|
+
rake rum:build # ...
|
349
|
+
rake rum:test # ...
|
350
|
+
```
|
data/lib/rumrunner/docker.rb
CHANGED
@@ -266,6 +266,13 @@ module Rum
|
|
266
266
|
File.join(*[@registry, @username, @name].compact.map(&:to_s))
|
267
267
|
end
|
268
268
|
|
269
|
+
##
|
270
|
+
# Show handle
|
271
|
+
def inspect
|
272
|
+
handle = @tag.nil? || @tag.to_sym == :latest ? family : to_s
|
273
|
+
"#<#{self.class.name}[#{handle}]>"
|
274
|
+
end
|
275
|
+
|
269
276
|
##
|
270
277
|
# Convert the image reference to string.
|
271
278
|
def to_s
|
@@ -22,8 +22,8 @@ module Rum
|
|
22
22
|
#
|
23
23
|
def rum(*args, &block)
|
24
24
|
name, _, deps = Rake.application.resolve_args(args)
|
25
|
-
|
26
|
-
Manifest.new(name: name,
|
25
|
+
path, home = deps
|
26
|
+
Manifest.new(name: name, path: path, home: home, &block).install
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
data/lib/rumrunner/manifest.rb
CHANGED
@@ -14,21 +14,22 @@ module Rum
|
|
14
14
|
attr_reader :image
|
15
15
|
|
16
16
|
def_delegator :@env, :<<, :env
|
17
|
-
def_delegator :@
|
17
|
+
def_delegator :@path, :to_s, :path
|
18
|
+
def_delegator :@home, :to_s, :home
|
18
19
|
def_delegators :@image, :registry, :username, :name, :tag, :to_s
|
19
20
|
|
20
21
|
##
|
21
|
-
# Initialize new manifest with name and
|
22
|
+
# Initialize new manifest with name, build path, and home path for caching
|
22
23
|
# build digests. Evaluates <tt>&block</tt> if given.
|
23
24
|
#
|
24
25
|
# Example:
|
25
|
-
# Manifest.new(name: "my_image",
|
26
|
+
# Manifest.new(name: "my_image", path: ".", home: ".docker")
|
26
27
|
#
|
27
|
-
def initialize(name:,
|
28
|
-
@
|
29
|
-
@
|
28
|
+
def initialize(name:, path:nil, home:nil, env:nil, &block)
|
29
|
+
@path = path || ENV["RUM_PATH"] || "."
|
30
|
+
@home = home || ENV["RUM_HOME"] || ".docker"
|
31
|
+
@env = env || []
|
30
32
|
@image = Docker::Image.parse(name)
|
31
|
-
@env = []
|
32
33
|
instance_eval(&block) if block_given?
|
33
34
|
end
|
34
35
|
|
@@ -58,9 +59,8 @@ module Rum
|
|
58
59
|
# build :name => [:deps]
|
59
60
|
#
|
60
61
|
def build(*args, &block)
|
61
|
-
|
62
|
-
|
63
|
-
sh Docker::Build.new(options: build_options, &block).to_s
|
62
|
+
task(*args) do
|
63
|
+
sh Docker::Build.new(options: build_options, path: path, &block).to_s
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -75,10 +75,10 @@ module Rum
|
|
75
75
|
name, _, deps = Rake.application.resolve_args(args)
|
76
76
|
|
77
77
|
images = deps.map{|dep| Docker::Image.parse("#{@image}-#{dep}") }
|
78
|
-
iidfiles = images.map{|image| File.join(
|
78
|
+
iidfiles = images.map{|image| File.join(home, *image) }
|
79
79
|
|
80
|
-
task name => iidfiles do
|
81
|
-
image =
|
80
|
+
task name => iidfiles do |t|
|
81
|
+
image = t.prereqs.empty? ? to_s : File.read(t.prereqs.first)
|
82
82
|
sh Docker::Run.new(options: run_options, image: image, &block).to_s
|
83
83
|
end
|
84
84
|
end
|
@@ -95,7 +95,7 @@ module Rum
|
|
95
95
|
|
96
96
|
# Assemble image/iidfile from manifest/stage name
|
97
97
|
image = Docker::Image.parse("#{@image}-#{name}")
|
98
|
-
iidfile = File.join(
|
98
|
+
iidfile = File.join(home, *image)
|
99
99
|
iidpath = File.split(iidfile).first
|
100
100
|
|
101
101
|
# Ensure path to iidfile exists
|
@@ -104,20 +104,20 @@ module Rum
|
|
104
104
|
iidpath
|
105
105
|
else
|
106
106
|
images = deps.map{|x| Docker::Image.parse("#{@image}-#{x}") }
|
107
|
-
images.map{|x| File.join(
|
107
|
+
images.map{|x| File.join(home, *x) }
|
108
108
|
end
|
109
109
|
|
110
110
|
# Build stage and save digest in iidfile
|
111
|
-
stage_file
|
111
|
+
stage_file(iidfile, iiddeps, tag: image, target: name, &block)
|
112
112
|
|
113
113
|
# Shortcut to build stage by name
|
114
|
-
stage_task
|
114
|
+
stage_task(name, iidfile)
|
115
115
|
|
116
116
|
# Shell into stage
|
117
|
-
stage_shell
|
117
|
+
stage_shell(name, iidfile)
|
118
118
|
|
119
119
|
# Clean stage
|
120
|
-
stage_clean
|
120
|
+
stage_clean(name, iidfile, deps)
|
121
121
|
end
|
122
122
|
|
123
123
|
##
|
@@ -133,7 +133,7 @@ module Rum
|
|
133
133
|
|
134
134
|
target = deps.first
|
135
135
|
image = Docker::Image.parse("#{@image}-#{target}")
|
136
|
-
iidfile = File.join(
|
136
|
+
iidfile = File.join(home, *image)
|
137
137
|
path = File.split(name).first
|
138
138
|
deps = [iidfile]
|
139
139
|
|
@@ -142,9 +142,9 @@ module Rum
|
|
142
142
|
deps << path
|
143
143
|
end
|
144
144
|
|
145
|
-
artifact_file
|
145
|
+
artifact_file(name, deps, iidfile, &block)
|
146
146
|
|
147
|
-
artifact_clobber
|
147
|
+
artifact_clobber(name, path)
|
148
148
|
end
|
149
149
|
|
150
150
|
##
|
@@ -158,7 +158,7 @@ module Rum
|
|
158
158
|
target = Rake.application.resolve_args(args).first
|
159
159
|
name = task_name shell: target
|
160
160
|
image = Docker::Image.parse("#{@image}-#{target}")
|
161
|
-
iidfile = File.join(
|
161
|
+
iidfile = File.join(home, *image)
|
162
162
|
|
163
163
|
Rake::Task[name].clear if Rake::Task.task_defined?(name)
|
164
164
|
|
@@ -175,6 +175,7 @@ module Rum
|
|
175
175
|
##
|
176
176
|
# Install any remaining tasks for the manifest.
|
177
177
|
def install
|
178
|
+
install_default unless Rake::Task.task_defined?(:default)
|
178
179
|
install_clean
|
179
180
|
|
180
181
|
self
|
@@ -200,20 +201,34 @@ module Rum
|
|
200
201
|
def install_clean
|
201
202
|
desc "Remove any temporary images and products"
|
202
203
|
task :clean do
|
203
|
-
Dir[File.join
|
204
|
+
Dir[File.join(home, "**/*")].reverse.each do |name|
|
204
205
|
sh "docker", "image", "rm", "--force", File.read(name) if File.file?(name)
|
205
206
|
rm_rf name
|
206
207
|
end
|
207
|
-
rm_rf
|
208
|
+
rm_rf home if Dir.exist?(home)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
##
|
213
|
+
# Install :default task that builds the image
|
214
|
+
def install_default
|
215
|
+
iidfile = File.join(home, *image)
|
216
|
+
file iidfile do |t|
|
217
|
+
tsfile = "#{t.name}@#{Time.now.utc.to_i}"
|
218
|
+
build = Docker::Build.new(options: build_options, path: path)
|
219
|
+
build.with_defaults(iidfile: tsfile, tag: tag || :latest)
|
220
|
+
sh build.to_s
|
221
|
+
cp tsfile, iidfile
|
208
222
|
end
|
223
|
+
task :default => iidfile
|
209
224
|
end
|
210
225
|
|
211
226
|
##
|
212
227
|
# Install file task for stage and save digest in iidfile
|
213
228
|
def stage_file(iidfile, iiddeps, tag:, target:, &block)
|
214
|
-
file iidfile => iiddeps do
|
215
|
-
tsfile = "#{
|
216
|
-
build
|
229
|
+
file iidfile => iiddeps do |t|
|
230
|
+
tsfile = "#{t.name}@#{Time.now.utc.to_i}"
|
231
|
+
build = Docker::Build.new(options: build_options, path: path, &block)
|
217
232
|
build.with_defaults(iidfile: tsfile, tag: tag, target: target)
|
218
233
|
sh build.to_s
|
219
234
|
cp tsfile, iidfile
|
@@ -232,7 +247,7 @@ module Rum
|
|
232
247
|
def stage_shell(name, iidfile)
|
233
248
|
desc "Shell into `#{name}` stage"
|
234
249
|
task task_name(shell: name), [:shell] => iidfile do |t,args|
|
235
|
-
digest = File.read(
|
250
|
+
digest = File.read(t.prereqs.first)
|
236
251
|
shell = args.any? ? args.to_a.join(" ") : "/bin/sh"
|
237
252
|
run = Docker::Run.new(options: run_options)
|
238
253
|
.entrypoint(shell)
|
@@ -250,7 +265,7 @@ module Rum
|
|
250
265
|
# Clean stage image
|
251
266
|
desc "Remove any temporary images and products through `#{name}` stage"
|
252
267
|
task task_name(clean: name) do
|
253
|
-
if File.exist?
|
268
|
+
if File.exist?(iidfile)
|
254
269
|
sh "docker", "image", "rm", "--force", File.read(iidfile)
|
255
270
|
rm_rf iidfile
|
256
271
|
end
|
data/lib/rumrunner/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rumrunner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Mancevice
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10
|
11
|
+
date: 2019-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -104,6 +104,8 @@ executables:
|
|
104
104
|
extensions: []
|
105
105
|
extra_rdoc_files: []
|
106
106
|
files:
|
107
|
+
- LICENSE
|
108
|
+
- README.md
|
107
109
|
- bin/rum
|
108
110
|
- lib/rumrunner.rb
|
109
111
|
- lib/rumrunner/application.rb
|
@@ -131,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
133
|
- !ruby/object:Gem::Version
|
132
134
|
version: '0'
|
133
135
|
requirements: []
|
134
|
-
rubygems_version: 3.0.
|
136
|
+
rubygems_version: 3.0.6
|
135
137
|
signing_key:
|
136
138
|
specification_version: 4
|
137
139
|
summary: Rum Runner is a Rake-based utility for building projects with multi-stage
|