こんどはMacで再挑戦するBotHeaven

いろいろとあってHeroku登録〜Macで環境整備〜お試しWebアプリを作るまでに流れ着きました。
すぐに始めてみました。

ログインしたあとに何か出てくる。

Authentication successful.
! Heroku client internal error.
! Search for help at: https://help.heroku.com
! Or report a bug at: https://github.com/heroku/heroku/issues/new

Error: Permission denied - /Users/kagakentarou/.heroku/autoupdate.last (Errno::EACCES)
Command: heroku login
Version: heroku-toolbelt/3.39.5 (x86_64-darwin10.8.0) ruby/1.9.3
Error ID: ----


More information in /Users/kagakentarou/.heroku/error.log

Permission denied - /Users/kagakentarou/.heroku/error.log

なんとなくSSH鍵を疑う。

heroku を久々使おうとしたら Permission denied (publickey) エラーを参考に進める

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/kagakentarou/.ssh/id_rsa): heroku_rsa

~/.ssh/configが存在しているらしいけど見当たらないので作成

$ vi ~/.ssh/config
Host heroku.com
User git
port 22
Hostname heroku.com
IdentityFile ~/.ssh/heroku_rsa
TCPKeepAlive yes
IdentitiesOnly yes

それでもエラーが出る。
herokuの入れ直しを検討、Removing Heroku Toolbelt

あとOSの再起動、sshはそのままでエラーが出なくなった。やっとスタートに立ったよ!

はじまり

さーはじめっぞ

$ cd ~/heroku
$ git clone https://github.com/alfa-jpn/BotHeaven.git
(だらだら)
$ cd BotHeaven
$ cp .env.example env

envを編集

bundle install --path vendor/bundle
(だらだら)
An error occurred while installing pg (0.18.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.1'` succeeds before bundling.

うまくいかない。

紆余曲折

postgresappを導入

postgresappを削除する。


http://brew.shを参照

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
(だらだら)
$ brew install postgresql
(だらだら)
$ brew list
openssl postgresql readline
$ brew doctor

bundleしてもまだダメ。

MacにPostgreSQLをインストールを参考

$ initdb /usr/local/var/postgres -E utf8
(だらだら)
$ postgres --version
postgres (PostgreSQL) 9.4.4

正解を見つける

Can't find the PostgreSQL client library (libpq)

$ ARCHFLAGS="-arch x86_64" bundle install --path vendor/bundle

あとは

bundle exec rake db:migrate RAILS_ENV=production
bundle exec rails s -e production

ブラウザで「http://localhost:3000」で確認

デプロイ

再確認する

$ cd ~/heroku/BotHeaven
$ git init
$ git add .
$ git commit -m "first commit"
$ heroku create BotHeaven0722
$ git push heroic master

データベース

データベースに関して
 特に指定しない場合はsqlite3で動きます、heroku等で動かす場合は下記の環境変数を追加することでpostgresqlを使用することができます。

ADAPTER=pg
DATABASE_URL=postgresqlのデータベースURL

忘れていたので変更してみる

$ bundle exec rake db:migrate RAILS_ENV=production
rake aborted!
NoMethodError: undefined method `tr' for nil:NilClass

webのherokuのdatabasesを見ると何もない。
コマンドで作成してみたがうまくいかないのでwebで無料版を作成してみた。
Connection SettingsのURLを.envの「postgresqlのデータベースURL」に「postgres://(ちょー長い)」を貼り付ける

bundle exec rake db:migrate RAILS_ENV=production
(できた)
git push heroku master
(sqlite3でエラーが出る)

Gemfileの構文を変更する

# Environment
#gem 'sqlite3', group: "sqlite3"
(#を付けてコメントアウト
group :development, :test do
gem 'sqlite3'
(開発とテストはsqlite3を使うよ)

これで

git push heroku master
heroku run rake db:migrate
heroku open

うごいた。

「モジュールを作成」
OAuth error: invalid_client_id

ローカルでためす

OAuth Error: redirect_uri did not match any configured URIs.
Passed URI : http://localhost:3000/auth/slack/callback
Allowed URI : http://botheaven_hoge.herokuapp.com/auth/slack/callback
Allowed URI : https://botheaven_hoge.herokuapp.com/auth/slack/callback

URIは合っているのか?

https://api.slack.com/methods/oauth.access/test
こんな便利なものがあるじゃないか!(使いこなせなかった)

もういちど

「モジュールを作成」
OAuth error: invalid_client_id
https://slack.com/oauth/authorize?client_id=&redirect_uri=http%3A%2F%2Fbotheaven_hoge.herokuapp.com%2Fauth%2Fslack%2Fcallback&response_type=code&scope=client&state=hogehogehoge&team=

client_idが空だ。

コードを追いかけるけど、.gitignoreに.envが書いてあるあたりがダメだと思い始める。

.gitignoreファイル

# dotenv
# .env(コメントアウト

コマンド

git add .env
git commit -m "add env"

これで動いた。
あとでまとめよう。