1

我正在尝试将一个简单的 sinatra 应用程序部署到 appfog,数据库后端是 postgresql。

这是我想出的

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:postgres@localhost:5432/todo_list")
end

我的清单.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...

有谁知道如何设置一个使用带有 appfog 的 postgresql 数据库的 sinatra 应用程序?

4

1 回答 1

3

我尝试自己在 af 上运行您的代码,它看起来是正确的。您是否已将数据库绑定到您的应用程序?要将“服务”绑定到 appfog 中的应用程序,您必须在 af cli 中执行以下步骤:

af bind-service <servicename> <appname> 

您还可以在应用程序的服务选项卡下的 console.appfog.com 上的 appfog 控制台中绑定数据库。

于 2012-10-10T22:33:06.677 回答