Top Level Namespace
Defined Under Namespace
Instance Method Summary collapse
- #cfn(args, &block) ⇒ Object
- #docker_build(args, &block) ⇒ Object
- #docker_image(args, block = nil) ⇒ Object
- #docker_up(args, &block) ⇒ Object
- #env(args, &block) ⇒ Object
- #external(dep, &block) ⇒ Object
- #external_docker_image(args, block) ⇒ Object
- #git(args, prerequisites, block = nil) ⇒ Object
- #parse_env(environment) ⇒ Object
- #s3(args, prerequisites, block = nil) ⇒ Object
- #wget(args, prerequisites, block = nil) ⇒ Object
Instance Method Details
#cfn(args, &block) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/panoramix/plugin/cfn.rb', line 184 def cfn(args, &block) name = args.keys[0] deps = args[name] = deps.select { |d| d.is_a? Hash } # Get cloudformation template file path template = .empty? ? nil : .first[:template] # Raise error if :template value is nil unless template = I18n.t('errors.cfn.no_template_provided') raise(Panoramix::Plugin::DockerUpExceptionError, ) end # Required by aws cli template = File. template # Get cloudformation parameters file path parameters = .empty? ? nil : .first[:parameters] # Raise error if :parameters value is nil unless parameters = I18n.t('errors.cfn.no_parameters_provided') raise(Panoramix::Plugin::DockerUpExceptionError, ) end # Raise error if the file does not exist unless File.exists? parameters = I18n.t('errors.cfn.parameters_not_found', {:path => parameters}) raise(Panoramix::Plugin::DockerUpExceptionError, ) end # Get the PANORAMIX_OWNER environment variable owner = ENV["PANORAMIX_OWNER"] raise "Variable PANORAMIX_OWNER not defined" unless owner # Convert name.surname to namesurname owner = owner.gsub(".", "") descriptions = I18n.t('cfn') descriptions = Hash.new if descriptions.class != Hash # Merge deps with the cloudformation template file task prerequisites = deps.select { |d| ! d.is_a? Hash } prerequisites = prerequisites.push(template) # Create a task for each version ["blue", "green", nil].each do |version| # Create a task inside each development stage namespace ["pro", "pre", "dev", "test"].each do |stage| stage_name = version ? "#{stage}:#{name}:#{version}" : "#{stage}:#{name}" instance = Panoramix::Plugin::CloudFormation.new(name, template, parameters, stage, owner, version) Panoramix.define_tasks(stage_name, descriptions, instance, prerequisites, block) end end end |
#docker_build(args, &block) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/panoramix/plugin/docker_build.rb', line 47 def docker_build(args, &block) # Get task name name = args.keys[0] # Get configuration hash config = args[name].select { |dep| dep.is_a? Hash }.first # Get dockerfile if given dockerfile = config.fetch(:dockerfile, nil) # Raise error if :dockerfile value is nil unless dockerfile = I18n.t('errors.docker_build.no_dockerfile_provided') raise end # Get context if given context = config.fetch(:context, File.dirname(dockerfile)) # Select the host host = config.fetch(:host, nil) # Select provided dependencies prerequisites = args[name].select { |d| ! d.is_a? Hash } # Merge prerequisites with the Dockerfile file_task prerequisites = prerequisites.push(dockerfile) unless dockerfile.nil? prerequisites.flatten! instance = Panoramix::Plugin::DockerBuild.new(name, dockerfile, context, host) descriptions = I18n.t('docker_build') descriptions = Hash.new if descriptions.class != Hash Panoramix.define_tasks(name,descriptions, instance, prerequisites, block) end |
#docker_image(args, block = nil) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/panoramix/plugin/docker_build.rb', line 40 def docker_image(args, block=nil) puts "Warning using obsolete docker_image \t => #{"docker_image".bold} <image_name> => {dockerfile: <path_dockerfile>}.\n\tchange to: \t => #{"docker_build".bold} <image_name> => {dockerfile: <path_dockerfile>}".red docker_build(args, block) end |
#docker_up(args, &block) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/panoramix/plugin/docker_up.rb', line 136 def docker_up(args, &block) name = args.keys[0] deps = args[name] compose_params = deps.select { |d| d.is_a? Hash } # Get docker-compose file path compose = compose_params.first[:compose] # Raise error if :compose value is nil unless compose = I18n.t('errors.docker_up.no_compose_provided') raise(Panoramix::Plugin::DockerUpExceptionError, ) end # Get flags flags = {} # Get environment environment = parse_env(compose_params.first[:env] || []) # Select the host host = compose_params[0].fetch(:host, nil) # Merge deps with the compose file_task prerequisites = deps.select { |d| ! d.is_a? Hash } prerequisites = prerequisites.push(compose) instance = Panoramix::Plugin::DockerUp.new(name, compose, environment, host) descriptions = I18n.t('docker_up') descriptions = Hash.new if descriptions.class != Hash Panoramix.define_tasks(name, descriptions, instance, prerequisites, block) end |
#env(args, &block) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/panoramix/plugin/env.rb', line 48 def env(args, &block) name = "" deps = [] # case env "URL" if (args.class == String) name = args vars = [name] else # case env "some_var" => [{:vars => [......]}] name = args.keys[0] deps = args[name] = deps.select { |d| d.is_a? Hash } # Get variables array vars = .empty? ? nil : .first[:vars] end descriptions = I18n.t('env') descriptions = Hash.new if descriptions.class != Hash # Merge deps prerequisites = deps.select { |d| ! d.is_a? Hash } instance = Panoramix::Plugin::Environment.new(name, vars) Panoramix.define_tasks(name, descriptions, instance, prerequisites, block) end |
#external(dep, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/panoramix/external.rb', line 7 def external(dep, &block) # Provided value can be either array or hash, so we need to make sure the final value is an array value = [dep.values[0]].flatten # Select the hash with params params = value.select { |d| d.is_a? Hash }.first # Handle with MPI handled_dep = Panoramix::MPI.handle_external(dep.keys[0], params) raise "Only a single external dependency supported (received: #{dep.keys})" if handled_dep.length != 1 # Select provided dependencies prerequisites = value.select { |d| ! d.is_a? Hash } case handled_dep.values[0].keys[0] when :s3 s3(handled_dep, prerequisites, block) when :wget wget(handled_dep, prerequisites, block) when :git git(handled_dep, prerequisites, block) when :dockerimage external_docker_image(handled_dep, block) when :docker puts "Warning using obsolete external dependency key \t => external <image_name> {#{"docker".bold}: <docker_image_name> }.\n\tchange to: \t => external <image_name> {#{"dockerimage".bold}: <docker_image_name> }.".red external_docker_image(handled_dep, block) else raise "Unknown external protocol '#{dep.values[0].keys[0]}'" end end |
#external_docker_image(args, block) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/panoramix/plugin/docker_image.rb', line 45 def external_docker_image(args, block) name = args.keys[0] src = args[name][:dockerimage] || args[name][:docker] host = args[name][:host] || nil prerequisites = [] instance = Panoramix::Plugin::DockerImage.new(name, src, host) descriptions = I18n.t('docker_image') descriptions = Hash.new if descriptions.class != Hash Panoramix.define_tasks(name, descriptions, instance, prerequisites, block) end |
#git(args, prerequisites, block = nil) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/panoramix/plugin/git.rb', line 81 def git(args, prerequisites, block=nil) # Name of the task name = args.keys[0] # Get :git value from arguments src = args.values[0][:git] # Get :tag value from arguments tag = args.values[0][:tag] # Generate a new instance using the provided arguments instance = Panoramix::Plugin::Git.new(name, src, tag) descriptions = I18n.t('git') descriptions = Hash.new if descriptions.class != Hash # Define git instance tasks Panoramix.define_tasks(name, descriptions, instance, prerequisites, block) end |
#parse_env(environment) ⇒ Object
126 127 128 129 130 131 132 133 134 |
# File 'lib/panoramix/plugin/docker_up.rb', line 126 def parse_env environment res=Hash.new environment.each do |var| res[var]=ENV[var] end res end |
#s3(args, prerequisites, block = nil) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/panoramix/plugin/s3.rb', line 56 def s3(args, prerequisites, block=nil) # Task name name = args.keys[0] # Artifacts url src = args.values[0][:s3] # Provided flags flags = args.values[0][:flags] instance=Panoramix::Plugin::S3.new(name, src, flags) descriptions = I18n.t('s3') descriptions = Hash.new if descriptions.class != Hash Panoramix.define_tasks(name, descriptions, instance, prerequisites, block) end |
#wget(args, prerequisites, block = nil) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/panoramix/plugin/wget.rb', line 51 def wget(args, prerequisites, block=nil) # Task name name = args.keys[0] # Artifacts url src = args.values[0][:wget] # Provided flags flags = args.values[0][:flags] instance=Panoramix::Plugin::Wget.new(name, src, flags) descriptions = I18n.t('wget') descriptions = Hash.new if descriptions.class != Hash Panoramix.define_tasks(name, descriptions, instance, prerequisites, block) end |