#!/usr/bin/env ruby # Configure like so: # dockerfile: |- # RUN apk add --no-cache build-base git # RUN gem install gem_hadar bundler # # script: &script |- # ruby -v # rake test # # images: # ruby:3.0-alpine: *script # ruby:2.7-alpine: *script # ruby:2.6-alpine: *script # ruby:2.5-alpine: *script # ruby:2.4-alpine: *script # ruby:2.3-alpine: *script require 'yaml' require 'tmpdir' require 'fileutils' include FileUtils alias sh system def provide_image(image, dockerfile) tag = "all_images/#{image}" sh "docker pull '#{image}'" build_dir = File.join(Dir.tmpdir, 'build') mkdir_p build_dir cd build_dir do File.open('Dockerfile', 'w') do |t| t.puts <<~end FROM #{image} WORKDIR /work #{dockerfile} end end sh "docker build -t '#{tag}' ." end tag ensure rm_rf File.join(Dir.tmpdir, 'build') end def red(string) "\e[31m#{string}\e[0m" end def green(string) "\e[32m#{string}\e[0m" end config = YAML.load_file(ARGV.shift || '.all_images.yml') dockerfile = config['dockerfile'].to_s Array(config['images']).each do |image, script| tag = provide_image image, dockerfile if sh "docker run --name all_images -v `pwd`:/work '#{tag}' sh -c '#{script}'" puts green('SUCCESS') else puts red('FAILURE') end ensure sh 'docker rm -f all_images >/dev/null' end