Skip to content

Instantly share code, notes, and snippets.

@wshihadeh
Last active October 20, 2019 18:42
Show Gist options
  • Save wshihadeh/03c3f61f3e3cc841c27c55751ac8ce72 to your computer and use it in GitHub Desktop.
Save wshihadeh/03c3f61f3e3cc841c27c55751ac8ce72 to your computer and use it in GitHub Desktop.
Create docker files
require 'fileutils'
module RailsBaseImages
class Dockerfile
attr_accessor :ruby_version, :additional_pkgs
def initialize(attributes = {})
attributes.each do |key, value|
public_send("#{key}=", value)
end
end
def render
ERB.new(File.read("Dockerfile.erb")).result(binding)
end
end
end
class DockerFilesCreator
def config
@config ||= YAML.load_file("images.yml")
end
def call
config["images"].each do |image|
puts "Createing docker file for #{image['name']}"
docker_file_path = "#{image['name'].gsub!(':', '/')}"
dockerfile = Dockerfile.new(
ruby_version: image["ruby_version"],
additional_pkgs: image["additional_pkgs"],
install_gems: image["install_gems"],
).render
begin
FileUtils.mkdir_p(docker_file_path)
File.open("#{docker_file_path}/Dockerfile", 'w') { |file| file.write(dockerfile) }
rescue => e
puts "Failed: #{e.inspect}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment