Skip to content

Instantly share code, notes, and snippets.

@mtrense
Last active November 10, 2022 18:37
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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