all_images 0.5.0 → 0.7.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 +4 -4
- data/.utilsrc +3 -4
- data/CHANGES.md +42 -10
- data/Rakefile +7 -6
- data/all_images.gemspec +8 -7
- data/lib/all_images/app.rb +197 -24
- data/lib/all_images/config.rb +33 -8
- data/lib/all_images/version.rb +1 -1
- data/lib/all_images.rb +11 -0
- data/spec/spec_helper.rb +2 -6
- metadata +25 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42b558d4ade42f9b21753fda5785174363fa80a5ffd8ff1989e7976250d249f1
|
4
|
+
data.tar.gz: 9291ccd0e8c4395825cd2bd4dd0123f5c84f62e5af15405affbec47eaf43d692
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b98d326311eb1fb12ced669ab1134a473a12d985118c8ff66911bee5282f17c1f09a92ace674c7d14f78a571212b78113fc11592b8612fc5c19f21a503329c37
|
7
|
+
data.tar.gz: a3e3fd149747181efd18dd8283f7591a0cf8a39b32ae1b5dffea51fd19c0b14864eb3306e0478723a22555845c89d46c2c2015b7fd85a9c708ed37b7b495bb24
|
data/.utilsrc
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
# vim: set ft=ruby:
|
2
2
|
|
3
3
|
search do
|
4
|
-
prune_dirs /\A(\.svn|\.git|CVS|tmp|tags|coverage|pkg)\z/
|
4
|
+
prune_dirs /\A(\.svn|\.git|CVS|tmp|tags|coverage|pkg|\.yardoc)\z/
|
5
5
|
skip_files /(\A\.|\.sw[pon]\z|\.(log|fnm|jpg|jpeg|png|pdf|svg)\z|tags|~\z)/i
|
6
6
|
end
|
7
7
|
|
8
8
|
discover do
|
9
|
-
prune_dirs /\A(\.svn|\.git|CVS|tmp|tags|coverage|pkg)\z/
|
9
|
+
prune_dirs /\A(\.svn|\.git|CVS|tmp|tags|coverage|pkg|\.yardoc)\z/
|
10
10
|
skip_files /(\A\.|\.sw[pon]\z|\.log\z|~\z)/
|
11
|
-
binary false
|
12
11
|
end
|
13
12
|
|
14
13
|
strip_spaces do
|
15
|
-
prune_dirs /\A(\..*|CVS|pkg)\z/
|
14
|
+
prune_dirs /\A(\..*|CVS|pkg|\.yardoc)\z/
|
16
15
|
skip_files /(\A\.|\.sw[pon]\z|\.log\z|~\z)/
|
17
16
|
end
|
18
17
|
|
data/CHANGES.md
CHANGED
@@ -1,9 +1,41 @@
|
|
1
1
|
# Changes
|
2
2
|
|
3
|
+
## 2025-09-03 v0.7.0
|
4
|
+
|
5
|
+
- **Interactive Image Selection**: Integrated `SearchUI` for enhanced user
|
6
|
+
experience when selecting Docker images
|
7
|
+
- **Improved Configuration Handling**: Better error handling and fallback
|
8
|
+
mechanisms for configuration loading
|
9
|
+
- Removed support for Ruby **3.0** and **3.1**
|
10
|
+
- Added support for Ruby **3.4** with `ruby:3.4-alpine` image configuration
|
11
|
+
- Simplified SimpleCov setup using `GemHadar::SimpleCov.start`
|
12
|
+
- Removed obsolete `binary` option from utils config
|
13
|
+
- Added comprehensive documentation across the library
|
14
|
+
- Improved logging with `info_puts` method for colored console output
|
15
|
+
|
16
|
+
## 2024-10-14 v0.6.0
|
17
|
+
|
18
|
+
### Significant Changes
|
19
|
+
* **Add support for environment variables to all_images**
|
20
|
+
+ Require `'tins/xt/full'` and add new method `env` to set environment variables.
|
21
|
+
+ Modified the `sh` method to use environment variables from the `env` method.
|
22
|
+
+ Modified the `run_image` method to include environment variables in the Docker command.
|
23
|
+
* Update rake task to use spec instead of test
|
24
|
+
* Added `[IMAGE]` as an optional argument in the Usage message.
|
25
|
+
|
26
|
+
### Other Changes
|
27
|
+
* Reformat CHANGES.md
|
28
|
+
* Add error reporting to `sh`
|
29
|
+
+ Added require `'shellwords'`
|
30
|
+
|
31
|
+
#### Environment Variables
|
32
|
+
* Added `env` section to `.all_images.yml`
|
33
|
+
* Defined `FOO=bar` and `USER` environment variables
|
34
|
+
|
3
35
|
## 2024-09-01 v0.5.0
|
4
36
|
|
5
37
|
* **Update image processing for parallel execution**:
|
6
|
-
|
38
|
+
+ Added random suffix to image names to prevent conflicts between concurrent processes.
|
7
39
|
* Added `CHANGES.md` file
|
8
40
|
|
9
41
|
## 2024-08-08 v0.4.1
|
@@ -31,20 +63,20 @@
|
|
31
63
|
## 2023-06-01 v0.2.3
|
32
64
|
|
33
65
|
* **New Features**
|
34
|
-
|
66
|
+
+ Added support for Ruby 3.2
|
35
67
|
* **Changes**
|
36
|
-
|
37
|
-
|
68
|
+
+ Bumped build version
|
69
|
+
+ Removed support for Ruby 2.5
|
38
70
|
* **Bug Fixes**
|
39
|
-
|
71
|
+
+ Repaired `fail_fast` mode
|
40
72
|
|
41
73
|
## 2023-04-19 v0.2.2
|
42
74
|
|
43
75
|
* **New Version Features**
|
44
|
-
|
45
|
-
|
76
|
+
+ Progress into the future of ruby development
|
77
|
+
+ Progress into the future
|
46
78
|
* **Significant Changes**
|
47
|
-
|
79
|
+
+ Removed development dependency (again)
|
48
80
|
|
49
81
|
## 2022-11-17 v0.2.1
|
50
82
|
|
@@ -53,8 +85,8 @@
|
|
53
85
|
## 2022-11-17 v0.2.0
|
54
86
|
|
55
87
|
* **New Features**
|
56
|
-
|
57
|
-
|
88
|
+
+ Added commands to run and debug single images
|
89
|
+
+ Added a debug debugger feature
|
58
90
|
|
59
91
|
## 2022-11-17 v0.1.0
|
60
92
|
|
data/Rakefile
CHANGED
@@ -10,18 +10,19 @@ GemHadar do
|
|
10
10
|
summary 'Runs a script in all of the docker images'
|
11
11
|
description 'A script that runs a script in all of the configured docker images'
|
12
12
|
test_dir 'spec'
|
13
|
-
ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', 'coverage',
|
14
|
-
'.AppleDouble', 'tags', '.DS_Store'
|
15
13
|
readme 'README.md'
|
16
14
|
title "#{name.camelize} -- #{summary}"
|
15
|
+
licenses << 'MIT'
|
16
|
+
executables << 'all_images'
|
17
|
+
ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', 'coverage',
|
18
|
+
'.AppleDouble', 'tags', '.DS_Store', '.yardoc'
|
17
19
|
package_ignore '.all_images.yml', '.gitignore', 'VERSION'
|
18
20
|
|
19
|
-
dependency 'tins',
|
20
|
-
dependency '
|
21
|
+
dependency 'tins', '~> 1.42'
|
22
|
+
dependency 'search_ui', '~> 0.0'
|
23
|
+
dependency 'term-ansicolor', '~> 1.11'
|
21
24
|
development_dependency 'rake'
|
22
25
|
development_dependency 'simplecov'
|
23
26
|
development_dependency 'rspec'
|
24
27
|
development_dependency 'debug'
|
25
|
-
licenses << 'MIT'
|
26
|
-
executables << 'all_images'
|
27
28
|
end
|
data/all_images.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: all_images 0.
|
2
|
+
# stub: all_images 0.7.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "all_images".freeze
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.7.0".freeze
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Florian Frank".freeze]
|
11
|
-
s.date = "
|
11
|
+
s.date = "1980-01-02"
|
12
12
|
s.description = "A script that runs a script in all of the configured docker images".freeze
|
13
13
|
s.email = "flori@ping.de".freeze
|
14
14
|
s.executables = ["all_images".freeze]
|
@@ -17,17 +17,18 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.homepage = "https://github.com/flori/all_images".freeze
|
18
18
|
s.licenses = ["MIT".freeze]
|
19
19
|
s.rdoc_options = ["--title".freeze, "AllImages -- Runs a script in all of the docker images".freeze, "--main".freeze, "README.md".freeze]
|
20
|
-
s.rubygems_version = "3.
|
20
|
+
s.rubygems_version = "3.6.9".freeze
|
21
21
|
s.summary = "Runs a script in all of the docker images".freeze
|
22
22
|
s.test_files = ["spec/app_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
23
23
|
|
24
24
|
s.specification_version = 4
|
25
25
|
|
26
|
-
s.add_development_dependency(%q<gem_hadar>.freeze, ["~>
|
26
|
+
s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 2.2".freeze])
|
27
27
|
s.add_development_dependency(%q<rake>.freeze, [">= 0".freeze])
|
28
28
|
s.add_development_dependency(%q<simplecov>.freeze, [">= 0".freeze])
|
29
29
|
s.add_development_dependency(%q<rspec>.freeze, [">= 0".freeze])
|
30
30
|
s.add_development_dependency(%q<debug>.freeze, [">= 0".freeze])
|
31
|
-
s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.
|
32
|
-
s.add_runtime_dependency(%q<
|
31
|
+
s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.42".freeze])
|
32
|
+
s.add_runtime_dependency(%q<search_ui>.freeze, ["~> 0.0".freeze])
|
33
|
+
s.add_runtime_dependency(%q<term-ansicolor>.freeze, ["~> 1.11".freeze])
|
33
34
|
end
|
data/lib/all_images/app.rb
CHANGED
@@ -2,31 +2,62 @@ require 'term/ansicolor'
|
|
2
2
|
require 'tmpdir'
|
3
3
|
require 'fileutils'
|
4
4
|
require 'tins'
|
5
|
+
require 'tins/xt/full'
|
6
|
+
require 'shellwords'
|
7
|
+
require 'search_ui'
|
5
8
|
|
9
|
+
# AllImages::App is the core application class that orchestrates Docker image
|
10
|
+
# execution workflows
|
11
|
+
#
|
12
|
+
# This class provides the main interface for running scripts across multiple
|
13
|
+
# Docker images, handling configuration loading, command processing, and Docker
|
14
|
+
# container operations.
|
15
|
+
#
|
16
|
+
# It supports various commands including listing available images, running all
|
17
|
+
# images, running specific images, and debugging interactive sessions.
|
18
|
+
#
|
19
|
+
# The application manages Docker image building, tagging, and cleanup while
|
20
|
+
# providing environment variable handling and error reporting capabilities.
|
6
21
|
class AllImages::App
|
7
22
|
include Term::ANSIColor
|
8
23
|
include FileUtils
|
24
|
+
include SearchUI
|
9
25
|
|
10
|
-
|
11
|
-
|
26
|
+
# Initializes a new instance of the AllImages application
|
27
|
+
#
|
28
|
+
# Sets up the application with the provided command-line arguments,
|
29
|
+
# determines the initial command to execute, and prepares internal state
|
30
|
+
# for processing configuration and Docker image operations.
|
31
|
+
#
|
32
|
+
# @param args [ Array<String> ] the command-line arguments passed to the
|
33
|
+
# application
|
12
34
|
def initialize(args)
|
13
35
|
@args = args.dup
|
36
|
+
@config = load_config or return 23
|
14
37
|
@command = pick_command
|
15
38
|
@commands = %w[ ls help run debug run_all ].sort
|
16
39
|
@suffix = Tins::Token.new(alphabet: Tins::Token::BASE32_ALPHABET, bits: 32)
|
17
40
|
end
|
18
41
|
|
42
|
+
# Executes the configured command across Docker images
|
43
|
+
#
|
44
|
+
# Processes the specified command and runs it against the configured Docker
|
45
|
+
# images. Depending on the command, this method may list available images,
|
46
|
+
# display help information, or execute scripts in containers. It handles both
|
47
|
+
# individual image execution and batch processing of all configured images.
|
48
|
+
#
|
49
|
+
# @return [ Integer ] the cumulative result code from executing commands
|
50
|
+
# across images, where 0 indicates success and non-zero values indicate
|
51
|
+
# failures
|
19
52
|
def run
|
20
|
-
|
21
|
-
|
22
|
-
result = 0
|
53
|
+
result = 0
|
23
54
|
case @command
|
24
55
|
when 'ls'
|
25
|
-
puts
|
56
|
+
puts images.map(&:first)
|
26
57
|
when 'help'
|
27
|
-
puts "Usage: #{File.basename($0)} #{@commands * ?|} IMAGE"
|
58
|
+
puts "Usage: #{File.basename($0)} #{@commands * ?|} [IMAGE]"
|
28
59
|
else
|
29
|
-
|
60
|
+
images.each do |image, script|
|
30
61
|
case @command
|
31
62
|
when 'run_all'
|
32
63
|
result |= run_image(image, script)
|
@@ -45,23 +76,110 @@ class AllImages::App
|
|
45
76
|
|
46
77
|
private
|
47
78
|
|
79
|
+
# Returns an array of configured Docker images for execution
|
80
|
+
#
|
81
|
+
# This method retrieves the list of Docker images from the application's
|
82
|
+
# configuration and ensures it is returned as an Array instance, even if the
|
83
|
+
# configuration contains a single image value rather than an array.
|
84
|
+
#
|
85
|
+
# @return [ Array<String> ] an array containing the names of Docker images
|
86
|
+
# to be processed by the application
|
87
|
+
def images
|
88
|
+
Array(@config['images'])
|
89
|
+
end
|
90
|
+
|
91
|
+
# Prints the given text using green colored output
|
92
|
+
#
|
93
|
+
# @param text [ String ] the text to be printed with color formatting
|
94
|
+
def info_puts(text)
|
95
|
+
puts white { on_color(28) { text } }
|
96
|
+
end
|
97
|
+
|
98
|
+
# Returns a hash of environment variables for Docker container execution
|
99
|
+
#
|
100
|
+
# This method constructs a set of environment variables by combining those
|
101
|
+
# specified in the configuration file with any terminal-related variables
|
102
|
+
# from the current environment, ensuring proper variable expansion and
|
103
|
+
# assignment for use in Docker container runs.
|
104
|
+
#
|
105
|
+
# @return [ Hash ] a hash mapping environment variable names to their values
|
106
|
+
def env
|
107
|
+
vars = @config.fetch('env', [])
|
108
|
+
vars << 'TERM' if ENV.key?('TERM')
|
109
|
+
vars.each_with_object({}) { |v, h|
|
110
|
+
name, value = v.split(?=, 2)
|
111
|
+
if value
|
112
|
+
h[name] = value
|
113
|
+
else
|
114
|
+
h[name] = ENV[name]
|
115
|
+
end
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
# Executes a system command and handles its result
|
120
|
+
#
|
121
|
+
# This method runs a given system command with the provided arguments,
|
122
|
+
# optionally logging the execution when debug mode is enabled. It checks the
|
123
|
+
# command's exit status and raises an exception if the command fails,
|
124
|
+
# otherwise returning true to indicate success.
|
125
|
+
#
|
126
|
+
# @param a [ Array<String> ] the command and its arguments to be executed
|
127
|
+
#
|
128
|
+
# @return [ TrueClass ] when the command executes successfully
|
129
|
+
#
|
130
|
+
# @raise [ RuntimeError ] if the executed command exits with a non-zero status
|
131
|
+
def sh(*a)
|
132
|
+
if $DEBUG
|
133
|
+
STDERR.puts "Executing #{a.inspect}."
|
134
|
+
end
|
135
|
+
system(*a)
|
136
|
+
if $?.success?
|
137
|
+
true
|
138
|
+
else
|
139
|
+
raise "Command #{Shellwords.join(a).inspect} failed with: #{$?.exitstatus}"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# Generates a unique name for Docker container operations
|
144
|
+
#
|
145
|
+
# Creates a name by combining the fixed prefix "all_images" with a randomly
|
146
|
+
# generated suffix, separated by a hyphen, for use in Docker container
|
147
|
+
# identification and cleanup.
|
148
|
+
#
|
149
|
+
# @return [ String ] a unique identifier suitable for Docker container naming
|
48
150
|
def name
|
49
151
|
[ 'all_images', @suffix ] * ?-
|
50
152
|
end
|
51
153
|
|
154
|
+
# Executes a Docker image with the specified script in a container
|
155
|
+
#
|
156
|
+
# This method builds a Docker image based on the provided configuration,
|
157
|
+
# runs the script inside the container, and handles both interactive and
|
158
|
+
# non-interactive execution modes. It ensures cleanup of the container
|
159
|
+
# afterward regardless of success or failure.
|
160
|
+
#
|
161
|
+
# @param image [ String ] the Docker image name to use for execution
|
162
|
+
# @param script [ String ] the script content to be executed within the container
|
163
|
+
# @param interactive [ TrueClass, FalseClass ] flag indicating whether to run
|
164
|
+
# the container interactively or in non-interactive mode
|
165
|
+
#
|
166
|
+
# @return [ Integer ] exit code indicating success (0) or failure (1) of the script execution
|
52
167
|
def run_image(image, script, interactive: false)
|
53
168
|
dockerfile = @config.fetch('dockerfile').to_s
|
54
|
-
tag
|
55
|
-
|
169
|
+
tag = provide_image image, dockerfile, script
|
170
|
+
envs = env.full? { |e| +' ' << e.map { |n, v| '-e %s=%s' % [ n, v.inspect ] } * ' ' }
|
56
171
|
if interactive
|
57
172
|
puts "You can run /script interactively now."
|
58
|
-
sh "docker run --name #{name} -it
|
173
|
+
sh "docker run --name #{name} -it#{envs} -v `pwd`:/work '#{tag}' sh"
|
59
174
|
return 0
|
60
175
|
else
|
61
|
-
|
176
|
+
info_puts "Running container #{name.inspect} for image tagged #{tag.inspect}."
|
177
|
+
if sh "docker run --name #{name} -it#{envs} -v `pwd`:/work '#{tag}' sh -c /script"
|
178
|
+
info_puts "Image tagged #{tag.inspect} was run with result:"
|
62
179
|
puts green('SUCCESS')
|
63
180
|
return 0
|
64
181
|
else
|
182
|
+
info_puts "Image tagged #{tag.inspect} was run with result:"
|
65
183
|
puts red('FAILURE')
|
66
184
|
return 1
|
67
185
|
end
|
@@ -70,6 +188,41 @@ class AllImages::App
|
|
70
188
|
sh "docker rm -f #{name} >/dev/null"
|
71
189
|
end
|
72
190
|
|
191
|
+
# Presents a searchable interface for selecting a configured Docker image
|
192
|
+
#
|
193
|
+
# This method initializes and starts a search UI that allows users to
|
194
|
+
# interactively pick a Docker image from the list of configured images. It
|
195
|
+
# provides filtering capabilities based on user input and displays the
|
196
|
+
# options with visual highlighting for the selected item.
|
197
|
+
#
|
198
|
+
# @return [ String ] the name of the selected Docker image
|
199
|
+
def pick_configured_image
|
200
|
+
Search.new(
|
201
|
+
prompt: 'Pick a configured container image: ',
|
202
|
+
match: -> answer {
|
203
|
+
matches = images.map(&:first).grep(/#{Regexp.quote(answer)}/)
|
204
|
+
matches.empty? and matches = images
|
205
|
+
matches.first(Tins::Terminal.lines - 1)
|
206
|
+
},
|
207
|
+
query: -> _answer, matches, selector {
|
208
|
+
matches.each_with_index.map { |m, i|
|
209
|
+
i == selector ? "#{blue{?⮕}} #{on_blue{bold{m}}}" : " #{m.to_s}"
|
210
|
+
} * ?\n
|
211
|
+
},
|
212
|
+
found: -> _answer, matches, selector {
|
213
|
+
matches[selector]
|
214
|
+
},
|
215
|
+
output: STDOUT
|
216
|
+
).start
|
217
|
+
end
|
218
|
+
|
219
|
+
# Determines the command to execute based on the provided arguments
|
220
|
+
#
|
221
|
+
# Processes the command-line arguments to identify the intended operation,
|
222
|
+
# handling cases for running all images, listing images, running a specific
|
223
|
+
# image, debugging a specific image, or displaying help information.
|
224
|
+
#
|
225
|
+
# @return [ String ] the determined command to be executed
|
73
226
|
def pick_command
|
74
227
|
case command = @args.shift
|
75
228
|
when 'run_all', nil
|
@@ -77,32 +230,51 @@ class AllImages::App
|
|
77
230
|
when 'ls'
|
78
231
|
'ls'
|
79
232
|
when 'run'
|
80
|
-
@selected = @args.shift
|
233
|
+
@selected = @args.shift || pick_configured_image
|
234
|
+
@selected or fail "Usage: #{File.basename($0)} #{command} IMAGE"
|
81
235
|
'run_selected'
|
82
236
|
when 'debug'
|
83
|
-
@selected = @args.shift
|
237
|
+
@selected = @args.shift || pick_configured_image
|
238
|
+
@selected or fail "Usage: #{File.basename($0)} #{command} IMAGE"
|
84
239
|
'debug_selected'
|
85
240
|
else
|
86
241
|
'help'
|
87
242
|
end
|
88
243
|
end
|
89
244
|
|
245
|
+
# Loads and processes the configuration file for the AllImages application
|
246
|
+
#
|
247
|
+
# This method determines the appropriate configuration file to load based on
|
248
|
+
# command-line arguments or defaults to .all_images.yml. If the file doesn't exist
|
249
|
+
# and no alternative is provided, it initializes a default configuration file
|
250
|
+
# and displays an example for customization before exiting.
|
251
|
+
#
|
252
|
+
# @return [ Object, nil ] the parsed configuration hash if successful, or nil if
|
253
|
+
# initialization occurred and the method should terminate early
|
90
254
|
def load_config
|
91
255
|
config_filename = '.all_images.yml'
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
return
|
99
|
-
end
|
100
|
-
else
|
101
|
-
config_filename = @args.shift
|
256
|
+
unless File.exist?(config_filename)
|
257
|
+
AllImages::Config.init(config_filename)
|
258
|
+
puts bold("Config file #{config_filename} not found!\n\n") +
|
259
|
+
"The following example was created, adapt to your own needs:\n\n",
|
260
|
+
AllImages::Config.example, ""
|
261
|
+
return
|
102
262
|
end
|
103
263
|
AllImages::Config.load(config_filename)
|
104
264
|
end
|
105
265
|
|
266
|
+
# Prepares a Docker image for execution by pulling, building, and tagging it
|
267
|
+
#
|
268
|
+
# This method ensures that the specified Docker image is available locally,
|
269
|
+
# creates a temporary build environment, generates a Dockerfile with the
|
270
|
+
# provided configuration and script, builds the image with a unique tag, and
|
271
|
+
# cleans up the temporary files afterward.
|
272
|
+
#
|
273
|
+
# @param image [ String ] the base Docker image name to pull and use for building
|
274
|
+
# @param dockerfile [ String ] additional Dockerfile instructions to include in the build
|
275
|
+
# @param script [ String ] the script content that will be copied into the built image
|
276
|
+
#
|
277
|
+
# @return [ String ] the unique tag assigned to the newly built Docker image
|
106
278
|
def provide_image(image, dockerfile, script)
|
107
279
|
prefix = @config.fetch('prefix', File.basename(Dir.pwd))
|
108
280
|
tag = "#{prefix}/all_images/#{image}"
|
@@ -124,6 +296,7 @@ class AllImages::App
|
|
124
296
|
COPY --chmod=755 script /script
|
125
297
|
end
|
126
298
|
end
|
299
|
+
info_puts "Now building image #{tag.inspect}…"
|
127
300
|
sh "docker build --pull -t '#{tag}' ."
|
128
301
|
end
|
129
302
|
tag
|
data/lib/all_images/config.rb
CHANGED
@@ -1,15 +1,25 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
|
+
# Configuration handling for AllImages
|
4
|
+
#
|
5
|
+
# Provides functionality for loading, initializing, and accessing example
|
6
|
+
# configuration files used by the AllImages application to define Docker image
|
7
|
+
# build and execution parameters.
|
3
8
|
module AllImages::Config
|
9
|
+
# Loads and parses a YAML configuration file
|
10
|
+
#
|
11
|
+
# @param filename [ String ] the path to the YAML file to load
|
12
|
+
#
|
13
|
+
# @return [ Object ] the parsed YAML content as a Ruby object
|
4
14
|
def load(filename)
|
5
15
|
YAML.unsafe_load_file(filename)
|
6
16
|
end
|
7
17
|
|
8
|
-
|
18
|
+
# Example configuration for `all_images`.
|
19
|
+
EXAMPLE = <<~EOT
|
9
20
|
dockerfile: |-
|
10
|
-
RUN apk add --no-cache build-base git
|
11
|
-
RUN gem
|
12
|
-
RUN gem install gem_hadar bundler
|
21
|
+
RUN apk add --no-cache build-base yaml-dev git
|
22
|
+
RUN gem install gem_hadar
|
13
23
|
|
14
24
|
script: &script |-
|
15
25
|
echo -e "\\e[1m"
|
@@ -19,18 +29,33 @@ module AllImages::Config
|
|
19
29
|
rake test
|
20
30
|
|
21
31
|
images:
|
32
|
+
ruby:3.4-alpine: *script
|
22
33
|
ruby:3.3-alpine: *script
|
23
34
|
ruby:3.2-alpine: *script
|
24
|
-
|
25
|
-
ruby:3.0-alpine: *script
|
26
|
-
end
|
35
|
+
EOT
|
27
36
|
|
37
|
+
# Initializes a configuration file with example content
|
38
|
+
#
|
39
|
+
# Creates a new configuration file at the specified path and writes example
|
40
|
+
# configuration content to it. This method is typically used when no existing
|
41
|
+
# configuration file is found, providing a starting point for users to
|
42
|
+
# customize.
|
43
|
+
#
|
44
|
+
# @param filename [ String ] the path where the example configuration file
|
45
|
+
# will be created
|
28
46
|
def init(filename)
|
29
|
-
File.open(filename,
|
47
|
+
File.open(filename, ?w) do |output|
|
30
48
|
output.print EXAMPLE
|
31
49
|
end
|
32
50
|
end
|
33
51
|
|
52
|
+
# Returns the example configuration content
|
53
|
+
#
|
54
|
+
# This method provides access to the predefined example configuration
|
55
|
+
# that can be used to initialize a new configuration file.
|
56
|
+
#
|
57
|
+
# @return [ String ] the multi-line string containing the example configuration
|
58
|
+
# structure and default settings
|
34
59
|
def example
|
35
60
|
EXAMPLE
|
36
61
|
end
|
data/lib/all_images/version.rb
CHANGED
data/lib/all_images.rb
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
# AllImages is a Ruby library that provides functionality for managing and
|
2
|
+
# executing scripts across multiple Docker images.
|
3
|
+
#
|
4
|
+
# It offers a command-line interface for running automated tasks in
|
5
|
+
# containerized environments, supporting configuration-driven execution, image
|
6
|
+
# building, and interactive debugging.
|
7
|
+
#
|
8
|
+
# The library includes modules for handling configuration files, managing
|
9
|
+
# Docker image operations, and providing a user-friendly interface for
|
10
|
+
# developers to test their code across different environments without manual
|
11
|
+
# setup.
|
1
12
|
module AllImages
|
2
13
|
end
|
3
14
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: all_images
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: gem_hadar
|
@@ -16,14 +15,14 @@ dependencies:
|
|
16
15
|
requirements:
|
17
16
|
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
18
|
+
version: '2.2'
|
20
19
|
type: :development
|
21
20
|
prerelease: false
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
23
|
- - "~>"
|
25
24
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
25
|
+
version: '2.2'
|
27
26
|
- !ruby/object:Gem::Dependency
|
28
27
|
name: rake
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,28 +85,42 @@ dependencies:
|
|
86
85
|
requirements:
|
87
86
|
- - "~>"
|
88
87
|
- !ruby/object:Gem::Version
|
89
|
-
version: '1.
|
88
|
+
version: '1.42'
|
90
89
|
type: :runtime
|
91
90
|
prerelease: false
|
92
91
|
version_requirements: !ruby/object:Gem::Requirement
|
93
92
|
requirements:
|
94
93
|
- - "~>"
|
95
94
|
- !ruby/object:Gem::Version
|
96
|
-
version: '1.
|
95
|
+
version: '1.42'
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: search_ui
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0.0'
|
103
|
+
type: :runtime
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0.0'
|
97
110
|
- !ruby/object:Gem::Dependency
|
98
111
|
name: term-ansicolor
|
99
112
|
requirement: !ruby/object:Gem::Requirement
|
100
113
|
requirements:
|
101
|
-
- - "
|
114
|
+
- - "~>"
|
102
115
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
116
|
+
version: '1.11'
|
104
117
|
type: :runtime
|
105
118
|
prerelease: false
|
106
119
|
version_requirements: !ruby/object:Gem::Requirement
|
107
120
|
requirements:
|
108
|
-
- - "
|
121
|
+
- - "~>"
|
109
122
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
123
|
+
version: '1.11'
|
111
124
|
description: A script that runs a script in all of the configured docker images
|
112
125
|
email: flori@ping.de
|
113
126
|
executables:
|
@@ -138,7 +151,6 @@ homepage: https://github.com/flori/all_images
|
|
138
151
|
licenses:
|
139
152
|
- MIT
|
140
153
|
metadata: {}
|
141
|
-
post_install_message:
|
142
154
|
rdoc_options:
|
143
155
|
- "--title"
|
144
156
|
- AllImages -- Runs a script in all of the docker images
|
@@ -157,8 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
169
|
- !ruby/object:Gem::Version
|
158
170
|
version: '0'
|
159
171
|
requirements: []
|
160
|
-
rubygems_version: 3.
|
161
|
-
signing_key:
|
172
|
+
rubygems_version: 3.6.9
|
162
173
|
specification_version: 4
|
163
174
|
summary: Runs a script in all of the docker images
|
164
175
|
test_files:
|