LoginSignup
2
1

More than 5 years have passed since last update.

Heroku + Hubotでslackbot作成したときに生じたエラーまとめ

Last updated at Posted at 2019-03-03

ふと褒めまくっていれるbotがあったら良いなと思い、hubotでオリジナルbotを作成してみた。作り方は色んな記事で書かれているので、つまづいたところをまとめてみる。

環境

  • windows10 Home 64bit
  • hubot 3.3.0
  • heroku
  • git v2.19.1
  • node v10.15.1

ERROR一覧

①git push heroku masterが失敗する

ERROR内容を展開する
$git push heroku master
Enumerating objects: 15, done.
Counting objects: 100% (15/15), done.
Delta compression using up to 8 threads
Compressing objects: 100% (11/11), done.
Writing objects: 100% (15/15), 12.40 KiB | 1.03 MiB/s, done.
Total 15 (delta 0), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:        NODE_VERBOSE=false
remote:
remote: -----> Installing binaries
remote:        engines.node (package.json):  0.10.x
remote:        engines.npm (package.json):   unspecified (use default)
remote:
remote:        Resolving node version 0.10.x...
remote:        Downloading and installing node 0.10.48...
remote:        Detected package-lock.json: defaulting npm to version 5.x.x
remote:        Bootstrapping npm 5.x.x (replacing 2.15.1)...
remote:        npm 5.x.x installed
remote:
remote: /tmp/build_7c07fe93e841fdd958ff06c7f01b4d2e/.heroku/node/lib/node_modules/npm/bin/npm-cli.js:79
remote:       var notifier = require('update-notifier')({pkg})
remote:                                                     ^
remote: SyntaxError: Unexpected token }
remote:     at Module._compile (module.js:439:25)
remote:     at Object.Module._extensions..js (module.js:474:10)
remote:     at Module.load (module.js:356:32)
remote:     at Function.Module._load (module.js:312:12)
remote:     at Function.Module.runMain (module.js:497:10)
remote:     at startup (node.js:119:16)
remote:     at node.js:945:3
remote:
remote: /tmp/build_7c07fe93e841fdd958ff06c7f01b4d2e/.heroku/node/lib/node_modules/npm/bin/npm-cli.js:79
remote:       var notifier = require('update-notifier')({pkg})
remote:                                                     ^
remote: SyntaxError: Unexpected token }
remote:     at Module._compile (module.js:439:25)
remote:     at Object.Module._extensions..js (module.js:474:10)
remote:     at Module.load (module.js:356:32)
remote:     at Function.Module._load (module.js:312:12)
remote:     at Function.Module.runMain (module.js:497:10)
remote:     at startup (node.js:119:16)
remote:     at node.js:945:3
remote:
remote: /tmp/build_7c07fe93e841fdd958ff06c7f01b4d2e/.heroku/node/lib/node_modules/npm/bin/npm-cli.js:79
remote:       var notifier = require('update-notifier')({pkg})
remote:                                                     ^
remote: SyntaxError: Unexpected token }
remote:     at Module._compile (module.js:439:25)
remote:     at Object.Module._extensions..js (module.js:474:10)
remote:     at Module.load (module.js:356:32)
remote:     at Function.Module._load (module.js:312:12)
remote:     at Function.Module.runMain (module.js:497:10)
remote:     at startup (node.js:119:16)
remote:     at node.js:945:3
remote:
remote: -----> Build failed
remote:
remote:        We're sorry this build is failing! You can troubleshoot common issues here:
remote:        https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote:        If you're stuck, please submit a ticket so we can help:
remote:        https://help.heroku.com/
remote:
remote:        Love,
remote:        Heroku
remote:
remote:  !     Push rejected, failed to compile Node.js app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to xxx-xxx-xxx.
remote:
To https://git.heroku.com/xxx-xxx-xxx.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/xxx-xxx-xxx.git'

エラー内容見てみるとトラブルシュートのURLにトラブルが記載されていたので、それに従ってみた。
原因は、package.jsonに書かれたnodeのバージョンとローカルにインストールしたnodeのバージョンが異なっていたことだった。
下記のように書き換えることで解決。

package.json
"engines": {
    "node": "10.15.1"
  }

書き換えたら、git add .git commitを忘れずに実行する。

②heroku openを実行するとアプリケーションエラーが生じる

heroku logsでログを見てみると! Couldn't find that app.との記載があった。とりあえず、再起動してみたが治らず。
ログをより詳細に見ていくと、Procfileにslackアダプタに設定しておらずデフォルトのまま(bin/hubot -a campfire)であったことが判明したので、Procfileを修正した。

Procfile.
web: bin/hubot -a slack

hubotで使用するアダプタを変更するために、再度yo hubotを実行しアダプタをslackに指定することで解決した。

$ yo hubot
                     _____________________________
                    /                             \
   //\              |      Extracting input for    |
  ////\    _____    |   self-replication process   |
 //////\  /_____\   \                             /
 ======= |[^_/\_]|   /----------------------------
  |   | _|___@@__|__
  +===+/  ///     \_\
   | |_\ /// HUBOT/\\
   |___/\//      /  \\
         \      /   +---+
          \____/    |   |
           | //|    +===+
            \//      |xx|

? Owner YOUR_EMAIL_ADRESS
? Bot name your_bot_name
? Description A simple helpful robot for your Company
? Bot adapter slack #slackを指定すること
   create bin/hubot
   create bin/hubot.cmd
   create Procfile
   create README.md
   create external-scripts.json
   create hubot-scripts.json
   create .gitignore
   create package.json
   create scripts/example.coffee
   create .editorconfig

③作成したbotがすぐスリープする

1. Heroku設定画面からKeepaliveを設定する

下記のConfigを設定した。

HUBOT_HEROKU_KEEPALIVE_INTERVAL=5 #5分おきにPingで疎通確認
HUBOT_HEROKU_KEEPALIVE_URL=[your_app_URL] #keepaliveを設定するapp
HUBOT_HEROKU_SLEEP_TIME=23:59 #Botがスリープする時間
HUBOT_HEROKU_WAKEUP_TIME=6:00 #Botが起床する時間

しかし、botは相変わらずidle時間が30分過ぎるとスリープしてしまう。

2. Heroku schedulerを追加する

HerokuのアドオンであるHeroku schedulerをインストールし、Botのサーバーを寝かせないような設定を行った。このアドオンを追加するには、クレジットカード情報を登録する必要があるが、無料枠で使用している限り、請求は発生しない。
pic
"$"欄に下記スクリプトを追加する。

seq 1 13 | grep -qw $((10#`date -u "+%H"`)) && curl https://<your-app-name>.herokuapp.com > /dev/null 2>&1

次のスクリプトも試してみたが、こちらだとスリープしてしまった。

curl ${HUBOT_HEROKU_KEEPALIVE_URL}heroku/keepalive

結果

かわいいbotができた。
pic2

参考文献

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