LoginSignup
0
1

More than 1 year has passed since last update.

1年ぶりに更新したサービスがherokuのデプロイエラーが出たときにやった解決策

Posted at

1年前に作ったサービスで、クライアントさんから、値段部分の修正を依頼されました。
そのため4月に切り替わる時点でアップされるように、ローカルで準備を進めていました。
ちなみにローカルでは問題なく切り替わり、githubにもpushが完了。
3末日にさ、herokuにデプロイ!
git push origin heroku でものの数分で終わる作業なはずが
半日近く費やす結果になりました。
なぜかherokuにデプロイでエラーが出てしまいました。
随分久しぶりに動かしたのもあって諸々のアップデートが原因だったようですが、それに付随してのあれこれを記録がてら

herokuデプロイエラー

$git push heroku main

これで通常であれば、リモートリポジトリの最新のmainブランチのものがherokuに反映されるはずが

[Release/obj.target/binding/src/binding.o] Error 1
remote:        gyp ERR! build error 
remote:        gyp ERR! stack Error: `make` failed with exit code: 2
remote:        gyp ERR! stack     at ChildProcess.onExit (/tmp/build_46f356a5/node_modules/node-gyp/lib/build.js:262:23)
remote:        gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
remote:        gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
remote:        gyp ERR! System Linux 4.4.0-1101-aws
remote:        gyp ERR! command "/tmp/build_46f356a5/bin/node" "/tmp/build_46f356a5/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
remote:        gyp ERR! cwd /tmp/build_46f356a5/node_modules/node-sass
remote:        gyp ERR! node -v v16.13.1
remote:        gyp ERR! node-gyp -v v3.8.0
remote:        gyp ERR! not ok 
remote:        Build failed with error code: 1
remote: 
remote:  !
remote:  !     Precompiling assets failed.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote: 
remote:  !     Push failed
remote:  !
remote:  ! ## Warning - The same version of this code has already been built: c251fdcb0b5443de6fa662fa699e4b65db4e3fe2
remote:  !
remote:  ! We have detected that you have triggered a build from source code with version c251fdcb0b5443de6fa662fa699e4b65db4e3fe2
remote:  ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote:  !
remote:  ! If you are developing on a branch and deploying via git you must run:
remote:  !
remote:  !     git push heroku <branchname>:main
remote:  !
remote:  ! This article goes into details on the behavior:
remote:  !   https://devcenter.heroku.com/articles/duplicate-build-version
remote: 
remote: Verifying deploy...
remote: 
remote: !       Push rejected to herokuのapp名
remote: 
To https://git.heroku.com/emu-project.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/app名.git'

githubにはちゃんとリモートリポジトリには登録されたし、問題がないはず、、
ですがよく見ると、考えられるのは

  • nodeがなんとか言ってる
  • 違うブランチからじゃないの?と言われてる?
  • git push heroku :mainやってみてと言ってる
で、長いので省略しましたがwebpackのwarningがめちゃくちゃ出てたのです。 1年も触ってなかったので相談したところ、おそらくアップデートしたらいけるでしょうとのこと。

webpackをアップデート

$yarn upgrade @rails/webpacker --latest

ひとまず。
アップデートしてみました。

$bundle update
$yarn upgrade --latest

諸々アップデートを完了しました。
アップデートしたのでまたcommitせねばなりませんので

$git add .
$git commit -m "コミット名"
$git push origin main

すると今度は

ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

git hubのリポジトリが見つかりませんときました。

git push origin mainのエラーの解決

アップデートしたせいなのか、数日前は使えていたgithubのリポジトリにアップデートできなくなっていました。
原因は2点でした。

1.githubのsshキーの設定(長いこと変えてなかったので期限が切れていた)
2.アップデートした際なのか、リポジトリ名とurlがあってなかった。

です。
特に1のキーの設定は一度やったにもかかわらず、うまくいかなかったので、一度削除して
新たに作り直してみました。

https://zenn.dev/schnell/articles/0e1c2e9db5c08d

ざっとみた限りこの記事が端的でわかりやすいかもです。
作成したkeyをgithubの設定の登録まで終わったら、

2のリポジトリの名前とurlが合っていないか確認。

$ git remote -v

こちらのurlとgithubのリモートリポジトリのsshの方のアドレスが違っていないか確認する。
(私はIDがなぜか抜けてしまっていました)
urlの修正は

$git remote set-url origin git@github.com:自分のgithub名/リモートリポジトリ名.git

これでもう一度git remote -vで名前が直っているか確認して
コミット、プッシュ、
そうすると無事githubのリポジトリに登録がされ、その後のherokuの方へも無事に
デプロイすることができました!

1年近く放置してたサイトでherokuにデプロイは完了したものの、今後はherokuのアップデートもしなくてはいけないし、、いわゆるホームページ的なサイトなのでWordpressなどで作成し直すかの提案を今後して行く必要があるかな、、と思ってます。(この辺りはクライアント様と応相談)
heroku、久々に触ったのでビクビクしてしまいました〜

0
1
0

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
0
1