阿里云如何使用AWS S3并用figaro管理密码

阅读: 评论:0

阿里云如何使用AWS S3并用figaro管理密码

阿里云如何使用AWS S3并用figaro管理密码

前提: 已经把rails app部署到阿里云,已有AWS账号,并且申请了AWS
S3,记录下密钥ID和私钥,Region,Bucket_name。

设置figaro

编辑l

production:SEND_CLOUD_USER_NAME: xxxSEND_CLOUD_USER_KEY: xxxxxsecret_key_base: xxxxxxxAWS_ACCESS_KEY_ID: xxxxxxxxAWS_SECRET_ACCESS_KEY: hIMMHPxxxxxxxAWS_REGION: ap-northeast-1AWS_BUCKET_NAME: xxxxx
development:SEND_CLOUD_USER_NAME: xxxSEND_CLOUD_USER_KEY: xxxxxsecret_key_base: xxxxxxxAWS_ACCESS_KEY_ID: xxxxxxxxAWS_SECRET_ACCESS_KEY: hIMMHPxxxxxxxAWS_REGION: ap-northeast-1AWS_BUCKET_NAME: xxxxx

安装fog

另外还有fog-aws可以用。
添加gem 'fog'
bundle install
新增carrierwave.rb文件,touch config/initializers/carrierwave.rb
编辑这个文件:

使用fog存图片

在xxx_uploader.rb中设置,当在开发模式的时候就把图片存在本地文档中,如果是在产品模式,就用fog存图片。

uploaders/house_image_uploader.rb

  v.development?storage :v.production?storage :fogend

debug

做完这些,如果是部署到heroku的,还会有一步骤是要把figaro同步到heroku,figaro heroku:set -e production,但我们是部署到阿里云的,就没有这一步。
提交代码到github,准备部署,执行cap production deploy,过程中会报错:

00:22 deploy:assets:precompile01 bundle exec rake assets:precompile01 rake aborted!01 ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key01 /home/deploy/homey/shared/bundle/ruby/2.4.0/gems/fog-core-1.45.0/lib/fog/core/service.rb:244:in `validate…01 /home/deploy/homey/shared/bundle/ruby/2.4.0/gems/fog-core-1.45.0/lib/fog/core/service.rb:268:in `handle_s…01 /home/deploy/homey/shared/bundle/ruby/2.4.0/gems/fog-core-1.45.0/lib/fog/core/service.rb:98:in `new'01 /home/deploy/homey/shared/bundle/ruby/2.4.0/gems/fog-core-1.45.0/lib/fog/core/services_mixin.rb:16:in `ne…01 /home/deploy/homey/shared/bundle/ruby/2.4.0/gems/fog-core-1.45.0/lib/fog/storage.rb:27:in `new'......

大概意思是说没有aws_access_key_idaws_secret_access_key,可以理解,因为如果是heroku还要同步一下figaro的信息呢,而在阿里云的时候就缺少了这一步,明显不行。
然后开figaro的git资料,看到这一段:

Other Hosts
If you're not deploying to Heroku, you have two options:Generate a remote configuration file
Set ENV variables directly
Generating a remote configuration file is preferred because of:familiarity – Management of l is like that of l.
isolation – Multiple applications on the same server will not produce configuration key collisions.

大概意思大概是让我们自己建立一个l放到云服务器了,只要不是放在github里就好。于是我连接远程服务器,在/appname/shared/config下和/appname/current/config两个地方都创建了,并且把内容贴进去,保存退出。
再次运行,发现同样的问题还在!但是进入到远程服务器的console,用来测试又是能显示密钥来的。

irb(main):003:0> ENV["AWS_ACCESS_KEY_ID"]
=> "AKIAJNP35BSxxxxxxxxx"
irb(main):004:0> v.AWS_ACCESS_KEY_ID
=> "AKIAJNP35BSxxxxxxxxx"
irb(main):005:0> 

到底问题出在哪里?继续查资料,直到我看到这样的一段话:

And finally if we deploy application with Capistrano we have to deploy it properly. We should put l to the Capistrano shared folder on the server and change config/deploy.rb like this:

before 'deploy:assets:precompile', :symlink_config_filesdesc "Link shared files"
task :symlink_config_files dosymlinks = {"#{shared_path}/l" => "#{release_path}/l","#{shared_path}/config/l" => "#{release_path}/config/l"}run symlinks.map{|from, to| "ln -nfs #{from} #{to}"}.join(" && ")
end

得到一些灵感,在自己的rails application中找到config/deploy.rb,里面有一行是:

append :linked_files, "l", "l"

我把l加到后面去:

append :linked_files, "l", "l", "l"

再次尝试,部署成功!

本文发布于:2024-02-05 04:47:39,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170724477263164.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:阿里   如何使用   密码   AWS   figaro
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23