Home>

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

    Was self resolved! In the deploy.rb file

    set: linked_files,% w {config/credentials.yml.enc}


    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.