前提・実現したいこと
AWSでのデプロイ
①EC2インスタンスを作成後、デプロイ作業の途中でGemfileが存在しないとのエラーが発生する
②bundle exec cap production deployコマンド実行後にエラーが発生
今回のデプロイは2回目で、以前使用していたEC2を使用してる為環境構築は完了しています。
(Ruby,Node.js,Mysql,nginx,unicorn,capistrano)
発生している問題・エラーメッセージ
terminal
1bundlerインストール後 2$ bundle install 3結果 4Could not locate Gemfile 5 6ユニコーン起動時 7$ bundle exec unicorn_rails -c config/unicorn.rb -E production -D 8結果 9Could not locate Gemfile or .bundle/ directory 10 11ログ確認 12$ less log/unicorn.stderr.log 13結果 14log/unicorn.stderr.log: そのようなファイルやディレクトリはありません
terminal
1ローカル 2$ bundle exec cap production deploy 3結果 4runners/parallel.rb:10 run> terminated with exception (report_on_exception is true): 5Traceback (most recent call last): 6 1: from /Users/shiro/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute' 7/Users/shiro/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as ec2-user@18.179.106.191: git exit status: 128 (SSHKit::Runner::ExecuteError) 8git stdout: Nothing written 9git stderr: ssh: connect to host example.com port 22: Network is unreachable 10fatal: Could not read from remote repository. 11 12Please make sure you have the correct access rights 13and the repository exists. 14(Backtrace restricted to imported tasks) 15cap aborted! 16SSHKit::Runner::ExecuteError: Exception while executing as ec2-user@18.179.106.191: git exit status: 128 17git stdout: Nothing written 18git stderr: ssh: connect to host example.com port 22: Network is unreachable 19fatal: Could not read from remote repository. 20 21Please make sure you have the correct access rights 22and the repository exists. 23 24Caused by: 25SSHKit::Command::Failed: git exit status: 128 26git stdout: Nothing written 27git stderr: ssh: connect to host example.com port 22: Network is unreachable 28fatal: Could not read from remote repository. 29 30Please make sure you have the correct access rights 31and the repository exists. 32 33Tasks: TOP => deploy:check => git:check 34(See full trace by running task with --trace) 35The deploy has failed with an error: Exception while executing as ec2-user@18.179.106.191: git exit status: 128 36git stdout: Nothing written 37git stderr: ssh: connect to host example.com port 22: Network is unreachable 38fatal: Could not read from remote repository. 39 40Please make sure you have the correct access rights 41and the repository exists. 42 43** DEPLOY FAILED 44** Refer to log/capistrano.log for details. Here are the last 20 lines: 45以下省略
該当のソースコード
unicorn
1 2pp_path = File.expand_path('../../../', __FILE__) 3 4worker_processes 1 5 6working_directory "#{app_path}/current" 7pid "#{app_path}/shared/tmp/pids/unicorn.pid" 8listen "#{app_path}/shared/tmp/sockets/unicorn.sock" 9stderr_path "#{app_path}/shared/log/unicorn.stderr.log" 10stdout_path "#{app_path}/shared/log/unicorn.stdout.log" 11 12timeout 60 13 14preload_app true 15GC.respond_to?(:copy_on_write_friendly=) && GC.copy_on_write_friendly = true 16 17check_client_connection false 18 19run_once = true 20 21before_fork do |server, worker| 22 defined?(ActiveRecord::Base) && 23 ActiveRecord::Base.connection.disconnect! 24 25 if run_once 26 run_once = false # prevent from firing again 27 end 28 29 old_pid = "#{server.config[:pid]}.oldbin" 30 if File.exist?(old_pid) && server.pid != old_pid 31 begin 32 sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU 33 Process.kill(sig, File.read(old_pid).to_i) 34 rescue Errno::ENOENT, Errno::ESRCH => e 35 logger.error e 36 end 37 end 38end 39 40after_fork do |_server, _worker| 41 defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection 42end
deployrb
1# config valid for current version and patch releases of Capistrano 2lock "~> 3.14.0" 3 4set :application, "simpleisbest" 5set :repo_url, "git@example.com:shiropt/typ-pro.git" 6 7set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads') 8 9set :rbenv_type, :user 10set :rbenv_ruby, '2.5.1' 11 12# chat-spaceで使ったpemを指定 13set :ssh_options, auth_methods: ['publickey'], 14 keys: ['~/.ssh/shiro.pem'] 15 16set :unicorn_pid, -> { "#{shared_path}/tmp/pids/unicorn.pid" } 17set :unicorn_config_path, -> { "#{current_path}/config/unicorn.rb" } 18set :keep_releases, 5 19 20set :linked_files, %w{ config/secrets.yml} 21 22after 'deploy:publishing', 'deploy:restart' 23namespace :deploy do 24 task :restart do 25 invoke 'unicorn:stop' 26 invoke 'unicorn:start' 27 end 28 29 desc 'upload secrets.yml' 30 task :upload do 31 on roles(:app) do |host| 32 if test "[ ! -d #{shared_path}/config ]" 33 execute "mkdir -p #{shared_path}/config" 34 end 35 upload!('config/secrets.yml', "#{shared_path}/config/secrets.yml") 36 end 37 end 38 before :starting, 'deploy:upload' 39 after :finishing, 'deploy:cleanup' 40end 41 42
試したこと
①Gemfileがないと言われているので$find-nameGemfileコマンドを実行
下記のディリクトリにあることを確認しcdしてbundle install
/usr/share/ruby/gems/2.0/gems/json-1.8.3/Gemfile
結果
terminal
1[!] There was an error parsing `Gemfile`: There are no gemspecs at /usr/share/ruby/gems/2.0/gems/json-1.8.3. Bundler cannot continue. 2 3 # from /usr/share/ruby/gems/2.0/gems/json-1.8.3/Gemfile:5 4 # ------------------------------------------- 5 # 6 > gemspec :name => 'json' 7 # gemspec :name => 'json_pure' 8 # -------------------------------------------
database.ymlのsecret_key_baseがsshに保存してあるsecret_key_baseと異なっていたので変更してみましたが解決しておりません。
②エラー文から以下を実行
・リモートリポジトリのアクセス権が正しくないので、sshKeyを再発行してGithubへ登録。$ssh -T git@githubコマンドを実行し接続が出来ていることは確認出来ました。
・ log/capistrano.logを確認。やはり下記のエラー文がある
Please make sure you have the correct access rights and the repository exists.
補足情報(FW/ツールのバージョンなど)
ruby 2.5.1
Rails 5.0.7.2
bundler 2.1.4
capistrano 3.14.0
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/06/06 12:27
2020/06/06 13:35
2020/06/06 22:02
2020/06/06 23:19
2020/06/07 12:35