Rails CircleCI 连接上的 Fake-S3 被拒绝
Rails Fake-S3 on CircleCI Connection refused
我正在尝试在 this gist 之后使用 Paperclip 配置 Fake-S3。在开发机器上一切正常,但是当我试图在 CircleCI 上 运行 它时,我收到错误
Errno::ECONNREFUSED: Connection refused - connect(2) for "local-bucket.local.s3.endpoint" port 4567
我有下一个config/environments/test.rb:
config.paperclip_defaults = {
storage: :s3,
s3_credentials: {
access_key_id: 'anything',
secret_access_key: 'anything'
},
bucket: 'local-bucket',
s3_host_name: 'local.s3.endpoint',
s3_protocol: 'http',
url: ':s3_alias_url',
s3_host_alias: 'local-bucket.local.s3.endpoint:4567',
path: '/test/:class/:attachment/:id_partition/:style/:filename',
s3_options: {
use_ssl: false,
s3_port: 4567
}
}
在 CircleCI 上,我将该行添加到 /etc/hosts:
127.0.0.1 local-bucket.local.s3.endpoint
并且运行宁下一个命令:
fakes3 -r ./fakes3 -p 4567 >log/fakes3.log 2>&1 &
因此,当我尝试使用下一个代码创建新存储桶时:
s3 = AWS::S3.new(
access_key_id: 'anything',
secret_access_key: 'anything',
s3_endpoint: 'local.s3.endpoint',
s3_port: 4567,
use_ssl: false
)
s3.buckets.create('local-bucket')
我遇到下一个错误:
rake aborted!
Errno::ECONNREFUSED: Connection refused - connect(2) for "local-bucket.local.s3.endpoint" port 4567
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/http/connection_pool.rb:327:in `start_session'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/http/connection_pool.rb:127:in `session_for'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/http/net_http_handler.rb:56:in `handle'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:253:in `block in make_sync_request'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:282:in `retry_server_errors'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/s3/region_detection.rb:11:in `retry_server_errors'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:249:in `make_sync_request'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:511:in `block (2 levels) in client_request'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:391:in `log_client_request'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:477:in `block in client_request'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:373:in `return_or_raise'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:476:in `client_request'
(eval):3:in `create_bucket'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/s3/bucket_collection.rb:109:in `create'
/home/ubuntu/***/lib/tasks/fakes3.rake:11:in `block (2 levels) in <top (required)>'
Tasks: TOP => fakes3:create_bucket
(See full trace by running task with --trace)
请帮我找出问题所在?
更新(1):
我意识到如果我通过 SSH 和 运行
连接到 CircleCI 构建
fakes3 -r ./fakes3 -p 4567 >log/fakes3.log 2>&1 &
来自 rails 应用程序文件夹的一切都按需要工作并且所有测试都通过。
更新(2):
circle.yml 个文件:
test:
pre:
- bundle exec fakes3 -r ./fakes3 -p 4567 >./log/fakes3.log 2>&1 &
- bundle exec rake fakes3:create_bucket
经过几天寻找决定后,我找到了。
问题出在 运行 FakeS3 在后台使用 & sign
fakes3 -r ./fakes3 -p 4567 >log/fakes3.log 2>&1 &
关注来自 CircleCI 的 this docs:
Starting a background process from circle.yml is entirely possible, but it is not done by adding & to the end of your command line. Instead, you set the background flag on the command.
所以,我重写了 FakeS3 的启动方式:
test:
pre:
- bundle exec fakes3 -r ./fakes3 -p 4567 >./log/fakes3.log 2>&1:
background: true
- bundle exec rake fakes3:create_bucket
得到了结果。
我正在尝试在 this gist 之后使用 Paperclip 配置 Fake-S3。在开发机器上一切正常,但是当我试图在 CircleCI 上 运行 它时,我收到错误
Errno::ECONNREFUSED: Connection refused - connect(2) for "local-bucket.local.s3.endpoint" port 4567
我有下一个config/environments/test.rb:
config.paperclip_defaults = {
storage: :s3,
s3_credentials: {
access_key_id: 'anything',
secret_access_key: 'anything'
},
bucket: 'local-bucket',
s3_host_name: 'local.s3.endpoint',
s3_protocol: 'http',
url: ':s3_alias_url',
s3_host_alias: 'local-bucket.local.s3.endpoint:4567',
path: '/test/:class/:attachment/:id_partition/:style/:filename',
s3_options: {
use_ssl: false,
s3_port: 4567
}
}
在 CircleCI 上,我将该行添加到 /etc/hosts:
127.0.0.1 local-bucket.local.s3.endpoint
并且运行宁下一个命令:
fakes3 -r ./fakes3 -p 4567 >log/fakes3.log 2>&1 &
因此,当我尝试使用下一个代码创建新存储桶时:
s3 = AWS::S3.new(
access_key_id: 'anything',
secret_access_key: 'anything',
s3_endpoint: 'local.s3.endpoint',
s3_port: 4567,
use_ssl: false
)
s3.buckets.create('local-bucket')
我遇到下一个错误:
rake aborted!
Errno::ECONNREFUSED: Connection refused - connect(2) for "local-bucket.local.s3.endpoint" port 4567
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/http/connection_pool.rb:327:in `start_session'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/http/connection_pool.rb:127:in `session_for'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/http/net_http_handler.rb:56:in `handle'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:253:in `block in make_sync_request'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:282:in `retry_server_errors'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/s3/region_detection.rb:11:in `retry_server_errors'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:249:in `make_sync_request'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:511:in `block (2 levels) in client_request'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:391:in `log_client_request'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:477:in `block in client_request'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:373:in `return_or_raise'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/core/client.rb:476:in `client_request'
(eval):3:in `create_bucket'
/home/ubuntu/***/vendor/bundle/ruby/2.2.0/gems/aws-sdk-v1-1.64.0/lib/aws/s3/bucket_collection.rb:109:in `create'
/home/ubuntu/***/lib/tasks/fakes3.rake:11:in `block (2 levels) in <top (required)>'
Tasks: TOP => fakes3:create_bucket
(See full trace by running task with --trace)
请帮我找出问题所在?
更新(1):
我意识到如果我通过 SSH 和 运行
连接到 CircleCI 构建fakes3 -r ./fakes3 -p 4567 >log/fakes3.log 2>&1 &
来自 rails 应用程序文件夹的一切都按需要工作并且所有测试都通过。
更新(2):
circle.yml 个文件:
test:
pre:
- bundle exec fakes3 -r ./fakes3 -p 4567 >./log/fakes3.log 2>&1 &
- bundle exec rake fakes3:create_bucket
经过几天寻找决定后,我找到了。 问题出在 运行 FakeS3 在后台使用 & sign
fakes3 -r ./fakes3 -p 4567 >log/fakes3.log 2>&1 &
关注来自 CircleCI 的 this docs:
Starting a background process from circle.yml is entirely possible, but it is not done by adding & to the end of your command line. Instead, you set the background flag on the command.
所以,我重写了 FakeS3 的启动方式:
test:
pre:
- bundle exec fakes3 -r ./fakes3 -p 4567 >./log/fakes3.log 2>&1:
background: true
- bundle exec rake fakes3:create_bucket
得到了结果。