AllImages - Runs a script in all of the docker images
Description π
AllImages is a Ruby-based command-line tool that automates running scripts across multiple Docker images. It provides a configuration-driven approach to testing and executing code in containerized environments, supporting both batch execution and interactive debugging.
Architecture Overview ποΈ
AllImages follows a well-defined architectural pattern with clear separation of concerns between several key components:
Core Components π§©
Application Class (AllImages::App)
- The central hub managing command-line interface, configuration loading, and Docker operations π
- Handles command processing and execution flow π¦
- Manages Docker image building, tagging, and cleanup π§
- Provides environment variable handling and error reporting π‘οΈ
Configuration Manager (AllImages::Config)
- Centralized configuration handling via YAML files π
- Manages default configuration generation and loading π
- Provides example configuration templates π
Component Interactions π
graph LR
A[AllImages::App] --> B[Configuration]
A --> C[Docker Operations]
A --> D[SearchUI]
B --> E[YAML Files]
C --> F[Docker Engine]
D --> G[User Interface]
The AllImages::App acts as the main coordinator, loading configuration files
and orchestrating Docker operations. The SearchUI enables interactive image
selection, while Docker operations handle the actual container execution.
Loading Mechanism π₯
AllImages supports automatic configuration file generation when none exists:
-
Automatic initialization when
.all_images.ymlis missing π¨ - Configuration loading from specified YAML files π
- Default configuration with example content provided π
Command Execution Flow π
AllImages supports multiple execution modes:
-
Batch execution: Run scripts across all configured images (
run_all) -
Selective execution: Run scripts on specific images (
run <image>) -
Interactive debugging: Debug scripts in containerized environments (
debug <image>) -
Listing: Display available images (
ls) -
Help: Show usage information (
help)
Use Case: Multi-Version Ruby Testing π§ͺ
AllImages is particularly useful for running tests/specs across different Ruby versions and platforms. This makes it an excellent tool for:
- Cross-version compatibility testing - Ensuring your code works across multiple Ruby versions
- Platform consistency verification - Testing on different operating systems and environments
- CI/CD pipeline automation - Automating test execution across multiple environments
- Dependency resolution testing - Verifying how your code behaves with different dependency versions
Example: Ruby Version Testing
dockerfile: |-
RUN apk add --no-cache build-base yaml-dev openssl-dev git
RUN gem update --system
RUN gem install bundler gem_hadar
script: &script |-
echo -e "\e[1m"
ruby -v
echo -e "\e[0m"
bundle update --all
bundle install --jobs=$(getconf _NPROCESSORS_ONLN)
rake spec
fail_fast: true
images:
ruby:3.4-alpine: *script
ruby:3.3-alpine: *script
ruby:3.2-alpine: *script
ruby:3.1-alpine: *scriptThis configuration automatically runs your test suite across Ruby 3.4, 3.3, 3.2, and 3.1, ensuring compatibility across versions.
Installation π¦
You can install AllImages via RubyGems:
gem install all_imagesOr add it to your Gemfile:
gem 'all_images'Usage π οΈ
Basic Workflow
- Run
all_imagesto generate a default.all_images.ymlconfiguration file - Customize the configuration file to define your Docker images and scripts
- Execute commands to run scripts across images
Command Examples π
# Run scripts across all configured images
all_images run_all
# Or
all_images
# Run script on a specific image
all_images run ruby:3.4-alpine
# Debug script in a specific image interactively
all_images debug ruby:3.4-alpine
# List available images
all_images ls
# Show help information
all_images helpConfiguration File Structure π
Given a configuration file like .all_images.yml:
dockerfile: |-
RUN apk add --no-cache build-base yaml-dev openssl-dev git
RUN gem update --system
RUN gem install bundler gem_hadar
script: &script |-
echo -e "\e[1m"
ruby -v
echo -e "\e[0m"
bundle update --all
bundle install --jobs=$(getconf _NPROCESSORS_ONLN)
rake spec
fail_fast: true
images:
ruby:3.4-alpine: *script
ruby:3.3-alpine: *script
ruby:3.2-alpine: *scriptEnvironment Variables π§ͺ
AllImages supports environment variable handling:
- Configuration-defined environment variables are passed to containers
-
TERMenvironment variable is automatically included if present - Variables can be specified in the configuration file using
envkey
Docker Integration π§
The tool automatically:
- Pulls base Docker images from Docker Hub
- Builds custom Docker images with scripts
- Runs containers with proper volume mounting
- Cleans up containers after execution
- Supports both interactive and non-interactive modes
Advanced Features π
Interactive Debugging π οΈ
# Start interactive session in container
all_images debug ruby:3.4-alpineThis provides a shell prompt inside the container for debugging scripts.
Failure Handling β οΈ
The fail_fast configuration option stops execution on first failure:
fail_fast: trueSearchable Image Selection π―
When no image is specified, AllImages provides an interactive search interface:
all_images run
# Shows searchable list of available imagesPre/Post Execution Hooks π
AllImages supports pre/post execution hooks in your configuration:
before: |-
echo π Preparingβ¦
echo Deleting Gemfile.lock
rm -f Gemfile.lock
after: |-
if [[ "$RESULT" = "1" ]]
then
echo π΅ Some tests failed!
else
echo π₯³ All tests passed!
fi
# ... rest of your configuration-
beforehook runs before each image execution -
afterhook runs after each image execution withRESULTenvironment variable -
RESULTindicates success (0) or failure (1) of the test script - Hooks are non-fatal (won't stop the workflow if they fail)
Error Handling β οΈ
AllImages provides comprehensive error handling for common scenarios:
Configuration Errors π
- Missing configuration file (automatically generates example)
- Invalid YAML syntax in configuration files
Docker Errors π§
- Failed Docker image pulls
- Build failures
- Container execution errors
Command Errors π¨
- Invalid command-line arguments
- Missing required parameters
Container Cleanup
AllImages ensures proper cleanup of Docker containers even on failures:
- Automatic removal of containers after execution
- Temporary build directories are cleaned up automatically
Logging
The tool provides colored output for better visibility:
- Success messages in green
- Failure messages in red
- Informational messages in white with blue background
Configuration βοΈ
Default Configuration
When no .all_images.yml file exists, AllImages generates a default
configuration with example content:
dockerfile: |-
RUN apk add --no-cache build-base yaml-dev openssl-dev git
RUN gem update --system
RUN gem install bundler gem_hadar
script: &script |-
echo -e "\e[1m"
ruby -v
echo -e "\e[0m"
bundle update --all
bundle install --jobs=$(getconf _NPROCESSORS_ONLN)
rake spec
fail_fast: true
images:
ruby:3.4-alpine: *script
ruby:3.3-alpine: *script
ruby:3.2-alpine: *scriptSecurity Considerations β οΈ
Docker Security
- Containers run with mounted current directory for script access
- Temporary build directories are cleaned up automatically
- No privileged operations are performed
Script Security
- Scripts are executed within isolated Docker containers
- No direct access to host system (except mounted directories)
- Container cleanup ensures no residual artifacts
Download π₯
The homepage of this library is located at
Author π¨βπ»
License π
This software is licensed under the MIT license