Introduced automatic deployment by Capistrano
An error occurs when posting an image on the AWS EC2 server.
The storage location is set to S3, and images can be saved in the local environment.
I want to be able to save images even in a production environment.
Error log when posting images
D, [2020-10-27T11: 45: 08.431895 # 20923] DEBUG-: [bcae8d8e-a293-4511-a0b2-5ccb1b83f1a6] User Load (0.3ms) SELECT ʻusers`. * FROM ʻusers` WHERE ʻusers` .ʻId` = 1 ORDER BY ʻusers` .ʻid` ASC LIMIT 1
D, [2020-10-27T11: 45: 08.441089 # 20923] DEBUG-: [bcae8d8e-a293-4511-a0b2-5ccb1b83f1a6] (0.1ms) BEGIN
D, [2020-10-27T11: 45: 08.441965 # 20923] DEBUG-: [bcae8d8e-a293-4511-a0b2-5ccb1b83f1a6] User Load (0.2ms) SELECT ʻusers`. * FROM ʻusers` WHERE ʻusers` .ʻId` = 1 LIMIT 1
D, [2020-10-27T11: 45: 08.442575 # 20923] DEBUG-: [bcae8d8e-a293-4511-a0b2-5ccb1b83f1a6] (0.1ms) ROLLBACK
I, [2020-10-27T11: 45: 08.443031 # 20923] INFO-: [bcae8d8e-a293-4511-a0b2-5ccb1b83f1a6] Redirected to http://18.180.124.79/topps/new
I, [2020-10-27T11: 45: 08.443252 # 20923] INFO-: [bcae8d8e-a293-4511-a0b2-5ccb1b83f1a6] Completed 302 Found in 13ms (ActiveRecord: 0.7ms)
I, [2020-10-27T11: 45: 08.481704 # 20923] INFO-: [fd76f30f-105f-4bba-8642-3d946547ef6c] Started GET "/ topps/new" for 218.220.166.199 at 2020-10-27 11: 45:08 +0000
I, [2020-10-27T11: 45: 08.482469 # 20923] INFO-: [fd76f30f-105f-4bba-8642-3d946547ef6c] Processing by ToppsController # new as HTML
D, [2020-10-27T11: 45: 08.483855 # 20923] DEBUG-: [fd76f30f-105f-4bba-8642-3d946547ef6c] User Load (0.3ms) SELECT ʻusers`. * FROM ʻusers` WHERE ʻusers` .ʻId` = 1 ORDER BY ʻusers` .ʻid` ASC LIMIT 1
I, [2020-10-27T11: 45: 08.484671 # 20923] INFO-: [fd76f30f-105f-4bba-8642-3d946547ef6c] Rendering topps/new.haml within layouts/application
I, [2020-10-27T11: 45: 08.485921 # 20923] INFO-: [fd76f30f-105f-4bba-8642-3d946547ef6c] Rendered topps/_new.haml (0.9ms)
I, [2020-10-27T11: 45: 08.486083 # 20923] INFO-: [fd76f30f-105f-4bba-8642-3d946547ef6c] Rendered topps/new.haml within layouts/application (1.3ms)
I, [2020-10-27T11: 45: 08.487039 # 20923] INFO-: [fd76f30f-105f-4bba-8642-3d946547ef6c] Rendered layouts/_flash.html.haml (0.1ms)
I, [2020-10-27T11: 45: 08.487359 # 20923] INFO-: [fd76f30f-105f-4bba-8642-3d946547ef6c] Completed 200 OK in 5ms (Views: 2.9ms | ActiveRecord: 0.3ms)
Corresponding source code
deproy.rb
lock '3.14.1'
set: linked_files,% w {config/credentials.yml.enc}
set: application,'kiawase'
set: repo_url,'[email protected]: ik425524/kiawase.git'
set: linked_dirs, fetch (: linked_dirs, []). push ('log','tmp/pids','tmp/cache','tmp/sockets','vendor/bundle','public/system',' public/uploads')
set: linked_files,% w {config/credentials.yml.enc}
set: linked_files, fetch (: linked_files, []). push ("config/master.key")set: rbenv_type,: user
set: rbenv_ruby, '2.5.1'
set: ssh_options, auth_methods: ['publickey'],
keys: ['~/.ssh/kiawase.pem']
set: unicorn_pid,->{"# {shared_path} /tmp/pids/unicorn.pid"}
set: unicorn_config_path,->{"# {current_path} /config/unicorn.rb"}
set: keep_releases, 5
after'deploy: publishing','deploy: restart'
namespace: deploy do
task: restart do
invoke'unicorn: restart'
end
desc'upload credentials.yml.enc'
task: upload do
on roles (: app) do | host |
if test "[! -d # {shared_path}/config]"
execute "mkdir -p # {shared_path}/config"
end
upload! ('config/credentials.yml.enc', "# {shared_path} /config/credentials.yml.enc")
end
end
before: starting,'deploy: upload'
after: finishing,'deploy: cleanup'
end
carrirwave.rb
require'carrierwave/storage/abstract'
require'carrierwave/storage/file'
require'carrierwave/storage/fog'CarrierWave.configure do | config |
config.storage =: fog
config.fog_provider ='fog/aws'
config.fog_credentials = {
provider:'AWS',
aws_access_key_id: Rails.application.credentials.aws [: access_key_id],
aws_secret_access_key: Rails.application.credentials.aws [: secret_access_key],
region:'ap-northeast-1'
}
config.fog_directory ='kiawase-2020'
config.asset_host ='https://s3-ap-northeast-1.amazonaws.com/kiawase-2020'
end
What I tried
○ Check the contents of sudo vim/etc/environment
○ Check the contents of credentials
Result
aws:
access_key_id: 111111
secret_access_key: 222222
secret_key_base: 111111111
○ Check if the master key is reflected in the production environment with the config.require_master_key = true command
○ Check if ImageMagick is installed in the production environment
Supplementary information (FW/tool version, etc.)I have hypothesized that there is a mistake in the description of deproy.rb or the way of writing the key of credentials, but I can not consider what is wrong, and I am at a loss because I can not find information even if I search is.
I would appreciate it if you could teach me the mistakes.
-
Answer # 1
Related articles
- ruby on rails - i implemented it so that images can be saved in s3 of aws, but the view can no longer be displayed
- ruby on rails - can't access rails server
- ruby on rails - i want to start the puma server and deploy the rails app
- ruby - unable to open rails server
- ruby on rails - unable to start server in aws production environment
- ruby - how to upload images directly from rails to s3 on aws
- ruby on rails - saved description in nested controller
- ruby on rails - rails associated model is not saved in db
- ruby - not saved with rails new save method
- ruby - rails s fails to start the server with a usage: rails new app_path [options] error
- ruby on rails - it is not saved in the database after registering the product
- ruby - i started the server in rails s but can't open it
- ruby on rails 5 - some items are not saved in db when posting from rails form
- ruby on rails - not saved by create action
- ruby on rails - i want to display all the images in the [rails] directory in the browser!
- ruby - unable to access server with rails s
- ruby on rails - at the launch of the rails web server
- ruby on rails - image cannot be saved (activestorage installed) null in image of table
- ruby on rails - i want to display the posted images in a random order (get information from the record)
- i don't understand the need for a web server such as nginx when deploying ruby on rails applications on ec2
- unable to boot with mysql error number 28 means'no space left on device'!
- ruby on rails - i want to know the settings of auto scaling for automatic server recovery (maintaining the number of instances)
- ruby on rails - i want to solve the problem that "we're sorry, but something went wrong" is displayed in the productio
- ruby - it works fine in my local environment, but when i deploy it to aws, i get an error in mysql2 :: error: unknown column
- ruby - i entered secret_key_base, but http error 500 cannot be resolved
- css - bootstrap is not reflected in aws production environment
- ruby on rails - i want to deploy to aws ec2 server
- nginx - [production environment] how to read less log/productionlog when rails does not start properly
Was self resolved! In the deploy.rb file
No description was required.
In addition, there seemed to be a problem with the format of the image I was trying to post in the test, and I was able to post other images without problems.
Thank you for your reply.