質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
unicorn

Unicornは、汎用のRackアプリケーションサーバ。RackとWebサーバーの機能を併せ持ちます。レスポンス処理や、Nginx単体がRackの機能をサポートしていない事から、一般的にはNginx+Unicorn+Railsの構成を取って用います。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

Q&A

解決済

2回答

2112閲覧

AWSデプロイ途中のGemfileやディレクトリが見つからずにエラーになる

shiropt

総合スコア1

unicorn

Unicornは、汎用のRackアプリケーションサーバ。RackとWebサーバーの機能を併せ持ちます。レスポンス処理や、Nginx単体がRackの機能をサポートしていない事から、一般的にはNginx+Unicorn+Railsの構成を取って用います。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

0グッド

0クリップ

投稿2020/06/05 12:27

前提・実現したいこと

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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

ベストアンサー

deploy実行前に github にpushしていないように思われます。
git push してからdeployしてください。

判断の理由
localではGemfileがgit管理されている
サーバーには1fileしかない

投稿2020/06/06 11:49

winterboum

総合スコア23284

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

shiropt

2020/06/06 12:27

ご指摘ありがとうございます。 pushした結果bundle installは出来るようになりましたが $bundle exec cap production deploy実行後はやはり同じエラーが発生してしまいます。 また、互換性があるかわかりませんが、ユニコーン起動時にも下記のエラーが発生しております、 bundler: failed to load command: unicorn_rails (/home/ec2user/.rbenv/versions/2.5.1/bin/unicorn_rails)
winterboum

2020/06/06 13:35

> pushした結果bundle installは出来るようになりましたが > $bundle exec cap production deploy実行後はやはり同じエラーが発生してしまいます。 この手順を、keyboadに打ち込んだ内容そのまま載せてください。 historyがとれたらそれも
shiropt

2020/06/06 22:02

ギットハブデスクトップにてプッシュを実行しました。 historyは以下の様になっております。 deploy.rb set :repo_url, "git@example.com:shiropt/typ-pro.git" ↓ set :repo_url, "git@example.com:shiropt/Typro.git" リポジトリ名を変更しており、それが反映されていなかった事がGemfileが見つからなかった原因かと思います。 push後にsshでbundle installすると成功 $bundle exec cap production deploy 結果 エラー文 01 ssh: connect to host example.com port 22: Network is unreachable 01 fatal: Could not read from remote repository. 01 01 Please make sure you have the correct access rights 01 and the repository exists. リモートリポジトリとの接続周りをもう一度確認してみます。
winterboum

2020/06/06 23:19

ssh: connect to host example.com port 22: Network is unreachable まずこれを解決かな
shiropt

2020/06/07 12:35

返信遅れて申し訳ございません。 色々検証した結果、自分の知識不足から解決する事が難しそうでしたので、基礎から学び直してEC2インスタンスを再構築する事に致しました。長々とお付き合いいただき本当にありがとうございました。
guest

0

/usr/share/ruby/gems/2.0/gems/json-1.8.3/Gemfile 
これは違います。jsonのgemのためのものでdeployしたアプリのものではないです。

deployは手作業?capstroとか使ってます? どのdirに置かれるようにしていますか?

投稿2020/06/05 23:16

winterboum

総合スコア23284

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

shiropt

2020/06/05 23:38

回答ありがとうございます。 deployはcapistranoを使い、dirは/var/wwwに置いております。
winterboum

2020/06/06 03:04

その下にcurrent というのは無いですか? そこに移ってやってください しかし、capならbundle install もしてくれない??
shiropt

2020/06/06 03:37

dirは/var/www/アプリ名となっております。 currntというdirは見つかりませんでした。 どのdirで実行しても[Could not locate Gemfile]と表示されてしまいます。 capでbundle installもしてくれるというのはどのタイミングでしょうか? 知識不足ですみません。
winterboum

2020/06/06 03:41

/var/www/アプリ名 の下にない? find /var/www/アプリ名 -name Gemfile するとどうなります?
shiropt

2020/06/06 03:51

/var/www/アプリ名 の下にはREADME.mdがあります。 find /var/www/アプリ名 -name Gemfileを実行すると何も起こりませんでした。
winterboum

2020/06/06 03:56

すると、Gemfileがgit管理されていないのかも。 開発環境で git log Gemfile するとどうなります?
shiropt

2020/06/06 04:03

``` commit d85d5040f1ec51943f83dbfecd261dfe1bec6007 Author: shiropt <63380875+shiropt@users.noreply.github.com> Date: Fri Jun 5 13:48:16 2020 +0900 deploy commit 3626fb621c75da92b344f095741c981d21d67641 Author: shiropt <63380875+shiropt@users.noreply.github.com> Date: Fri Jun 5 11:18:11 2020 +0900 gem追加 commit e89e213733e5335de8def18f2545501366313bfc Author: shiropt <63380875+shiropt@users.noreply.github.com> Date: Sun May 31 21:00:24 2020 +0900 Gem追加 commit 1bcc908a721ba1d83ffb3918d65317ef04b8f551 Author: shiropt <63380875+shiropt@users.noreply.github.com> Date: Mon May 4 13:34:59 2020 +0900 Initial commit ``` 上記の様に表示されました。
winterboum

2020/06/06 08:56

/var/www/アプリ名 の下にはREADME.md以外何がありますか?
shiropt

2020/06/06 11:45

README.mdのみとなっております。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問