rumrunner 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14bdd585158d5a24f0caa7868eeb5e8ef19bd54055950839f6dce9e6b134435d
4
- data.tar.gz: 240eab4bc1a0abaf9ba38e431f2d01af211a37b601c0ae3e2f764f858a2d04e0
3
+ metadata.gz: ccce65ebe39fca8b6c649ee4584cc97763ff0f0341434b810f92b3de7b498157
4
+ data.tar.gz: 1f679cd595b16cda478a2b3b416e8040c17ec84fe889f9e969807a25435d6850
5
5
  SHA512:
6
- metadata.gz: 93761c6971fe01063ae6c91f26a2ee19c2bbbab0a52e8027d5d0c2536f7f5201f6cfa0cd4d41ff9b3efd195d3392b1083c62b7449696f995bef062a69c8112ef
7
- data.tar.gz: c867c322254c754b275f90d66b5ed10f5082ca6185b7e59e24d24b7e4a5403e3e299aa9736df26ffeed6efdb859eb6d50916ab3743ec0099817d4e861aad1190
6
+ metadata.gz: c4252be1a723094c039c2a4c8b15e0bde5947c3e967f1486653b71f36af91c5be08c944f58ce2c3a7eb998f9159abb81e2b2be7642c23284bc437ba4f48d596b
7
+ data.tar.gz: 1a79e2c3b769db27f089c92ce90fa9ea3aebe7fd2218f5e7db5c34ac91157e5d49cff8d51e998cbad044e948204aedf9ffac115f9ab6618d19114ff7c4a955a3
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
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
+ [![Gem Version](https://badge.fury.io/rb/rumrunner.svg)](https://badge.fury.io/rb/rumrunner)
5
6
 
6
7
  Rum Runner is a Rake-based utility for building multi-stage Dockerfiles.
7
8
 
@@ -10,9 +11,10 @@ Users can pair a multi-stage Dockerfile with a Rumfile that uses a Rake-like DSL
10
11
  The `rum` executable allows users to easily invoke builds, shell-into specific stages for debugging, and export artifacts from built containers.
11
12
 
12
13
  Rum Runner has the following features:
13
- * Rake-like DSL/CLI that enable simple annotation and execution of builds.
14
- * Rumfiles are completely defined in standard Ruby syntax, like Rakefiles.
15
- * Users can chain Docker build stages with prerequisites.
14
+ * Fully compatible with Rake
15
+ * Rake-like DSL/CLI that enable simple annotation and execution of builds
16
+ * Rumfiles are completely defined in standard Ruby syntax, like Rakefiles
17
+ * Users can chain Docker build stages with prerequisites
16
18
  * Artifacts can be exported from stages
17
19
  * Shell tasks are automatically provided for every stage
18
20
  * Stage, artifact, and shell, steps can be customized
@@ -29,7 +31,7 @@ gem install rumrunner
29
31
 
30
32
  ## Quickstart
31
33
 
32
- Use the helper `Rum.init` to create a template Rumfile for your project:
34
+ Use the `Rum.init` helper to create a template Rumfile for your project:
33
35
 
34
36
  ```bash
35
37
  # Install the gem
@@ -66,13 +68,17 @@ Create `Rumfile` and describe your build:
66
68
  rum :image_name do
67
69
  tag "1.2.3"
68
70
 
69
- stage :build # => docker build --target build --tag image_name:1.2.3-build .
70
- stage :test => :build # => docker build --target test --tag image_name:1.2.3-test .
71
- stage :deploy => :test # => docker build --target deploy --tag image_name:1.2.3-deploy .
71
+ stage :build
72
+ stage :test => :build
73
+ stage :deploy => :test
74
+
75
+ # rum build => docker build --target build --tag image_name:1.2.3-build .
76
+ # rum test => docker build --target test --tag image_name:1.2.3-test .
77
+ # rum deploy => docker build --target deploy --tag image_name:1.2.3-deploy .
72
78
  end
73
79
  ```
74
80
 
75
- Run `bundle exec rum --tasks` to view the installed tasks:
81
+ Run `rum --tasks` to view the installed tasks:
76
82
 
77
83
  ```bash
78
84
  rum build # Build `build` stage
@@ -88,22 +94,32 @@ rum test:clean # Remove any temporary images and products from `test`
88
94
  rum test:shell[shell] # Shell into `test` stage
89
95
  ```
90
96
 
91
- Run the `<stage>` task to build the image up to that stage and cache the image digest.
97
+ ## Naming Convention
92
98
 
93
- Run the `<stage>:shell` task to build the image and then shell into an instance of the image running as a temporary container.
99
+ The name of the images are taken from the first argument to the main block and appended with the name of the stage.
94
100
 
95
- The default shell is `/bin/sh`, but this can be overridden at runtime with the task arg, eg `bundle exec rum build:shell[/bin/bash]`
96
-
97
- The name of the images are taken from the name of the initial block and appended with the name of the stage. The above example would build:
101
+ In the above example, built images would build be named:
98
102
 
99
103
  - `image_name:1.2.3-build`
100
104
  - `image_name:1.2.3-test`
101
105
  - `image_name:1.2.3-deploy`
102
106
 
107
+ The first argument to the main block can be any Docker image reference:
108
+
109
+ ```ruby
110
+ rum :"registry:5000/username/image" do
111
+ #...
112
+ end
113
+ ```
114
+
115
+ ## Digest Location
116
+
117
+ Images build with the `stage` task have their digests cached for easy lookup.
118
+
103
119
  The default location for the digests is in `.docker`, but that can be modified:
104
120
 
105
121
  ```ruby
106
- rum :image_name => "tmp" do |c|
122
+ rum :image_name => "tmp" do
107
123
  # ...
108
124
  end
109
125
  ```
@@ -119,16 +135,25 @@ rum :image_name do
119
135
  build :fizz do
120
136
  tag "image_name"
121
137
  path "."
122
- end # => docker build --tag image_name .
138
+ end
123
139
 
124
140
  run :buzz do
125
141
  rm true
126
142
  image "image_name"
127
143
  cmd %w{echo hello}
128
- end # => docker run --rm image_name echo hello
144
+ end
145
+
146
+ # rake fizz => docker build --tag image_name .
147
+ # rake buzz => docker run --rm image_name echo hello
129
148
  end
130
149
  ```
131
150
 
151
+ ## Blocks
152
+
153
+ 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.
154
+
155
+ Simply drop any leading `-`s from the option and convert to snake-case. Eg, `--build-arg` becomes `build_arg`; `--env-file` becomes `env_file`.
156
+
132
157
  ## Shared ENV variables
133
158
 
134
159
  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.
@@ -137,15 +162,46 @@ The `env` method can be invoked in the `rum` block to declare a value that will
137
162
  rum :image_name do
138
163
  env :FIZZ => :BUZZ
139
164
 
140
- stage :build # => docker build --build-arg FIZZ=BUZZ ...
165
+ stage :build
166
+
167
+ artifact "pkg.zip" => :build
168
+
169
+ # rum build => docker build --build-arg FIZZ=BUZZ ...
170
+ # rum pkg.zip => docker run --env FIZZ=BUZZ ...
171
+ end
172
+ ```
173
+
174
+ ## Shells
175
+
176
+ Run a stage task to build the image up to that stage and cache the image digest.
177
+
178
+ Run with the `:shell` suffix to build the image and then shell into an instance of the image running as a temporary container.
179
+
180
+ The default shell is `/bin/sh`, but this can be overridden at runtime with the task arg, eg. `rum build:shell[/bin/bash]`
181
+
182
+ ## Customize Shells
183
+
184
+ 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.
185
+
186
+ Customize the shell for a stage with the `shell` method:
187
+
188
+ ```ruby
189
+ rum :image_name do
190
+ stage :dev
191
+
192
+ shell :dev do
193
+ entrypoint "/bin/zsh"
194
+ rm false
195
+ volume "#{Dir.pwd}:/var/task/"
196
+ end
141
197
 
142
- artifact "pkg.zip" => :build # => docker run --env FIZZ=BUZZ ...
198
+ # rum dev => docker run --entrypoint /bin/zsh --volume $PWD:/var/task/ ...
143
199
  end
144
200
  ```
145
201
 
146
202
  ## Customize Stages
147
203
 
148
- Stages can be customized with blocks. Methods invoked on the stage are (with a few exceptions) passed onto the `docker build` command.
204
+ Stages can be customized with blocks:
149
205
 
150
206
  ```ruby
151
207
  rum :image_name do
@@ -164,6 +220,8 @@ rum :image_name do
164
220
  end
165
221
  ```
166
222
 
223
+ Methods invoked inside the stage block are interpreted as options for the eventual `docker build` command.
224
+
167
225
  ## Export Artifacts
168
226
 
169
227
  Use the `artifact` method to specify an artifact to be exported from the image.
@@ -189,35 +247,42 @@ rum :image_name do
189
247
  end
190
248
  ```
191
249
 
192
- ## Customize Shells
250
+ Methods invoked inside the artifact block are interpreted as options for the eventual `docker run` command.
193
251
 
194
- 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.
252
+ ## Default Task
195
253
 
196
- Customize the shell for a stage with the `shell` method:
254
+ Use the `default` method to set a default task when running the bare `rum` executable:
197
255
 
198
256
  ```ruby
199
257
  rum :image_name do
200
- stage :dev
258
+ stage :build
201
259
 
202
- shell :dev do
203
- entrypoint "/bin/zsh"
204
- rm false
205
- volume "#{Dir.pwd}:/var/task/"
206
- end
260
+ artifact "package.zip" => :build
261
+
262
+ default "package.zip"
207
263
  end
208
264
  ```
209
265
 
210
- ## Default Task
211
-
212
- Use the `default` method to set a default task when running `bundle exec rum`:
266
+ ## Integrate with Rake
213
267
 
268
+ 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:
214
269
 
215
270
  ```ruby
216
- rum :image_name do
217
- stage :build
271
+ # ./Rakefile
218
272
 
219
- artifact "package.zip" => :build
273
+ require "rumrunner"
220
274
 
221
- default "package.zip"
275
+ namespace :rum do
276
+ rum :image_name do
277
+ stage :build
278
+ stage :test => :build
279
+ end
222
280
  end
223
281
  ```
282
+
283
+ ```bash
284
+ $ rake --tasks
285
+
286
+ rake rum:build # ...
287
+ rake rum:test # ...
288
+ ```
@@ -14,17 +14,14 @@ module Rum
14
14
 
15
15
  # Put stages
16
16
  if File.exists? "Dockerfile"
17
- lines = File.read("Dockerfile").scan(/^FROM .*?$/)
18
- stages = lines.each_with_index.map do |line, i|
19
- line.scan(/ AS (.*?)$/).flatten.first || i.to_s
20
- end
17
+ stages = File.read("Dockerfile").scan(/^FROM .*? AS (.*?)$/).flatten
21
18
  stages.reverse.zip(stages.reverse[1..-1]).reverse.each do |stage, dep|
22
19
  if dep.nil?
23
20
  stdout.write " stage :\"#{stage}\"\n"
24
21
  else
25
22
  stdout.write " stage :\"#{stage}\" => :\"#{dep}\"\n"
26
23
  end
27
- end
24
+ end unless stages.empty?
28
25
  end
29
26
 
30
27
  # Fin
@@ -1,3 +1,3 @@
1
1
  module Rum
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
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.3
4
+ version: 0.2.4
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-22 00:00:00.000000000 Z
11
+ date: 2019-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -118,9 +118,10 @@ description: |
118
118
  specific stages for debugging, and export artifacts from built containers.
119
119
 
120
120
  Rum Runner has the following features:
121
- * Rake-like DSL/CLI that enable simple annotation and execution of builds.
122
- * Rumfiles are completely defined in standard Ruby syntax, like Rakefiles.
123
- * Users can chain Docker build stages with prerequisites.
121
+ * Fully compatible with Rake
122
+ * Rake-like DSL/CLI that enable simple annotation and execution of builds
123
+ * Rumfiles are completely defined in standard Ruby syntax, like Rakefiles
124
+ * Users can chain Docker build stages with prerequisites
124
125
  * Artifacts can be exported from stages
125
126
  * Shell tasks are automatically provided for every stage
126
127
  * Stage, artifact, and shell, steps can be customized