Skip to content

Instantly share code, notes, and snippets.

@mtrense
Last active November 10, 2022 18:37
Show Gist options
  • Save mtrense/f325e04b291388bbb69f to your computer and use it in GitHub Desktop.
Save mtrense/f325e04b291388bbb69f to your computer and use it in GitHub Desktop.
Dynamically create Rake tasks for all Dockerfiles (following the convention "<name>.Dockerfile") in the current directory
require 'rake/file_list'
IMAGES = Rake::FileList['*.Dockerfile'].collect {|f| f[/.+(?=\.Dockerfile)/] }
namespace :images do
IMAGES.each do |name|
desc "Build image '#{name}'"
task "build_#{name}" do
sh "docker build -f #{name}.Dockerfile -t mtrense/#{name} ."
end
end
desc 'Build all images'
task build_all: IMAGES.collect {|i| "build_#{i}" }
end
desc 'Build all images'
task default: 'images:build_all'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment