LoginSignup
1
0

More than 1 year has passed since last update.

Cloud Foundry(IBM Cloud)にDiscord BOTをデプロイしようとした際にハマったメモ

Posted at

手元で作成したDiscord BOTのNode.jsアプリケーションをCloud Foundry(IBM Cloud)にデプロイする際にハマりました。

デプロイ時間長すぎて検証に時間かかるのが大変......

おさらい: ログの調べ方

デプロイや起動に失敗した際は

$ ibmcloud cf logs アプリ名 --recent

でエラーログを見れます。

ERR Failed to make TCP connection to port 8080:

デプロイ時後の起動時にエラーが発生してました。

  2021-05-04T02:37:11.28+0900 [HEALTH/0] ERR Failed to make TCP connection to port 8080: connection refused (out of memory)
   2021-05-04T02:37:11.28+0900 [CELL/0] ERR Failed after 1m0.927s: readiness health check never passed.

待ち受けるサーバーが無いよと怒られてる模様です。

Discord.jsを利用してますが、このライブラリはHTTP サーバーを立てる方式ではない模様です。

Discord.js does not expose any kind of port nor a http server.
参考: https://github.com/discordjs/discord.js/issues/3577

以下のようなDiscrod.jsのサンプルのままだとうまく起動してくれませんでした。

const Discord = require('discord.js');
const client = new Discord.Client();

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

client.on('message', async msg => {
  if (msg.content === 'ping') {
    msg.reply('Pong!');
  }
});

client.login(process.env.DISCORD_TOKEN);

ちなみにこのときのmanifest.yamlはこんな感じです。

manifest.yaml
applications:
 - name: アプリ名
   random-route: true
   memory: 64M
   command: npm start

解決策1: expressを追加してサーバーを起動

待ち受けるサーバーが無くて怒られてるのでexpressを追加します。

const Discord = require('discord.js');
const client = new Discord.Client();

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

client.on('message', async msg => {
  if (msg.content === 'ping') {
    msg.reply('Pong!');
  }
});

client.login(process.env.DISCORD_TOKEN);

/*expressを追加*/
const express = require('express')
const app = express()

app.get('/', function (req, res) {
  res.send('Hello World')
})

app.listen(process.env.PORT || 3000);

これでOKです。

解決策2: manifest.yaml(の変更でできる気がする)

ProcessのTypeがWebでは無く別の指定にしたり、no-route: trueなども試してサーバーを追加しなくても起動するようにしたかったけどエラー解消されなかったです汗 

参考: https://docs.cloudfoundry.org/devguide/deploy-apps/manifest-attributes.html

一旦諦め。

ERR Killed

こちらもアプリ起動後に発生したエラーです。

[2021-05-04T10:52:45.49+0900 [APP/PROC/WEB/0] ERR Killed

例えば、 OOM Killed とあれば「メモリー不足」を意味し、コンテナーがリソース制限によってクラッシュしている
参考: https://www.ibm.com/docs/ja/bluemix_stage/containers/cs_troubleshoot_clusters.html?view=kc

みたいな話をググったら見つけたので64Mに指定してメモリを128Mにしてみました。

manifest.yaml
applications:
 - name: アプリ名
   random-route: true
   memory: 128M
   command: npm start

たまたま感ありますがこれで解決出来ました。

express入れた分でメモリ多く使ってしまったのかもしれません。

ひとりごと。 デプロイの時間が長すぎる問題

Cloud Foundryのmanifest.yamlだけでどうにかなる気がしてますが、検証しようにもデプロイの時間が長すぎる問題があります。

デプロイボタン押したらモンハンで一狩り行ってました。それくらい遅い。

ちゃちゃっと試したいのに時間長すぎるので拘りなければHerokuがいい気がするなぁ。

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