我正在尝试将一个简单的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
我的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...
有谁知道如何设置一个使用appgog的postgresql数据库的sinatra应用程序?
答案 0 :(得分:3)
我尝试自己运行你的代码,看起来是正确的。你有没有将数据库绑定到你的应用程序?要将“服务”绑定到appfog中的应用程序,您必须在af cli中执行以下步骤:
af bind-service <servicename> <appname>
您还可以在应用程序服务选项卡下的console.appfog.com的appfog控制台中绑定数据库。