Sha256: fa77625d15b1b6eaece20727dff46f4559ab73863155586f1add82797f803afc

Contents?: true

Size: 853 Bytes

Versions: 1

Compression:

Stored size: 853 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 --rm -it' ]
      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(" ")
    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.1 lib/maril/generator.rb