Sha256: 3f22c349406c75bf56e12ca17c38f2d83d5aa932749e9802130ff20cb2b6a8a0

Contents?: true

Size: 848 Bytes

Versions: 1

Compression:

Stored size: 848 Bytes

Contents

module Maril
  class Generator
    def initialize(options={})
      @host = options[:host] || options['host']
      @id = options[:id] || options['id']
    end

    def generate
      app = fetch_app
      cmd = [ 'docker run' ]
      app['env'].each do |k, v|
        cmd << "-e #{k}=#{v}"
      end
      app['container']['docker']['parameters'].each do |parameter|
        cmd << "--#{parameter['key']} #{parameter['value']}"
      end
      app['container']['docker']['portMappings'].each do |mapping|
        cmd << "-p #{mapping['containerPort']}:#{mapping['containerPort']}"
      end
      cmd << app['container']['docker']['image']
      cmd << app['cmd'] if app['cmd']
      cmd.join(" \\\n")
    end

    private

    def fetch_app
      res = RestClient.get("#{@host}/v2/apps#{@id}")
      JSON.parse(res.body)['app']
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
maril-0.1.0 lib/maril/generator.rb