2012-10-08 104 views
1

我想部署一個簡單的sinatra應用程序到appfog,數據庫後端是postgresql。如何部署使用postgresql的sinatra應用程序到appfog

下面是我想出

require 'sinatra' 
require 'data_mapper' 

if ENV['VCAP_SERVICES'] 
    require 'json' 
    services = JSON.parse(ENV['VCAP_SERVICES']) 
    postgresql_key = services.keys.select { |svc| svc =~ /postgresql/i }.first 
    postgresql = services[postgresql_key].first['credentials'] 
    postgresql_conn = "postgres://"+postgresql['user']+":"+postgresql['password']+ \ 
    "@"+postgresql['host']+":"+postgresql['port']+"/"+postgresql['name'] 
    DataMapper.setup(:default, postgresql_conn) 
else 
    DataMapper.setup(:default, "postgres://postgres:[email protected]:5432/todo_list") 
end 

我manifest.yml

--- 
applications: 
    .: 
    name: supertasks 
    framework: 
     name: sinatra 
     info: 
     mem: 128M 
     description: Sinatra Application 
     exec: ruby web.rb 
    infra: hp 
    url: ${name}.${target-base} 
    mem: 128M 
    instances: 1 
    services: 
     postgresql-4aaf: 
     type: postgresql 

而且我的Gemfile具有下面的代碼

source :rubygems 

gem 'sinatra' 
gem 'thin' 
gem "pg" 
gem 'data_mapper' 
gem 'dm-postgres-adapter' 
gem 'json' 

我收到以下錯誤,當我嘗試啓動應用程序

Error: Application [supertasks] failed to start, logs information below.                    

====> /logs/staging.log <==== 

# Logfile created on 2012-10-08 18:59:58 +0000 by logger.rb/25413 
Adding json-1.7.5.gem to app... 
Adding data_mapper-1.2.0.gem to app... 
Adding dm-core-1.2.0.gem to app... 
Adding addressable-2.2.8.gem to app... 
Adding dm-aggregates-1.2.0.gem to app... 
Adding dm-constraints-1.2.0.gem to app... 
Adding dm-migrations-1.2.0.gem to app... 
Adding dm-serializer-1.2.2.gem to app... 
Adding fastercsv-1.5.5.gem to app... 
Adding json_pure-1.7.5.gem to app... 
Adding multi_json-1.3.6.gem to app... 
Adding dm-timestamps-1.2.0.gem to app... 
Adding dm-transactions-1.2.0.gem to app... 
Adding dm-types-1.2.2.gem to app... 
Adding bcrypt-ruby-3.0.1.gem to app... 
Adding stringex-1.4.0.gem to app... 
Adding uuidtools-2.1.3.gem to app... 
Adding dm-validations-1.2.0.gem to app... 
Adding dm-postgres-adapter-1.2.0.gem to app... 
Adding dm-do-adapter-1.2.0.gem to app... 
Adding data_objects-0.10.9.gem to app... 
Adding do_postgres-0.10.9.gem to app... 
Adding pg-0.14.1.gem to app... 
Adding sinatra-1.3.3.gem to app... 
Adding rack-1.4.1.gem to app... 
Adding rack-protection-1.2.0.gem to app... 
Adding tilt-1.3.3.gem to app... 
Adding thin-1.5.0.gem to app... 
Adding daemons-1.1.9.gem to app... 
Adding eventmachine-1.0.0.gem to app... 
Adding bundler-1.1.3.gem to app... 
Adding cf-autoconfig-0.0.4.gem to app... 
Adding cf-runtime-0.0.2.gem to app. server error occurr... 

有誰知道如何設置一個使用postgresql數據庫與appfog的sinatra應用程序?

回答

3

我試着在自己的代碼上運行你的代碼,它看起來是正確的。你有沒有將數據庫綁定到你的應用程序呢?要綁定「服務」應用程序在appfog你必須去通過在AF CLI下列步驟操作:

af bind-service <servicename> <appname> 

您也可以綁定DB在appfog控制檯,console.appfog.com的服務標籤下應用程序。

相關問題