module DockerMgr::Util
Public Instance Methods
add_line_to_routine(routine,line)
click to toggle source
# File lib/util.rb, line 136 def add_line_to_routine(routine,line) File.open("#{routine_dir}/#{routine}",'a') { | file | file.write("#{line}\n") } end
add_packages(path,*packages)
click to toggle source
# File lib/util.rb, line 174 def add_packages(path,*packages) packages.each_with_index do |package,index| FileUtils.cp("#{install_dir}/install_#{package}.sh", "#{path}/administration/installation/#{index}_install_#{package}.sh") end FileUtils.cp("#{install_dir}/scriptrunner.sh", "#{path}/administration/scriptrunner.sh") end
add_trust(path)
click to toggle source
# File lib/util.rb, line 182 def add_trust(path) FileUtils.cp("#{admin_dir}/trust.sh", "#{path}/administration/trust.sh") empty_directory("#{path}/administration/certificates") end
admin_dir()
click to toggle source
# File lib/util.rb, line 48 def admin_dir "#{root_dir}/admin" end
apps_dir()
click to toggle source
# File lib/util.rb, line 44 def apps_dir "#{root_dir}/apps" end
attic_dir()
click to toggle source
# File lib/util.rb, line 40 def attic_dir "#{root_dir}/attic" end
backup_dir()
click to toggle source
# File lib/util.rb, line 27 def backup_dir "#{root_dir}/backup" end
base_images_dir()
click to toggle source
# File lib/util.rb, line 31 def base_images_dir "#{root_dir}/base_images" end
cert_dir()
click to toggle source
# File lib/util.rb, line 66 def cert_dir "#{proxy_dir}/ca_certs" end
config()
click to toggle source
# File lib/util.rb, line 74 def config if File.exist? "#{admin_dir}/config.yml" YAML.load_file "#{admin_dir}/config.yml" else result = Hash.new result[:email] = extract_email result[:name] = extract_name host = "#{result[:name].gsub(/\s/,'-').downcase}.de" puts "pleas enter your host-name (#{host})" choice = STDIN.gets.chomp result[:host] = choice.empty? ? host : choice File.write "#{admin_dir}/config.yml", result.to_yaml result end end
data_services(app_name)
click to toggle source
# File lib/util.rb, line 106 def data_services(app_name) YAML.load(File.read("#{apps_dir}/#{app_name}/docker-compose.yml")).each_key .select {|k| k.end_with?("data")} end
exec_hook(app_name,type,hook_name)
click to toggle source
# File lib/util.rb, line 120 def exec_hook(app_name,type,hook_name) if File.exist? "#{apps_dir}/#{app_name}/administration/hooks/#{type}.d/#{hook_name}" `#{apps_dir}/#{app_name}/administration/hooks/#{type}.d/#{hook_name}` end end
extract_date(entry)
click to toggle source
# File lib/util.rb, line 91 def extract_date(entry) /_\d+\./.match(entry).to_s.chop[1..-1].to_i end
extract_email()
click to toggle source
# File lib/util.rb, line 151 def extract_email extract_git_variable("user.email") end
extract_git_variable(name)
click to toggle source
# File lib/util.rb, line 141 def extract_git_variable(name) git_config = `git config --list` result = git_config.lines.grep(/#{Regexp.quote(name)}/).map{|e| e.split('=')[1].chomp }.first unless result puts "please enter your #{name.split('.')[1]}" result = STDIN.gets.chomp end result end
extract_name()
click to toggle source
# File lib/util.rb, line 155 def extract_name extract_git_variable("user.name") end
generate_ca_installer()
click to toggle source
# File lib/util.rb, line 159 def generate_ca_installer directory "install_certificate","#{root_dir}/install_certificate" FileUtils.cp "#{admin_dir}/ca/rootCA.crt","install_certificate" package_tar "install_certificate" FileUtils.rm_rf "install_certificate" end
install_dir()
click to toggle source
# File lib/util.rb, line 56 def install_dir "#{admin_dir}/installation_scripts" end
package_tar(dir_name,current_dir = nil)
click to toggle source
# File lib/util.rb, line 166 def package_tar(dir_name,current_dir = nil) if current_dir `tar -cf #{dir_name}.tar -C #{current_dir} #{dir_name}` else `tar -cf #{dir_name}.tar #{dir_name}` end end
proxy_dir()
click to toggle source
# File lib/util.rb, line 60 def proxy_dir "#{root_dir}/proxy" end
remove_line_from_routine(routine,filter_line)
click to toggle source
# File lib/util.rb, line 127 def remove_line_from_routine(routine,filter_line) File.open "#{routine_dir}/tmp","w" do | output_file | File.foreach "#{routine_dir}/#{routine}" do | line | output_file.write line unless line == "#{filter_line}\n" end end FileUtils.mv "#{routine_dir}/tmp", "#{routine_dir}/#{routine}" end
root_dir()
click to toggle source
# File lib/util.rb, line 9 def root_dir return @root_dir if @root_dir search_dir = Dir.pwd while search_dir && !root_dir_condition(search_dir) parent = File.dirname(search_dir) # project_root wird entweder der Root-pfad oder false. Wenn es false # wird, bricht die Schleife ab. Vgl. Rails search_dir = (parent != search_dir) && parent end project_root = search_dir if root_dir_condition(search_dir) raise 'you are not within a presentation-project.' unless project_root @root_dir = Pathname.new(File.realpath project_root) end
root_dir_condition(search_dir)
click to toggle source
# File lib/util.rb, line 23 def root_dir_condition(search_dir) search_dir.is_a?(String) && search_dir.end_with?("/docker") && (Dir.entries(search_dir) && %w{admin backup apps}).length == 3 end
routine_dir()
click to toggle source
# File lib/util.rb, line 52 def routine_dir "#{admin_dir}/routines" end
runner_dir()
click to toggle source
# File lib/util.rb, line 35 def runner_dir "#{root_dir}/ci_runner" end
service_hooks_for(app_name,type)
click to toggle source
# File lib/util.rb, line 95 def service_hooks_for(app_name,type) Dir.entries("#{apps_dir}/#{app_name}/administration/hooks/#{type}.d") .select {| entry | !entry.start_with?(".") && entry != "before_all" && entry != "after_all" } end
services(app_name)
click to toggle source
# File lib/util.rb, line 100 def services(app_name) YAML.load(File.read("#{apps_dir}/#{app_name}/docker-compose.yml")) .each_key .select {|k| !k.end_with?("data")} end
vhost_dir()
click to toggle source
# File lib/util.rb, line 70 def vhost_dir "#{proxy_dir}/vhosts.d" end
volumes(app_name,service_name)
click to toggle source
# File lib/util.rb, line 111 def volumes(app_name,service_name) raw_volumes = YAML.load(File.read("#{apps_dir}/#{app_name}/docker-compose.yml"))["#{service_name}"]['volumes'] raw_volumes.map do |volume| volume.chop! if volume.end_with? '/' volume[0] = '' if volume.start_with? '/' volume end end