rumrunner 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/rumrunner/application.rb +10 -0
- data/lib/rumrunner/docker.rb +122 -4
- data/lib/rumrunner/dsl_definition.rb +12 -3
- data/lib/rumrunner/init.rb +7 -0
- data/lib/rumrunner/manifest.rb +64 -0
- data/lib/rumrunner/version.rb +3 -1
- data/lib/rumrunner.rb +3 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21ff1aee760e860283bf640e87bbdd97f5e6995caa5cdce7187c829e29417a67
|
4
|
+
data.tar.gz: f2acce2d5a033fce78a9010395063a8f44c8a45348de6eb08728aea43d873720
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b04b16707b81b88364e880fd3ba15dab605853735eaa67b537a1f9f293824a341befbceea5634ef1d8b6bbcdcf9bd63be841c0dfb768af97a8d662ad0870456
|
7
|
+
data.tar.gz: c9116ff64a6b9f4d77e724f49ec903f3c917a81acaab9b7905d4a96c0623aae6c77a3c9503dcb7aae4597c65458ee269dbf755ff629d4208d3df9ba7a4cfaa3d
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
<img alt="rumrunner" src="./docs/icon.png"/>
|
2
1
|
|
2
|
+
![Rum Runner](https://github.com/amancevice/rumrunner/blob/master/rumrunner.png?raw=true)
|
3
3
|
[![Build Status](https://travis-ci.com/amancevice/rumrunner.svg?branch=master)](https://travis-ci.com/amancevice/rumrunner)
|
4
4
|
[![codecov](https://codecov.io/gh/amancevice/rumrunner/branch/master/graph/badge.svg)](https://codecov.io/gh/amancevice/rumrunner)
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/rumrunner.svg)](https://badge.fury.io/rb/rumrunner)
|
@@ -23,6 +23,8 @@ Rum Runner has the following features:
|
|
23
23
|
|
24
24
|
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.
|
25
25
|
|
26
|
+
View the docs on [rubydoc.info](https://www.rubydoc.info/github/amancevice/rumrunner)
|
27
|
+
|
26
28
|
## Installation
|
27
29
|
|
28
30
|
```bash
|
@@ -1,7 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "rake"
|
2
3
|
|
3
4
|
module Rum
|
5
|
+
|
6
|
+
##
|
7
|
+
# Rum main application object. When invoking +rum+ from the
|
8
|
+
# command line, a Rum::Application object is created and run.
|
4
9
|
class Application < Rake::Application
|
10
|
+
|
11
|
+
##
|
12
|
+
# Default names for Rum Runner manifests.
|
5
13
|
DEFAULT_RAKEFILES = [
|
6
14
|
"rumfile",
|
7
15
|
"Rumfile",
|
@@ -9,6 +17,7 @@ module Rum
|
|
9
17
|
"Rumfile.rb",
|
10
18
|
]
|
11
19
|
|
20
|
+
##
|
12
21
|
# Initialize a Rumfile::Application object.
|
13
22
|
def initialize
|
14
23
|
super
|
@@ -16,6 +25,7 @@ module Rum
|
|
16
25
|
@rakefiles = DEFAULT_RAKEFILES.dup
|
17
26
|
end
|
18
27
|
|
28
|
+
##
|
19
29
|
# Initialize the command line parameters and app name.
|
20
30
|
def init(app_name="rum", argv = ARGV)
|
21
31
|
super "rum", argv
|
data/lib/rumrunner/docker.rb
CHANGED
@@ -1,8 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "forwardable"
|
2
3
|
|
3
4
|
module Rum
|
5
|
+
|
6
|
+
##
|
7
|
+
# Docker-specific objects and mixins.
|
4
8
|
module Docker
|
9
|
+
|
10
|
+
##
|
11
|
+
# Mixin to enable adding instance methods to a class that
|
12
|
+
# gets or sets-and-returns the given attr of the instance.
|
5
13
|
module AttrCallable
|
14
|
+
|
15
|
+
##
|
16
|
+
# Method to define a method-accessor for each argument supplied.
|
17
|
+
# When extended by a class
|
18
|
+
#
|
19
|
+
# Example:
|
20
|
+
# class Fizz
|
21
|
+
# extend AttrCallable
|
22
|
+
# attr_method_accessor :buzz
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# fizz = Fizz.new
|
26
|
+
# fizz.buzz "foo"
|
27
|
+
# fizz.buzz
|
28
|
+
# # => "foo"
|
29
|
+
#
|
6
30
|
def attr_method_accessor(*args)
|
7
31
|
args.each do |var|
|
8
32
|
define_method var do |value = nil|
|
@@ -17,54 +41,96 @@ module Rum
|
|
17
41
|
end
|
18
42
|
end
|
19
43
|
|
44
|
+
##
|
45
|
+
# Mixin to enable runtime Docker command manipulation.
|
20
46
|
module Executable
|
21
47
|
include Enumerable
|
22
48
|
|
49
|
+
##
|
50
|
+
# The +OPTIONS+ portion of a Docker command.
|
23
51
|
attr_reader :options
|
24
52
|
|
53
|
+
##
|
54
|
+
# Initialize Docker executable with +OPTIONS+ and evaluate the
|
55
|
+
# <tt>&block</tt> if given.
|
25
56
|
def initialize(options:nil, &block)
|
26
57
|
@options = options || Options.new
|
27
58
|
instance_eval(&block) if block_given?
|
28
59
|
end
|
29
60
|
|
61
|
+
##
|
62
|
+
# Yield Docker command word by word.
|
30
63
|
def each
|
31
64
|
self.class.name.split(/::/)[1..-1].each{|x| yield x.downcase }
|
32
65
|
@options.each{|x| yield x }
|
33
66
|
end
|
34
67
|
|
68
|
+
##
|
69
|
+
# Interpret missing methods as +OPTION+.
|
35
70
|
def method_missing(m, *args, &block)
|
36
71
|
@options.send(m, *args, &block)
|
37
72
|
args.any? ? self : @options[m]
|
38
73
|
end
|
39
74
|
|
75
|
+
##
|
76
|
+
# Convert Docker command to string.
|
40
77
|
def to_s
|
41
78
|
to_a.join(" ")
|
42
79
|
end
|
43
80
|
|
44
|
-
|
81
|
+
##
|
82
|
+
# Assign default values to Docker command if not explicitly set.
|
83
|
+
#
|
84
|
+
# Example:
|
85
|
+
# Run.new(&block).with_defaults(user: "fizz")
|
86
|
+
#
|
87
|
+
# Unless the <tt>&block</tt> contains a directive to set a value for +user+,
|
88
|
+
# it will be set to "fizz".
|
89
|
+
def with_defaults(options = {})
|
45
90
|
options.reject{|k,v| @options.include? k }.each{|k,v| @options[k] << v }
|
46
91
|
self
|
47
92
|
end
|
48
93
|
end
|
49
94
|
|
95
|
+
##
|
96
|
+
# Collection of Docker command options to be applied on execution.
|
50
97
|
class Options
|
51
98
|
extend Forwardable
|
52
99
|
include Enumerable
|
53
100
|
|
54
|
-
attr_reader :data
|
55
|
-
|
56
101
|
def_delegators :@data, :[], :[]=, :include?, :to_h, :update
|
57
102
|
|
103
|
+
##
|
104
|
+
# Initialize a new +OPTIONS+ collection for Docker executable.
|
105
|
+
# Evaluates the <tt>&block</tt> if given.
|
58
106
|
def initialize(options = {}, &block)
|
59
107
|
@data = Hash.new{|hash, key| hash[key] = [] }.update(options)
|
60
108
|
instance_eval(&block) if block_given?
|
61
109
|
end
|
62
110
|
|
111
|
+
##
|
112
|
+
# Missing methods are interpreted as options to be added to the
|
113
|
+
# underlying collection.
|
114
|
+
#
|
115
|
+
# Example:
|
116
|
+
# opts = Options.new
|
117
|
+
# opts.fizz "buzz"
|
118
|
+
# # => @data={:fizz=>["buzz"]}
|
119
|
+
#
|
63
120
|
def method_missing(m, *args, &block)
|
64
121
|
@data[m] += args unless args.empty?
|
65
122
|
self
|
66
123
|
end
|
67
124
|
|
125
|
+
##
|
126
|
+
# Yield each option as a CLI flag/option, with +-+ or +--+ prefix.
|
127
|
+
#
|
128
|
+
# Example:
|
129
|
+
# opts = Options.new
|
130
|
+
# opts.fizz "buzz"
|
131
|
+
# opts.to_a
|
132
|
+
# # => ["--fizz", "buzz"]
|
133
|
+
#
|
68
134
|
def each
|
69
135
|
@data.each do |name, values|
|
70
136
|
option = name.length == 1 ? "-#{name}" : "--#{name.to_s.gsub(/_/, "-")}"
|
@@ -76,7 +142,7 @@ module Rum
|
|
76
142
|
yield val
|
77
143
|
end
|
78
144
|
elsif [true, false].include? value
|
79
|
-
yield option
|
145
|
+
yield "#{option}=#{value}"
|
80
146
|
else
|
81
147
|
yield option
|
82
148
|
yield value.to_s
|
@@ -85,40 +151,67 @@ module Rum
|
|
85
151
|
end
|
86
152
|
end
|
87
153
|
|
154
|
+
##
|
155
|
+
# Convert options to string.
|
156
|
+
#
|
157
|
+
# Example:
|
158
|
+
# opts = Options.new
|
159
|
+
# opts.fizz "buzz"
|
160
|
+
# opts.to_s
|
161
|
+
# # => "--fizz buzz"
|
162
|
+
#
|
88
163
|
def to_s
|
89
164
|
to_a.join(" ")
|
90
165
|
end
|
91
166
|
end
|
92
167
|
|
168
|
+
##
|
169
|
+
# Docker build command object.
|
93
170
|
class Build
|
94
171
|
extend AttrCallable
|
95
172
|
include Executable
|
96
173
|
|
174
|
+
##
|
175
|
+
# Access +PATH+ with method.
|
97
176
|
attr_method_accessor :path
|
98
177
|
|
178
|
+
##
|
179
|
+
# Initialize Docker build command with +OPTIONS+ and +PATH+.
|
180
|
+
# Evaluates the <tt>&block</tt> if given.
|
99
181
|
def initialize(options:nil, path:nil, &block)
|
100
182
|
@path = path
|
101
183
|
super options: options, &block
|
102
184
|
end
|
103
185
|
|
186
|
+
##
|
187
|
+
# Yield the Docker build commmand word-by-word.
|
104
188
|
def each
|
105
189
|
super{|x| yield x }
|
106
190
|
yield @path || "."
|
107
191
|
end
|
108
192
|
end
|
109
193
|
|
194
|
+
##
|
195
|
+
# Docker run command object.
|
110
196
|
class Run
|
111
197
|
extend AttrCallable
|
112
198
|
include Executable
|
113
199
|
|
200
|
+
##
|
201
|
+
# Access +IMAGE+ and +CMD+ with method.
|
114
202
|
attr_method_accessor :image, :cmd
|
115
203
|
|
204
|
+
##
|
205
|
+
# Initialize Docker run command with +OPTIONS+, +IMAGE+, and +CMD+.
|
206
|
+
# Evaluates the <tt>&block</tt> if given.
|
116
207
|
def initialize(options:nil, image:nil, cmd:nil, &block)
|
117
208
|
@image = image
|
118
209
|
@cmd = cmd
|
119
210
|
super options: options, &block
|
120
211
|
end
|
121
212
|
|
213
|
+
##
|
214
|
+
# Yield the Docker run commmand word-by-word.
|
122
215
|
def each
|
123
216
|
super{|x| yield x }
|
124
217
|
yield @image
|
@@ -126,12 +219,19 @@ module Rum
|
|
126
219
|
end
|
127
220
|
end
|
128
221
|
|
222
|
+
##
|
223
|
+
# Docker image object.
|
129
224
|
class Image
|
130
225
|
extend AttrCallable
|
131
226
|
include Enumerable
|
132
227
|
|
228
|
+
##
|
229
|
+
# Access components of the image reference by method.
|
133
230
|
attr_method_accessor :registry, :username, :name, :tag
|
134
231
|
|
232
|
+
##
|
233
|
+
# Initialize image by reference component.
|
234
|
+
# Evaluates <tt>&block</tt> if given.
|
135
235
|
def initialize(name:, registry:nil, username:nil, tag:nil, &block)
|
136
236
|
@registry = registry
|
137
237
|
@username = username
|
@@ -140,19 +240,37 @@ module Rum
|
|
140
240
|
instance_eval(&block) if block_given?
|
141
241
|
end
|
142
242
|
|
243
|
+
##
|
244
|
+
# Yield each non-nil component of the image reference in order.
|
143
245
|
def each
|
144
246
|
[@registry, @username, @name, @tag].compact.each{|x| yield x }
|
145
247
|
end
|
146
248
|
|
249
|
+
##
|
250
|
+
# Get the image reference without the @tag component.
|
147
251
|
def family
|
148
252
|
File.join *[@registry, @username, @name].compact.map(&:to_s)
|
149
253
|
end
|
150
254
|
|
255
|
+
##
|
256
|
+
# Convert the image reference to string.
|
151
257
|
def to_s
|
152
258
|
"#{family}:#{@tag || :latest}"
|
153
259
|
end
|
154
260
|
|
155
261
|
class << self
|
262
|
+
|
263
|
+
##
|
264
|
+
# Parse a string as a Docker image reference
|
265
|
+
#
|
266
|
+
# Example:
|
267
|
+
# Image.parse("image")
|
268
|
+
# Image.parse("image:tag")
|
269
|
+
# Image.parse("username/image")
|
270
|
+
# Image.parse("username/image:tag")
|
271
|
+
# Image.parse("registry:5000/username/image")
|
272
|
+
# Image.parse("registry:5000/username/image:tag")
|
273
|
+
#
|
156
274
|
def parse(string_or_symbol)
|
157
275
|
string = string_or_symbol.to_s
|
158
276
|
if string.count("/").zero? && string.count(":").zero?
|
@@ -1,15 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "rake"
|
2
3
|
|
3
4
|
require "rumrunner/manifest"
|
4
5
|
|
5
6
|
module Rum
|
7
|
+
|
8
|
+
##
|
9
|
+
# Defines the DSL methods for Rum Runner.
|
6
10
|
module DSL
|
7
11
|
|
8
12
|
private
|
9
13
|
|
10
|
-
|
11
|
-
#
|
12
|
-
#
|
14
|
+
##
|
15
|
+
# Rum base task block.
|
16
|
+
#
|
17
|
+
# Example
|
18
|
+
# rum :amancevice/rumrunner do
|
19
|
+
# tag %x(git describe --tags --always)
|
20
|
+
# # ...
|
21
|
+
# end
|
13
22
|
#
|
14
23
|
def rum(*args, &block)
|
15
24
|
name, _, deps = Rake.application.resolve_args(args)
|
data/lib/rumrunner/init.rb
CHANGED
@@ -2,6 +2,13 @@ require "rumrunner/docker"
|
|
2
2
|
|
3
3
|
module Rum
|
4
4
|
class << self
|
5
|
+
|
6
|
+
##
|
7
|
+
# Helper to initialize a +Rumfile+
|
8
|
+
#
|
9
|
+
# Example:
|
10
|
+
# $ ruby -r rumrunner -e Rum.init > Rumfile
|
11
|
+
#
|
5
12
|
def init(input = nil, stdin = $stdin, stdout = $stdout, stderr = $stderr)
|
6
13
|
# Get image name from stdin
|
7
14
|
stderr.write "Docker image name [#{default = File.split(Dir.pwd).last}]: "
|
data/lib/rumrunner/manifest.rb
CHANGED
@@ -2,16 +2,28 @@ require "forwardable"
|
|
2
2
|
require "rake"
|
3
3
|
|
4
4
|
module Rum
|
5
|
+
|
6
|
+
##
|
7
|
+
# Rum Runner Manifest for managing Docker commands.
|
5
8
|
class Manifest
|
6
9
|
extend Forwardable
|
7
10
|
include Rake::DSL if defined? Rake::DSL
|
8
11
|
|
12
|
+
##
|
13
|
+
# Access Docker image object.
|
9
14
|
attr_reader :image
|
10
15
|
|
11
16
|
def_delegator :@env, :<<, :env
|
12
17
|
def_delegator :@root, :to_s, :root
|
13
18
|
def_delegators :@image, :registry, :username, :name, :tag
|
14
19
|
|
20
|
+
##
|
21
|
+
# Initialize new manifest with name and root path for caching
|
22
|
+
# build digests. Evaluates <tt>&block</tt> if given.
|
23
|
+
#
|
24
|
+
# Example:
|
25
|
+
# Manifest.new(name: "my_image", root: ".docker")
|
26
|
+
#
|
15
27
|
def initialize(name:, root:nil, &block)
|
16
28
|
@name = name
|
17
29
|
@root = root || :".docker"
|
@@ -20,11 +32,25 @@ module Rum
|
|
20
32
|
instance_eval(&block) if block_given?
|
21
33
|
end
|
22
34
|
|
35
|
+
##
|
36
|
+
# Defines the default task for +rum+ executable.
|
37
|
+
#
|
38
|
+
# Example:
|
39
|
+
# default :task_or_file
|
40
|
+
# default :task_or_file => [:deps]
|
41
|
+
#
|
23
42
|
def default(*args, &block)
|
24
43
|
name = Rake.application.resolve_args(args).first
|
25
44
|
task :default => name
|
26
45
|
end
|
27
46
|
|
47
|
+
##
|
48
|
+
# Defines generic +docker build+ task.
|
49
|
+
#
|
50
|
+
# Example:
|
51
|
+
# build :name
|
52
|
+
# build :name => [:deps]
|
53
|
+
#
|
28
54
|
def build(*args, &block)
|
29
55
|
name, _, deps = Rake.application.resolve_args(args)
|
30
56
|
task name => deps do
|
@@ -32,6 +58,13 @@ module Rum
|
|
32
58
|
end
|
33
59
|
end
|
34
60
|
|
61
|
+
##
|
62
|
+
# Defines generic +docker run+ task.
|
63
|
+
#
|
64
|
+
# Example:
|
65
|
+
# run :name
|
66
|
+
# run :name => [:deps]
|
67
|
+
#
|
35
68
|
def run(*args, &block)
|
36
69
|
name, _, deps = Rake.application.resolve_args(args)
|
37
70
|
task name => deps do
|
@@ -39,6 +72,13 @@ module Rum
|
|
39
72
|
end
|
40
73
|
end
|
41
74
|
|
75
|
+
##
|
76
|
+
# Defines +docker build+ task for the given stage.
|
77
|
+
#
|
78
|
+
# Example:
|
79
|
+
# stage :name
|
80
|
+
# stage :name => [:deps]
|
81
|
+
#
|
42
82
|
def stage(*args, &block)
|
43
83
|
name, _, deps = Rake.application.resolve_args(args)
|
44
84
|
|
@@ -96,6 +136,14 @@ module Rum
|
|
96
136
|
deps.each{|dep| task :"#{dep}:clean" => :"#{name}:clean" }
|
97
137
|
end
|
98
138
|
|
139
|
+
##
|
140
|
+
# Defines +docker run+ task for redirecting a file from a running
|
141
|
+
# instance of the dependent stage's container to the local file
|
142
|
+
# system.
|
143
|
+
#
|
144
|
+
# Example:
|
145
|
+
# artifact :name => [:stage]
|
146
|
+
#
|
99
147
|
def artifact(*args, &block)
|
100
148
|
name, _, deps = Rake.application.resolve_args(args)
|
101
149
|
|
@@ -125,6 +173,13 @@ module Rum
|
|
125
173
|
end
|
126
174
|
end
|
127
175
|
|
176
|
+
##
|
177
|
+
# Defines +docker run+ task for shelling into the given stage.
|
178
|
+
#
|
179
|
+
# Example:
|
180
|
+
# shell :stage
|
181
|
+
# shell :stage => [:deps]
|
182
|
+
#
|
128
183
|
def shell(*args, &block)
|
129
184
|
target = Rake.application.resolve_args(args).first
|
130
185
|
name = :"#{target}:shell"
|
@@ -143,6 +198,8 @@ module Rum
|
|
143
198
|
end
|
144
199
|
end
|
145
200
|
|
201
|
+
##
|
202
|
+
# Install any remaining tasks for the manifest.
|
146
203
|
def install
|
147
204
|
install_clean
|
148
205
|
|
@@ -151,14 +208,21 @@ module Rum
|
|
151
208
|
|
152
209
|
private
|
153
210
|
|
211
|
+
##
|
212
|
+
# Get the shared build options for the Manifest.
|
154
213
|
def build_options
|
155
214
|
Docker::Options.new(build_arg: @env) unless @env.empty?
|
156
215
|
end
|
157
216
|
|
217
|
+
##
|
218
|
+
# Get the shared run options for the Manifest.
|
158
219
|
def run_options
|
159
220
|
Docker::Options.new(env: @env) unless @env.empty?
|
160
221
|
end
|
161
222
|
|
223
|
+
##
|
224
|
+
# Install :clean task for removing temporary Docker images and
|
225
|
+
# iidfiles.
|
162
226
|
def install_clean
|
163
227
|
desc "Remove any temporary images and products"
|
164
228
|
task :clean do
|
data/lib/rumrunner/version.rb
CHANGED
data/lib/rumrunner.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.2.
|
4
|
+
version: 0.2.5
|
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-07-
|
11
|
+
date: 2019-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|