lib/hitcher/providers/docker/dsl.rb in Hitcher-0.1.0 vs lib/hitcher/providers/docker/dsl.rb in Hitcher-0.1.1

- old
+ new

@@ -1,6 +1,7 @@ +require "toolrack" require_relative 'template' require_relative 'command_builder' require_relative 'command_runner' module Hitcher @@ -113,11 +114,12 @@ ## ## Module Dsl ## module Dsl - + include Antrapol::ToolRack::ConditionUtils + attr_reader :image, :cName, :df, :mounts, :exposes, :interactive_mode, :tty_mode def image_name(name) @image = name end @@ -187,30 +189,52 @@ end # # Operation # - def gen + def gen(depth = :all) @logger.debug "Generate output files!" te = Hitcher::Docker::TemplateEngine.new - if not @dockerfile.nil? + if depth == :dockerfile or depth == :all and not @dockerfile.nil? te.build_template(:dockerfile, { image: @image, dockerfile: @df.cont }) @logger.debug "Dockerfile generated" end - te.build_template(:build_container, { image_name: @image }) + if depth == :build_container or depth == :all + te.build_template(:build_container, { image_name: @image }) + end - # run script - mm = @mounts.collect { |m| m.hashify } - pp = @exposes.collect { |po| po.hashify } - te.build_template(:run_container, { mounts: mm, ports: pp, container_name: @cName, interactive: true, image: @image }) - @logger.debug "run_container generated" + if depth == :run_script or depth == :all + # run script + mm = @mounts.collect { |m| m.hashify } + pp = @exposes.collect { |po| po.hashify } + params = { mounts: mm, ports: pp, container_name: @cName, image: @image } + params[:interactive] = @interactive_mode if not_empty?(@interactive_mode) + params[:tty] = @tty_mode if not_empty?(@tty_mode) + te.build_template(:run_container, params) + @logger.debug "run_container generated" + end - te.build_template(:start_container, { container_name: @cName, drop_to_prompt: true }) + if depth == :start_container or depth == :all + params = { container_name: @cName } + params[:interactive] = @interactive_mode if not_empty?(@interactive_mode) + params[:tty] = @tty_mode if not_empty?(@tty_mode) + te.build_template(:start_container, params) + @logger.debug "start_container generated" + end - te.build_template(:container_prompt, { container_name: @cName }) + if depth == :container_prompt or depth == :all + params = { container_name: @cName } + params[:interactive] = @interactive_mode if not_empty?(@interactive_mode) + params[:tty] = @tty_mode if not_empty?(@tty_mode) + te.build_template(:container_prompt, params) + @logger.debug "container_prompt generated" + end + + @logger.debug "Sample script generated successfully" + end # generate output files end # module Dsl