Skip to content

Instantly share code, notes, and snippets.

@intinig

intinig/docker.rake

Created Mar 30, 2015
Embed
What would you like to do?
namespace :docker do
desc "Build docker images"
task :build do |t, args|
require 'securerandom'
images = ENV['IMAGES']
images = images.split ","
root = File.expand_path("../../../", __FILE__)
filename = File.join(root, "Dockerfile")
git_revision = `git rev-parse --short HEAD`.strip
dockerfile = File.read(filename)
secret_key = SecureRandom.hex(64)
dockerfile.gsub!(/ENV GIT_REVISION .*\n/, "ENV GIT_REVISION #{git_revision}\n")
dockerfile.gsub!(/ENV SECRET_KEY_BASE .*\n/, "ENV SECRET_KEY_BASE #{secret_key}\n")
File.open(filename, "w") {|f| f.puts dockerfile}
images.each do |img|
path = (img == "app_name") ? root : File.join(root, "container", img)
remote_img = (img == "app_name") ? "app_name" : "app_name-#{img}"
system "docker build -t 'quay.io/mikamai/#{remote_img}' #{path}"
end
end
desc "Push docker images"
task :push do |t, args|
images = ENV['IMAGES'] || "rgts"
images = images.split ","
root = File.expand_path("../../../", __FILE__)
images.each do |img|
remote_img = (img == "rgts") ? "rgts" : "rgts-#{img}"
system "docker push 'quay.io/mikamai/#{remote_img}'"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.