Sha256: 91fe4ba5c6ad29344567ab9178fcfc9803e5c5f22173d1ba41a67baed1ffcd3c
Contents?: true
Size: 1.84 KB
Versions: 2
Compression:
Stored size: 1.84 KB
Contents
$: << File.dirname(__FILE__) require 'sinatra' require 'sinatra/url_for' require 'sinatra/static_assets' require 'sinatra/flash' require 'sinatra/redirect_with_flash' require 'json' require 'pp' module TProv class Application < Sinatra::Base register Sinatra::StaticAssets register Sinatra::Flash helpers Sinatra::RedirectWithFlash set :public_folder, File.join(File.dirname(__FILE__), 'public') set :views, File.join(File.dirname(__FILE__), 'views') set :bind, '0.0.0.0' enable :sessions, :logging, :dump_errors, :raise_errors, :show_exceptions before do @app_name = "TProv" end get '/' do erb :index end post '/tomcat/create' do get_war(params[:name], params[:url]) redirect '/', :success => "Instance #{@domain_name} created!" end post '/tomcat/delete' do delete_instance(params[:id]) redirect '/', :success => "Instance #{params[:id]} deleted!" end get '/tomcat/list' do @instances = list_instances erb :instance_list end helpers do def get_war(name, url) cid = `docker run --name #{name} jamtur01/fetcher`.chop create_instance(name) end def create_instance(name) cid = `docker run -P --volumes-from #{name} -d -t jamtur01/tomcat7`.chop port = `docker port #{cid} 8080`.chop end def delete_instance(cid) kill = `docker kill #{cid}` end def list_instances @list = {} instance_ids = `docker ps -q`.split(/\n/).reject(&:empty?) instance_ids.each { |id| port = `docker port #{id} 8080`.chop config = JSON.parse(`docker inspect #{id}`) @list[id] = { 'hostname' => config[0]["Config"]["Hostname"], 'ip' => config[0]["NetworkSettings"]["IPAddress"], 'port' => port } } @list end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tprov-0.0.3 | lib/tprov/app.rb |
tprov-0.0.2 | lib/tprov/app.rb |