LoginSignup
12
12

More than 5 years have passed since last update.

Capistranoでデプロイできなくてこまった

Posted at

バージョンは
Capistrano Version: 3.0.1 (Rake Version: 10.1.1)
です。

結論から入ります。
デプロイ先のサーバーにログインしてgit-ssh.shを削除したらデプロイできました。

以下経緯。


Capistranoで設定していて以下のエラーがでました。

Permission denied (publickey).
Finished in 0.483 seconds with exit status 128 (failed).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

デプロイ先のサーバーからgitリポジトリへのアクセスに失敗しているエラーです。
gitリポジトリにアクセスするための秘密鍵の設定が誤っていたので直しました。

が…

$ cap production deploy
...
Permission denied (publickey).
Finished in 0.483 seconds with exit status 128 (failed).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

変わらぬ…
何度やっても失敗するのでそこまでで実行しているコマンドをデバッグモードで確認しました。

Command: ( RAILS_ENV=production /usr/bin/env mkdir -p /tmp/appname/ )
Uploading /tmp/appname/git-ssh.sh 0.0%
Uploading /tmp/appname/git-ssh.sh 100.0%
Command: ( RAILS_ENV=production /usr/bin/env chmod +x /tmp/appname/git-ssh.sh )
Command: ( RAILS_ENV=production GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/appname/git-ssh.sh /usr/bin/env git ls-remote git@gitserver:appname.git)

git-ssh.shを生成、アップロードし、実行権限を付与。
そのあとls-remoteで失敗する。

ということはgit-ssh.shが悪いのか…
しかし毎回ファイル生成してアップロードしてるからそもそも生成されるファイルが悪いということで、
設定ファイルが間違っているのかと思いいろいろテストしました。

悩んだ結果、リセットしてみようと思い、git-ssh.shを削除したらなおりました。
ファイルが既に存在している場合上書きされていなかったのか。

もし同じ現象にハマった人がいたらと思ったので共有でした。

12
12
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
12