Skip to content

Instantly share code, notes, and snippets.

@intinig
Created March 30, 2015 13:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save intinig/06dba9f914cfb94e8c8d to your computer and use it in GitHub Desktop.
Save intinig/06dba9f914cfb94e8c8d to your computer and use it in GitHub Desktop.
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